RedditVideoMakerBot 完整教學
對應 repo:
elebumm/RedditVideoMakerBot(v3.4.0, GPLv3, ⭐12.3K / 🍴2.88K) 對應 metadata:inbox/2026-05-29-github-elebumm-RedditVideoMakerBot.md
1. 專案定位
一句話:用 Python 把 Reddit 熱門貼文(或指定 thread)自動轉成 9:16 直式短影片(TikTok / YouTube Shorts / Instagram Reels 通用格式)。
典型產出:
- 上半畫面:Reddit thread/comment 截圖
- 下半畫面:Minecraft Parkour / Subway Surfers / GTA 等「無腦背景影片」
- 配音:TTS 合成的旁白(多家可選)
- 時長:通常 30–90 秒,剛好一個 short 的甜蜜點
目標使用者:
- 想做「Reddit 故事頻道」但不想剪片的 content creator
- 想批量產出 AI / automation 內容測試平台演算法的 marketer
- 想學「Python 自動化 + ffmpeg + Playwright + TTS 整合」的開發者(代碼結構乾淨、易讀,3000 行就能跑完整 pipeline)
為什麼值得內部研讀:
- 是一個少見「TTS + 瀏覽器截圖 + ffmpeg 合成」全 OSS 整合的 reference 實作
- TTS 模組化設計(
TTS/engine_wrapper.py抽象基底 + 7 個 adapter)可直接借鏡到內部專案 - Playwright screenshot pipeline 對 Reddit 這種 anti-bot 站點的處理技巧(cookie banner / age gate / NSFW gate)有參考價值
- 但也有不少安全問題(見 §6),不適合直接拿來 prod,學習與改造為主
2. 安裝指南
2.1 系統需求
| 項目 | 版本 |
|---|---|
| Python | 3.10 / 3.11 / 3.12(README 寫 3.10 only,實際 main.py 已放寬) |
| OS | Windows / macOS / Linux 全支援 |
| 依賴外部 binary | ffmpeg(Linux 上腳本會自動裝;macOS / Windows 需手動) |
| 瀏覽器 | Playwright 會自動下載 Chromium |
| 磁碟空間 | ~3–5 GB(含 Playwright Chromium + 背景影片 cache) |
2.2 三種安裝路徑
路徑 A:標準(推薦初次使用)
1git clone https://github.com/elebumm/RedditVideoMakerBot.git
2cd RedditVideoMakerBot
3python3 -m venv .venv
4source .venv/bin/activate # Windows: .\.venv\Scripts\activate
5pip install -r requirements.txt
6python -m playwright install
7python -m playwright install-deps # Linux 才需要
8python main.py # 首次跑會跳出設定精靈
路徑 B:Docker(推薦正式部署)
1git clone https://github.com/elebumm/RedditVideoMakerBot.git
2cd RedditVideoMakerBot
3bash build.sh # docker build -t rvmt .
4bash run.sh # 掛載 ./out 與 .env,跑容器
注意:
Dockerfile直接apt update && apt-get install ffmpeg,build 一次約 5–10 分鐘,image 約 1.5–2 GB。
路徑 C:一鍵 curl-bash(不推薦,見 §6)
1bash <(curl -sL https://raw.githubusercontent.com/elebumm/RedditVideoMakerBot/master/install.sh)
⚠️ 這個是經典的 curl | bash 反模式 — README 自己也標 EXPERIMENTAL。詳細安全分析見 §6。
2.3 首次跑會發生什麼
main.py第 91 行呼叫ffmpeg_install(),若系統沒裝會自動下載settings.check_toml()讀utils/.config.template.toml(11.5 KB 模板)→ 寫到專案根config.toml- 對每個缺漏欄位,用
utils/console.py的handle_input()互動式詢問 - Reddit credentials(client_id / client_secret / username / password / 2FA)
- TTS 選擇(tiktok / openai / elevenlabs / aws_polly / streamlabs / pyttsx3 / gtts)
- 背景影片 / 音樂 / 字體 / 字幕
- 設定完才開始第一支影片的 pipeline
3. 核心架構解析
3.1 整體 Pipeline
flowchart LR
A[Reddit Thread
via PRAW] --> B[Subreddit Scraper
reddit/subreddit.py]
B --> C[TTS Engine
TTS/engine_wrapper.py]
B --> D[Playwright Screenshot
video_creation/screenshot_downloader.py]
C --> E[Background Video
video_creation/background.py
yt-dlp]
D --> E
E --> F[Final Compose
video_creation/final_video.py
ffmpeg-python]
F --> G[results/
9:16 MP4]
3.2 主要模組對應
| 子系統 | 路徑 | 行數 | 職責 |
|---|---|---|---|
| Entry | main.py | 137 | 啟動流程編排、版本檢查、ffmpeg 自動安裝 |
| Settings | utils/settings.py + utils/.config.template.toml | 170 + 11.5 KB | TOML 配置驗證 / 缺欄位互動填寫 |
reddit/subreddit.py | 162 | PRAW 包裝、thread / comment / NSFW filter | |
| TTS Wrapper | TTS/engine_wrapper.py | 188 | 抽象「文字 → mp3 檔」+ Whisper 切句 |
| TTS Adapters | TTS/{TikTok,openai_tts,elevenlabs,aws_polly,streamlabs_polly,GTTS,pyttsx}.py | 22–165 各 | 各家 TTS provider 實作 |
| Screenshot | video_creation/screenshot_downloader.py | 264 | Playwright 截圖(含登入、暗模式、字級縮放) |
| Background | video_creation/background.py | 170 | yt-dlp 下載背景影片 / 音樂 + 隨機切片 |
| Final | video_creation/final_video.py | 493 | ffmpeg-python 合成(整個專案最長檔) |
| GUI | GUI.py + GUI/*.html | 116 + 4 個 HTML | Flask 設定介面(選用) |
3.3 一支影片的 9 個 stage
sequenceDiagram
participant U as User
participant M as main.py
participant R as PRAW / Subreddit
participant T as TTS Engine
participant P as Playwright
participant B as Background
participant F as ffmpeg
U->>M: python main.py
M->>R: get_subreddit_threads()
R-->>M: reddit_object (title + comments)
M->>T: save_text_to_mp3(reddit_object)
T-->>M: length, n_comments (mp3 寫到 assets/temp/)
M->>P: get_screenshots_of_reddit_posts()
P-->>M: png 寫到 assets/temp/
M->>B: download_background_video() + audio()
B-->>M: 背景影片 / 音樂
M->>B: chop_background() 隨機切片到 length
M->>F: make_final_video()
F-->>U: results//.mp4
3.4 設定檔結構(utils/.config.template.toml 摘要)
四大段:
[reddit.creds]— client_id / client_secret / username / password / 2FA[reddit.thread]— subreddit / random / post_id / max_comment_length / NSFW filter[settings]— allow_nsfw / total_video_length / opacity / storymode / theme / times_to_run[settings.tts]— voice_choice / random_voice / 各家 API key(tiktok sessionid / elevenlabs / openai)/ silence_duration
4. Helper Scripts 詳細用法
4.1 install.sh(185 行 bash)
1bash install.sh -h # 看選項
2bash install.sh -d # 只裝系統 deps(apt/brew/dnf/pacman)
3bash install.sh -p # 只裝 python deps + playwright
4bash install.sh -b # 只 git clone bot
5bash install.sh -l # bot + python deps
6bash install.sh # 全裝(系統 + bot + python + playwright)
涵蓋 5 個平台:install_macos / install_arch / install_deb / install_fedora / install_centos。
4.2 build.sh / run.sh
1# 1 行 build
2docker build -t rvmt .
3
4# 1 行 run(掛載 out/ 收成品、.env 給 secret)
5docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt
4.3 run.bat(Windows venv 啟動器)
自動 activate .venv 後跑 python main.py,遇錯按任意鍵退出。
4.4 GUI.py(Flask 設定介面)
1python GUI.py
2# → 127.0.0.1:4000 開啟設定 + backgrounds 管理 + 啟動按鈕
⚠️ 安全注意:hardcoded secret_key、預設綁 127.0.0.1 但若改 0.0.0.0 暴露到網路會非常危險(沒有 auth)。
4.5 常用 CLI 一鍵
1# 跑單一指定 post
2# 在 config.toml 把 [reddit.thread] post_id 設成 "abc123" 或 "abc123+def456"(+ 串多支)
3
4# 批量跑 N 支
5# config.toml [settings] times_to_run = 5
6
7# 從零跑(隨機抓 trending)
8python main.py
5. 應用場景
| 場景 | 怎麼用 | 注意 |
|---|---|---|
| AskReddit 故事頻道量產 | subreddit = "AskReddit", random = true, times_to_run = 10 | 注意 Reddit API 60 req/min |
| 鎖定特定 thread 二創 | post_id = "abc123" | 適合做「熱門 thread 中文配音版」 |
| 多語系版本(同 thread) | 跑 N 次、每次改 lang + tts.voice_choice | translators 套件做機翻 |
| 內部 demo / 學 ffmpeg pipeline | docker 跑、看 final_video.py | 不需要真的發片 |
| Marketing A/B test | 同 thread 不同 voice / 不同背景 → 比 CTR | 平台演算法可能判重複 |
6. 資安掃描報告
掃描方式:
grep -rn找eval / exec / os.system / subprocess shell=True / pickle / input() / api_key / password等 pattern + 人工審 install.sh / Dockerfile / GUI.py。
🔴 高風險(建議改造後再用)
utils/settings.pyL33, L81 +utils/gui_utils.pyL49 —eval()處理使用者輸入1value = eval(checks["type"])(value) # fixme remove eval雖然 source 是
.config.template.toml的type欄位(理論上開發者控管),但config.toml在使用者機器上是可改的,若有惡意 PR 改 template 或使用者 paste 來路不明的 config,會直接 RCE。原作者自己標fixme remove eval。utils/console.pyL105 —eval(user_input)用於驗證型別1isinstance(eval(user_input), check_type) # fixme: remove eval使用者在互動式精靈直接輸入字串 →
eval()執行。若是 CI / Docker 環境跑、又被別人控制 stdin,可直接 RCE。curl | bash安裝路徑(README L74)bash <(curl -sL https://raw.githubusercontent.com/.../install.sh)是經典反模式:沒有 GPG 簽章 / 沒有 hash 比對 / 攻擊者只要 compromise GitHub raw(或 MITM 沒走 HTTPS strict)就能植任意 payload。建議改:先curl -O下載、sha256sum比對、再執行。
🟡 中風險(瞭解後可接受)
utils/posttextparser.pyL19 —os.system("python -m spacy download en_core_web_sm")參數是 hardcoded,不從 user input 進來,實際風險低。但
os.system是 shell injection 高風險習慣,建議改subprocess.run([...], shell=False)。TTS/engine_wrapper.pyL130 —os.system(...)呼叫 ffmpeg 處理音檔。同上:參數有部分來自 reddit_id / file path,雖然這些值理論上由程式控制,但若 path 帶入特殊字元(reddit_id 來自 PRAW,理論安全)仍有 shell injection 潛在面。建議改
subprocess.run([...])。utils/ffmpeg_install.pyL71, L89, L107 —subprocess.run(..., shell=True)下載並執行 ffmpeg 安裝指令。指令字串是 hardcoded URL,風險低;但若哪天 mirror 被換、HTTPS 失效(沒 cert pin),下載到惡意 binary 是可能的。
GUI.pyL26 — Hardcoded Flasksecret_key1app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'只用於 flash message,不用於 session auth,影響面有限。但若有人 fork 後加了 session-based 功能(很可能),這把 key 全網公開 = session forgery。
無 auth 的 Flask GUI 暴露到
0.0.0.0的可能性預設綁 127.0.0.1 OK,但 README / docs 沒明確警告「絕對不要綁 0.0.0.0」。容易被新手部署到 VPS 後直接公開。
🟢 低風險 / 設計合理
main.pyL127–129 — 例外處理時主動把tiktok_sessionid/elevenlabs_api_key/openai_api_key換成 “REDACTED” 才印出,避免 traceback 洩 key。這是好實務。requirements.txt全部 pin 到具體版本(boto3==1.36.8/torch==2.7.0)— 防 supply chain 攻擊面相對小。.env透過 docker volume 掛入(run.sh的-v $(pwd)/.env:/app/.env)— 不寫進 image,符合 12-factor。使用者 credentials 走 PRAW 標準 OAuth,不自己重做 auth。
整體判定
🟡 黃燈 — 學習與內部測試 OK,prod 部署需先把 3 個 eval() 移除 / 換掉 os.system / 不要走 curl-bash。原作者自己也標了 fixme remove eval,可看出是「個人玩具」演化成熱門 repo 但 security debt 沒還的典型狀況。
7. FAQ
| 問題 | 答案 |
|---|---|
| 為什麼 README 說只支援 Python 3.10? | main.py 已放寬到 3.10/3.11/3.12;README 還沒同步。新版用 3.12 沒問題。 |
| TikTok TTS 為什麼一直失敗? | tiktok_sessionid 過期;要從 tiktok.com 重新抓 cookie。社群常見痛點。 |
| Reddit 截圖空白 / 黑屏? | Playwright 在 new Reddit (sh.reddit.com) 偶爾 race;通常重跑或 fallback old.reddit.com。 |
| 背景影片從哪來? | utils/background_videos.json 預設清單(Minecraft / Subway / GTA 等 YouTube),yt-dlp 下載。 |
| 影片直接能上 TikTok 嗎? | 技術上可以;但 README §28 明說「不做自動上傳,避免社群準則問題」。手動上傳即可。 |
| 商用? | GPLv3。商用沒問題但你自己的代碼也得 GPL。 |
| 為什麼 Open Issues 只有 18 個但 fork 2.8K? | maintainer 用 GitHub Actions 自動關 stale issue(7 天無活動標 stale、再 10 天關閉),所以 open 數一直壓得低。 |
8. 進階技巧
8.1 換 TTS 引擎(最常見客製)
TTS/engine_wrapper.py 是抽象基底;要加新 provider 只需:
- 新檔
TTS/your_provider.py實作class YourProvider:帶run(text, filepath, random_voice)方法 - 在
engine_wrapper.py的TTSEngine註冊 utils/.config.template.toml的[settings.tts]加 voice_choice 選項
只要 30–50 行就能整合自家 TTS。
8.2 改背景影片清單
utils/background_videos.json 加 YouTube URL + 信用列即可;yt-dlp 自動下載。
8.3 串多支 post 一次跑
config.toml:
1[reddit.thread]
2post_id = "abc123+def456+ghi789"
8.4 把 GUI 改成 multi-user
⚠️ 不建議。Flask app 沒有 auth 也沒有 user session 隔離,多人用 = 全部互看互改 config。若真要做,建議重寫成 FastAPI + JWT。
8.5 Headless server 部署
Playwright 跑 headless 需要 xvfb / playwright install-deps 補齊 .so。Docker 路徑(路徑 B)最省事。
9. 整合進其他工作流
| 內部工作流 | 怎麼用 RedditVideoMakerBot |
|---|---|
paper-tutorial | 不直接用(內容性質不符) |
gh-tutorial-qd | 本份就是用 gh-tutorial-qd 產出的,用來示範 demo |
ai-save / ai-gh-save | 把這個 repo 自己存進 inbox(已做) |
meeting-intel | 不適用(這是公開 OSS) |
| AI-Knowledge template 整體 | 適合作為「Python 自動化 + TTS + Playwright + ffmpeg 整合」的 reference 範本;TTS 抽象設計可借鏡到內部 multi-provider LLM wrapper |
| 內部 demo 影片產出 | ✋ 不建議 — 內容性質(Reddit 故事)跟內部工具示範差距大;做 demo 影片有更好的工具 |
10. 重點摘要 Checklist
- Python 3.10–3.12、GPLv3、~12K star,活躍 maintain
- 9 stage pipeline:PRAW → TTS → Playwright → yt-dlp → ffmpeg → MP4
- 7 家 TTS provider,模組化抽象設計值得學
- Docker 路徑最省事;curl-bash 路徑不推薦
- 🟡 黃燈安全等級:3 個
eval()+ 2 個os.system()+ curl-bash + hardcoded Flask key - 整體判定:學習 / 內部測試 OK;prod 用前先 remove eval / 換 subprocess.run / 加 auth
- 待研究:v3.4.0 新加的
blocked_words過濾(commitd531c34)實作細節 - 待研究:Spec-kit T0XX 系列 issue(GUI 重設計)是否值得 fork 改造
11. 進一步閱讀
- 官方文件:https://reddit-video-maker-bot.netlify.app/
- Discord 社群:https://discord.gg/qfQSx45xCV
- 對應 metadata 卡:
inbox/2026-05-29-github-elebumm-RedditVideoMakerBot.md - 編譯後 HTML:
projects/RedditVideoMakerBot/quarkdown-out/02-tutorial/index.html - 相關概念:
- PRAW: https://praw.readthedocs.io/
- Playwright Python: https://playwright.dev/python/
- ffmpeg-python: https://kkroening.github.io/ffmpeg-python/
- yt-dlp: https://github.com/yt-dlp/yt-dlp
- 替代 / 競品專案:
ShortGPT(更現代化的 GPT-driven 版)MoneyPrinterTurbo(中文社群熱門 fork)
Comments