用 Gemini API 替换 OpenAI,修复依赖冲突,跑通全流程的踩坑记录
📖 目录
- 项目简介
- 整体架构
- 前置准备 Checklist
- 安装步骤
- 配置详解
- 核心改造:用 Gemini API 替换 OpenAI
- Bug 修复记录
- 视频生成全流程
- 运行程序
- 发布到 YouTube
- 常见问题 FAQ
- 总结
🎯 项目简介
MoneyPrinterV2 是一个开源的 Python 自动化工具,核心能力:
| 功能 | 说明 |
|---|---|
| YouTube Shorts 生成器 | AI 写脚本 → AI 生成图片 → TTS 语音合成 → 自动合成视频 → 上传 YouTube |
| Twitter/X 机器人 | 自动生成推文并发布 |
| 联盟营销 | 抓取 Amazon 商品 → 生成推销文案 → 发布到 Twitter |
| 本地商家推广 | 抓取 Google Maps 商家 → 自动发送推广邮件 |
本文聚焦 YouTube Shorts 视频生成 这个最核心的功能。
原始架构的问题
原始项目使用 Ollama(本地 LLM) 作为文本生成引擎,需要本地跑大模型,对硬件要求高,速度慢。我把它改成了 Google Gemini API,通过 litellm 统一调用接口,速度快、成本低、无需本地 GPU。
🏗️ 整体架构
改造后的系统架构如下:
graph TB
subgraph "用户操作"
A[运行 python src/main.py] --> B[选择 YouTube Shorts]
B --> C[选择/创建账号]
end
subgraph "AI 文本生成 (Gemini API)"
C --> D[生成视频主题]
D --> E[生成视频脚本]
E --> F[生成视频元数据
标题/描述/标签]
F --> G[生成 AI 图片提示词]
end
subgraph "素材生成"
G --> H[调用 Gemini Imagen API
生成配图]
E --> I[KittenTTS 语音合成
将脚本转为语音]
end
subgraph "视频合成"
H --> J[MoviePy 合成视频]
I --> J
J --> K[Whisper 生成字幕]
K --> J
J --> L[输出 MP4 文件]
end
subgraph "发布"
L --> M{是否上传?}
M -->|Yes| N[Selenium 自动上传
到 YouTube Studio]
M -->|No| O[保存到 output/ 目录]
end
style D fill:#4285f4,color:#fff
style E fill:#4285f4,color:#fff
style F fill:#4285f4,color:#fff
style G fill:#4285f4,color:#fff
style H fill:#ea4335,color:#fff
style I fill:#34a853,color:#fff
style K fill:#fbbc05,color:#333数据流图
flowchart LR
subgraph "输入"
N1["频道领域
(niche)"]
N2["语言
(language)"]
end
subgraph "Gemini API 处理"
P1["主题生成"] --> P2["脚本编写"]
P2 --> P3["元数据生成"]
P2 --> P4["图片提示词"]
end
subgraph "素材层"
P4 --> IMG["Imagen 4.0
生成配图 ×5-10"]
P2 --> TTS["KittenTTS
语音合成 WAV"]
TTS --> STT["Whisper
语音识别→字幕 SRT"]
end
subgraph "合成层"
IMG --> MP4["MoviePy
图片+语音+字幕+背景音乐"]
TTS --> MP4
STT --> MP4
end
N1 --> P1
N2 --> P1
MP4 --> OUT["output/*.mp4"]
style P1 fill:#4285f4,color:#fff
style P2 fill:#4285f4,color:#fff
style P3 fill:#4285f4,color:#fff
style P4 fill:#4285f4,color:#fff
style IMG fill:#ea4335,color:#fff
style TTS fill:#34a853,color:#fff
style STT fill:#fbbc05,color:#333✅ 前置准备 Checklist
在开始之前,确保以下条件已满足:
## 环境准备清单
- [ ] Python 3.12 已安装
```bash
python --version # 确认输出 Python 3.12.x
- Git 已安装
- ImageMagick 已安装(字幕渲染必需)
# macOS brew install imagemagick # 验证 which convert - Firefox 浏览器已安装
- 有一个已登录 YouTube 的 Firefox Profile(上传视频用)
- Google Gemini API Key 已获取
- 前往 Google AI Studio 获取
- 免费额度足够测试使用
- (可选)ffmpeg 已安装
brew install ffmpeg
### 如何找到你的 Firefox Profile 路径
```bash
# macOS
ls ~/Library/Application\ Support/Firefox/Profiles/
# 找到 xxxxx.default-release 那个目录,完整路径就是 Profile 路径
# 例如:/Users/你的用户名/Library/Application Support/Firefox/Profiles/xxxxx.default-release
flowchart TD
A[打开 Firefox] --> B[地址栏输入 about:profiles]
B --> C[找到 default-release 配置文件]
C --> D[复制"根目录"路径]
D --> E[填入 config.json 的 firefox_profile 字段]
style A fill:#ff7139,color:#fff
style E fill:#34a853,color:#fff📦 安装步骤
第一步:克隆项目
git clone https://github.com/FujiwaraChoki/MoneyPrinterV2.git
cd MoneyPrinterV2
第二步:创建虚拟环境
# 创建虚拟环境
python -m venv venv
# macOS / Linux 激活
source venv/bin/activate
# Windows 激活
# .\venv\Scripts\activate
第三步:安装依赖
pip install -r requirements.txt
⚠️ 注意:这一步大概率会遇到 Bug,请看下面的 Bug 修复记录
第四步:修复依赖冲突(重要!)
原始 requirements.txt 里的包版本不兼容,安装后运行会报错。以下是必须修复的问题:
Bug #1:Selenium 版本过高
# 现象:ModuleNotFoundError: No module named 'selenium.webdriver.firefox.firefox_binary'
# 原因:selenium_firefox 包依赖的 firefox_binary 模块在 Selenium 4.40+ 中被移除
pip install selenium==4.39.0
Bug #2:MoviePy 版本过高
# 现象:ImportError: cannot import name 'editor' from 'moviepy'
# 原因:MoviePy 2.x 移除了 editor 模块,而 YouTube.py 中大量使用 from moviepy.editor import *
pip install 'moviepy<2'
安装后的完整验证
# 验证 Selenium 版本
pip show selenium | grep Version
# 期望输出:Version: 4.39.0
# 验证 MoviePy 版本
pip show moviepy | grep Version
# 期望输出:Version: 1.0.3
# 验证 litellm 已安装
pip show litellm | grep Version
flowchart TD
A[pip install -r requirements.txt] --> B{运行 python src/main.py}
B -->|报错: firefox_binary| C["pip install selenium==4.39.0"]
B -->|报错: moviepy.editor| D["pip install 'moviepy<2'"]
B -->|正常运行| E["✅ 安装成功!"]
C --> E
D --> E
style A fill:#4285f4,color:#fff
style C fill:#ea4335,color:#fff
style D fill:#ea4335,color:#fff
style E fill:#34a853,color:#fff⚙️ 配置详解
创建配置文件
cp config.example.json config.json
config.json 完整配置说明
{
"verbose": true,
"firefox_profile": "/Users/你的用户名/Library/Application Support/Firefox/Profiles/xxxxx.default-release",
"headless": false,
"ollama_base_url": "http://127.0.0.1:11434",
"ollama_model": "gemini/gemini-3.5-flash",
"twitter_language": "English",
"nanobanana2_api_base_url": "https://generativelanguage.googleapis.com/v1beta",
"nanobanana2_api_key": "你的-GEMINI-API-KEY",
"nanobanana2_model": "imagen-4.0-generate-001",
"nanobanana2_aspect_ratio": "9:16",
"threads": 2,
"zip_url": "",
"is_for_kids": false,
"stt_provider": "local_whisper",
"whisper_model": "base",
"whisper_device": "auto",
"whisper_compute_type": "int8",
"tts_voice": "Jasper",
"font": "bold_font.ttf",
"imagemagick_path": "/opt/homebrew/bin/convert",
"script_sentence_length": 12,
"assembly_ai_api_key": "",
"email": {
"smtp_server": "smtp.gmail.com",
"smtp_port": 587,
"username": "",
"password": ""
},
"google_maps_scraper": "https://github.com/gosom/google-maps-scraper/archive/refs/tags/v0.9.7.zip",
"google_maps_scraper_niche": "",
"scraper_timeout": 300,
"outreach_message_subject": "I have a question...",
"outreach_message_body_file": "outreach_message.html",
"post_bridge": {
"enabled": false,
"api_key": "",
"platforms": ["tiktok", "instagram"],
"account_ids": [],
"auto_crosspost": false
}
}
关键配置项速查表
| 配置项 | 说明 | 我的设置 |
|---|---|---|
ollama_model |
文本生成模型(通过 litellm 调 Gemini) | gemini/gemini-3.5-flash |
nanobanana2_api_key |
Gemini API Key | 去 AI Studio 获取 |
nanobanana2_model |
图片生成模型 | imagen-4.0-generate-001 |
nanobanana2_aspect_ratio |
图片比例(竖屏=9:16) | 9:16 |
firefox_profile |
已登录 YouTube 的 Firefox 配置路径 | 见上文获取方法 |
imagemagick_path |
ImageMagick convert 路径 | macOS: /opt/homebrew/bin/convert |
script_sentence_length |
脚本句子数(越长视频越长) | 12 |
stt_provider |
语音转文字引擎 | local_whisper(免费本地) |
tts_voice |
TTS 语音选择 | Jasper |
获取 ImageMagick 路径
# macOS (Apple Silicon)
which convert
# 通常输出: /opt/homebrew/bin/convert
# macOS (Intel)
# 通常输出: /usr/local/bin/convert
# Linux
# 通常输出: /usr/bin/convert
🔧 核心改造:用 Gemini API 替换 OpenAI
为什么替换?
原始项目使用 Ollama(本地运行大模型),存在以下问题:
graph LR
subgraph "原方案:Ollama 本地"
O1["需要下载 4GB+ 模型"] --> O2["需要 8GB+ RAM"]
O2 --> O3["生成速度慢
30-60秒/次"]
O3 --> O4["需要持续运行
Ollama 服务"]
end
subgraph "新方案:Gemini API"
G1["无需本地模型"] --> G2["API 免费额度充足"]
G2 --> G3["生成速度快
2-5秒/次"]
G3 --> G4["无需本地服务"]
end
style O3 fill:#ea4335,color:#fff
style G3 fill:#34a853,color:#fff改动一:`requirements.txt`
wheel
termcolor
schedule
requests
- ollama
+ litellm
kittentts @ https://github.com/KittenML/KittenTTS/releases/download/0.8.1/kittentts-0.8.1-py3-none-any.whl
移除 ollama 包,换成 litellm(统一的 LLM 调用库,支持所有主流 API)。
改动二:`src/llm_provider.py`(核心文件,完整重写)
这个文件是整个 AI 文本生成的入口。我把原来的 Ollama SDK 调用全部替换为 litellm + Gemini API:
import time
import litellm
from config import get_ollama_model, get_nanobanana2_api_key
_selected_model: str | None = None
# 当主模型 503 不可用时的备选模型
FALLBACK_MODELS = [
"gemini/gemini-2.5-flash",
"gemini/gemini-2.0-flash",
"gemini/gemini-2.5-pro",
]
MAX_RETRIES = 3
RETRY_DELAY = 10 # seconds
def list_models() -> list[str]:
"""返回推荐的 Gemini 模型列表"""
return [
"gemini/gemini-3.5-flash",
"gemini/gemini-2.5-flash",
"gemini/gemini-3.5-pro",
]
def select_model(model: str) -> None:
"""设置后续所有 generate_text 调用使用的模型"""
global _selected_model
_selected_model = model
def get_active_model() -> str | None:
"""返回当前选中的模型"""
return _selected_model
def generate_text(prompt: str, model_name: str = None) -> str:
"""
使用 Gemini API 生成文本,支持自动重试和模型降级。
工作流程:
1. 尝试主模型(默认 gemini/gemini-3.5-flash)
2. 如果主模型 503 不可用,最多重试 3 次
3. 3 次都失败,自动切换到备选模型
4. 所有模型都失败才抛出异常
"""
primary = model_name or _selected_model or "gemini/gemini-3.5-flash"
models_to_try = [primary] + [m for m in FALLBACK_MODELS if m != primary]
api_key = get_nanobanana2_api_key()
for model in models_to_try:
for attempt in range(MAX_RETRIES):
try:
response = litellm.completion(
model=model,
messages=[{"role": "user", "content": prompt}],
api_key=api_key,
)
return response.choices[0].message.content.strip()
except Exception as e:
error_str = str(e)
is_503 = ("503" in error_str
or "ServiceUnavailable" in error_str
or "UNAVAILABLE" in error_str)
if is_503 and attempt < MAX_RETRIES - 1:
print(f"⚠️ Model {model} unavailable (503), "
f"retry {attempt+1}/{MAX_RETRIES} in {RETRY_DELAY}s...")
time.sleep(RETRY_DELAY)
continue
elif is_503:
print(f"⚠️ Model {model} failed after {MAX_RETRIES} retries, "
f"trying next model...")
break
else:
raise
raise RuntimeError("All Gemini models unavailable. Try again later.")
改动三:`config.json` 模型配置
{
"ollama_model": "gemini/gemini-3.5-flash",
"nanobanana2_api_key": "你的API密钥"
}
这里的 ollama_model 字段名虽然还叫 ollama,但实际上传的是 litellm 格式的 Gemini 模型名。litellm 通过 gemini/ 前缀自动识别调用 Gemini API。
改动说明图
sequenceDiagram
participant M as main.py
participant L as llm_provider.py
participant LT as litellm 库
participant G as Gemini API
M->>L: generate_text("生成视频主题...")
L->>L: 构建 prompt + 选择模型
L->>LT: litellm.completion(model="gemini/gemini-3.5-flash")
LT->>G: POST /v1beta/models/gemini-3.5-flash:generateContent
G-->>LT: 返回 AI 生成文本
LT-->>L: 解析 response
L-->>M: 返回生成的文本
Note over L,G: 如果 503,自动重试 3 次后切换备选模型修改文件汇总
graph TD
subgraph "修改的文件"
A["requirements.txt
ollama → litellm"]
B["src/llm_provider.py
完全重写,Gemini API + 自动降级"]
C["config.json
ollama_model 改为 gemini/ 路径"]
end
subgraph "未修改的文件"
D["src/classes/YouTube.py
调用 generate_text() 不变"]
E["src/main.py
启动流程不变"]
F["src/classes/Twitter.py
调用方式不变"]
end
A --> B
C --> B
B --> D
B --> E
B --> F
style A fill:#ea4335,color:#fff
style B fill:#ea4335,color:#fff
style C fill:#ea4335,color:#fff
style D fill:#34a853,color:#fff
style E fill:#34a853,color:#fff
style F fill:#34a853,color:#fff💡 设计亮点:因为
llm_provider.py对外只暴露generate_text(prompt)一个函数接口,所有调用方(YouTube.py、Twitter.py、AFM.py)零改动就完成了 API 切换。
🐛 Bug 修复记录
Bug #1:Selenium 版本冲突 🔴
| 项目 | 详情 |
|---|---|
| 现象 | ModuleNotFoundError: No module named 'selenium.webdriver.firefox.firefox_binary' |
| 原因 | selenium_firefox 包依赖 firefox_binary 模块,该模块在 Selenium 4.40+ 被移除 |
| 影响 | 程序完全无法启动 |
| 修复 | 降级 Selenium 到 4.39.0 |
pip install selenium==4.39.0
依赖关系:
graph TD
A["main.py"] -->|import| B["Twitter.py"]
B -->|import| C["selenium_firefox"]
C -->|import| D["selenium.webdriver.firefox.firefox_binary"]
D -->|"❌ Selenium 4.44.0 中不存在"| E["ModuleNotFoundError!"]
F["pip install selenium==4.39.0"] -->|"✅ 该版本包含 firefox_binary"| D
style E fill:#ea4335,color:#fff
style F fill:#34a853,color:#fffBug #2:MoviePy 版本冲突 🔴
| 项目 | 详情 |
|---|---|
| 现象 | ImportError: cannot import name 'editor' from 'moviepy' |
| 原因 | MoviePy 2.x 移除了 moviepy.editor 模块,但 YouTube.py 中大量使用 from moviepy.editor import * |
| 影响 | 视频生成功能完全不可用 |
| 修复 | 降级 MoviePy 到 1.0.3 |
pip install 'moviepy<2'
受影响的代码:
# src/classes/YouTube.py 第 18-19 行
from moviepy.editor import * # ← MoviePy 2.x 中不存在
from moviepy.video.fx.all import crop # ← 同样依赖 editor
🎥 视频生成全流程
当你选择 "Generate Video" 后,程序会自动执行以下 7 个步骤:
flowchart TD
S["🎬 开始生成视频"] --> S1
subgraph S1["Step 1: 生成主题"]
S1A["调用 Gemini API"] --> S1B["根据 niche 生成
一个视频主题"]
end
S1 --> S2
subgraph S2["Step 2: 生成脚本"]
S2A["将主题发送给 Gemini"] --> S2B["生成 12 句话的视频旁白"]
S2B --> S2C{"脚本 < 5000 字?"}
S2C -->|No| S2A
S2C -->|Yes| S2D["保存脚本"]
end
S2 --> S3
subgraph S3["Step 3: 生成元数据"]
S3A["Gemini 生成标题
(含 hashtag)"] --> S3B["Gemini 生成描述"]
end
S3 --> S4
subgraph S4["Step 4: 生成图片提示词"]
S4A["根据脚本内容"] --> S4B["生成 5-10 条图片描述"]
end
S4 --> S5
subgraph S5["Step 5: 生成图片"]
S5A["遍历每条提示词"] --> S5B["调用 Gemini Imagen 4.0"]
S5B --> S5C["保存为 PNG"]
S5C --> S5D{"还有更多?"}
S5D -->|Yes| S5A
S5D -->|No| S5E["所有图片就绪"]
end
S5 --> S6
subgraph S6["Step 6: 语音合成"]
S6A["脚本文本发送给 KittenTTS"] --> S6B["生成 WAV 音频"]
S6B --> S6C["Whisper 识别音频
生成 SRT 字幕"]
end
S6 --> S7
subgraph S7["Step 7: 合成视频"]
S7A["MoviePy 加载所有图片"] --> S7B["裁剪为 9:16 竖屏"]
S7B --> S7C["每张图片展示 N 秒
N = 音频时长 / 图片数"]
S7C --> S7D["叠加 TTS 音频"]
S7D --> S7E["叠加背景音乐
音量降低到 10%"]
S7E --> S7F["叠加字幕(黄色+黑色描边)"]
S7F --> S7G["输出 MP4 → output/"]
end
S7 --> DONE["✅ 视频生成完成!"]
style S1 fill:#4285f4,color:#fff
style S2 fill:#4285f4,color:#fff
style S3 fill:#4285f4,color:#fff
style S4 fill:#4285f4,color:#fff
style S5 fill:#ea4335,color:#fff
style S6 fill:#34a853,color:#fff
style S7 fill:#fbbc05,color:#333
style DONE fill:#34a853,color:#fff各步骤耗时参考
| 步骤 | 耗时 | 说明 |
|---|---|---|
| 生成主题 | ~3s | Gemini API 一次调用 |
| 生成脚本 | ~5s | Gemini API 一次调用 |
| 生成元数据 | ~6s | 标题 + 描述,两次 API 调用 |
| 生成图片提示词 | ~4s | Gemini API 一次调用 |
| 生成 5-10 张图片 | ~30-60s | Imagen API,每张约 5-8s |
| TTS 语音合成 | ~10-20s | 本地 KittenTTS |
| Whisper 字幕 | ~5-10s | 本地 faster-whisper |
| MoviePy 合成 | ~30-60s | 取决于图片数量 |
| 总计 | ~2-3 分钟 | 全自动,无需人工干预 |
🚀 运行程序
启动
cd MoneyPrinterV2
source venv/bin/activate
python src/main.py
交互式菜单流程
程序启动后会看到以下菜单:
============ OPTIONS ===========
1. YouTube Shorts
2. Twitter Bot
3. Affiliate Marketing
4. Outreach
5. Quit
=================================
Select an option:
选择 1 进入 YouTube Shorts:
flowchart TD
START["python src/main.py"] --> MODEL["选择模型
gemini/gemini-3.5-flash"]
MODEL --> MENU["主菜单"]
MENU -->|"1. YouTube Shorts"| YT_MENU["YouTube 菜单"]
YT_MENU --> ACCT{"有缓存的
YouTube 账号?"}
ACCT -->|No| CREATE["创建账号
输入昵称/Firefox Profile/领域/语言"]
ACCT -->|Yes| SELECT["选择已有账号"]
CREATE --> YT_OPTS
SELECT --> YT_OPTS
YT_OPTS["YouTube 操作菜单"]
YT_OPTS -->|"1. Generate Video"| GEN["自动生成视频"]
YT_OPTS -->|"2. View Videos"| VIEW["查看已生成视频列表"]
YT_OPTS -->|"3. Schedule Uploads"| CRON["设置定时上传"]
YT_OPTS -->|"4. Back"| MENU
GEN --> UPLOAD{"是否上传到
YouTube?"}
UPLOAD -->|Yes| UP["Selenium 自动上传"]
UPLOAD -->|No| SAVE["保存到 output/"]
style START fill:#4285f4,color:#fff
style GEN fill:#34a853,color:#fff
style UP fill:#ea4335,color:#fff创建 YouTube 账号时需要输入
| 输入项 | 说明 | 示例 |
|---|---|---|
| Nickname | 账号昵称 | my-tech-channel |
| Firefox Profile Path | 已登录 YouTube 的 Firefox 配置路径 | /Users/eric/Library/Application Support/Firefox/Profiles/xxx.default-release |
| Niche | 频道领域/主题 | Artificial Intelligence |
| Language | 视频语言 | English 或 Chinese |
📤 发布到 YouTube
视频生成后会提示是否上传。选择 Yes 后,程序会通过 Selenium 自动操作 Firefox 浏览器完成上传:
sequenceDiagram
participant P as 程序
participant F as Firefox
participant Y as YouTube Studio
P->>F: 启动 Firefox(加载已登录的 Profile)
F->>Y: 打开 studio.youtube.com
Y-->>F: 已登录状态 ✓
P->>F: 打开 /upload 页面
P->>F: 选择视频文件
F->>Y: 上传视频文件
Y-->>F: 上传完成
P->>F: 填入 AI 生成的标题
P->>F: 填入 AI 生成的描述
P->>F: 选择"非儿童内容"
P->>F: 点击 Next × 3
P->>F: 选择"不公开"
P->>F: 点击"完成"
Y-->>F: 上传成功,返回视频链接
F-->>P: 获取视频 URL
P->>P: 保存到缓存文件💡 关键点:程序不处理登录!你需要提前在 Firefox 中手动登录 YouTube,然后把这个 Profile 的路径配置进去。
❓ 常见问题 FAQ
Q1: 获取 Gemini API Key 时提示需要付费?
Google AI Studio 提供免费额度,对于个人测试完全足够。前往 https://aistudio.google.com/apikey 创建 Key。
Q2: 运行时报错 `ImageMagick` 找不到?
# macOS
brew install imagemagick
# 然后在 config.json 中填入路径
which convert # 获取路径
Q3: 图片生成失败?
检查以下几点:
-
nanobanana2_api_key是否填写正确 - API Key 是否有 Imagen API 的访问权限
- 网络是否能访问 Google API(可能需要代理)
Q4: 上传 YouTube 时浏览器闪退?
- 确认 Firefox Profile 路径正确
- 确认该 Profile 已登录 YouTube
- 不要在程序运行时同时使用该 Firefox Profile
Q5: 如何修改视频语言为中文?
在创建 YouTube 账号时将 Language 设为 Chinese,AI 会自动用中文生成脚本。也可以在 config.json 中修改:
{
"script_sentence_length": 8
}
适当减少句子数量,因为中文每句信息量更大。
Q6: 想用其他图片生成模型?
修改 config.json 中的 nanobanana2_model:
{
"nanobanana2_model": "gemini-3.1-flash-image-preview"
}
支持两种类型:
imagen-*模型:使用 Imagen predict 端点gemini-*-image-*模型:使用 Gemini generateContent 端点
📝 总结
最终改动清单
## 改动总结
### 核心改动
- [x] 将 Ollama 本地 LLM 替换为 Gemini API(通过 litellm)
- [x] 重写 llm_provider.py,支持自动重试 + 模型降级
- [x] 配置使用 Gemini Imagen 4.0 生成图片
### Bug 修复
- [x] Selenium 降级到 4.39.0(修复 firefox_binary 导入错误)
- [x] MoviePy 降级到 1.0.3(修复 editor 模块缺失错误)
### 零改动
- [x] YouTube.py — 无需修改,接口兼容
- [x] Twitter.py — 无需修改,接口兼容
- [x] TTS 模块 — 本地运行,不涉及 API
- [x] Whisper 字幕 — 本地运行,不涉及 API
项目文件结构
MoneyPrinterV2/
├── config.json # ⚙️ 配置文件(需手动创建)
├── config.example.json # 📋 配置模板
├── requirements.txt # 📦 依赖(已改为 litellm)
├── output/ # 🎬 生成的 MP4 视频输出目录
├── Songs/ # 🎵 背景音乐素材
├── fonts/ # 🔤 字体文件
├── .mp/ # 🗂️ 缓存 + 临时文件(自动生成)
├── src/
│ ├── main.py # 🚀 主入口(交互式菜单)
│ ├── llm_provider.py # 🧠 LLM 调用(Gemini API)
│ ├── config.py # ⚙️ 配置读取
│ ├── cache.py # 💾 数据缓存
│ ├── cron.py # ⏰ 定时任务
│ └── classes/
│ ├── YouTube.py # 📺 视频生成 + 上传
│ ├── Twitter.py # 🐦 推文自动发布
│ ├── Tts.py # 🔊 语音合成(KittenTTS)
│ ├── AFM.py # 💰 联盟营销
│ └── Outreach.py # 📧 商家推广
└── scripts/
├── setup_local.sh # 🔧 macOS 一键配置
├── preflight_local.py # ✅ 环境检查
└── upload_video.sh # 📤 快速上传脚本
快速启动命令(一镜到底)
# 1. 克隆 & 进入目录
git clone https://github.com/FujiwaraChoki/MoneyPrinterV2.git
cd MoneyPrinterV2
# 2. 创建虚拟环境 & 激活
python -m venv venv
source venv/bin/activate
# 3. 安装依赖
pip install -r requirements.txt
# 4. 修复已知 Bug
pip install selenium==4.39.0 'moviepy<2'
# 5. 安装 ImageMagick(macOS)
brew install imagemagick
# 6. 创建配置文件
cp config.example.json config.json
# ⚠️ 编辑 config.json,填入你的 Gemini API Key 和 Firefox Profile 路径
# 7. 启动!
python src/main.py
本文基于 MoneyPrinterV2 实际部署经验编写,记录了 Gemini API 替换和依赖修复的完整过程。