Skip to content

Commit eef436c

Browse files
author
whotto
committed
Initial commit: Add core files for video note generator
0 parents  commit eef436c

File tree

6 files changed

+1269
-0
lines changed

6 files changed

+1269
-0
lines changed

.env.example

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# OpenRouter API 配置(必需)
2+
OPENROUTER_API_KEY=your-api-key-here
3+
OPENROUTER_API_URL=https://openrouter.ai/api/v1
4+
OPENROUTER_APP_NAME=video_note_generator
5+
OPENROUTER_HTTP_REFERER=https://github.com
6+
7+
# Unsplash API 配置(必需)
8+
UNSPLASH_ACCESS_KEY=your-unsplash-access-key-here
9+
UNSPLASH_SECRET_KEY=your-unsplash-secret-key-here
10+
11+
# 输出目录配置
12+
OUTPUT_DIR=generated_notes
13+
14+
# Whisper 配置
15+
WHISPER_MODEL=medium # 可选: tiny, base, small, medium, large-v2
16+
WHISPER_LANGUAGE=zh # 默认语言,可选:zh, en, ja 等
17+
18+
# FFmpeg 配置
19+
# Windows 用户需要设置 FFmpeg 路径,Mac/Linux 用户通常不需要
20+
# FFMPEG_PATH=C:\\path\\to\\ffmpeg.exe
21+
22+
# 代理配置(可选,如果你在中国大陆使用,建议配置)
23+
# HTTP_PROXY=http://127.0.0.1:7890
24+
# HTTPS_PROXY=http://127.0.0.1:7890
25+
26+
# 内容生成配置
27+
MAX_TOKENS=2000 # 生成小红书内容的最大长度
28+
CONTENT_CHUNK_SIZE=2000 # 长文本分块大小(字符数)
29+
TEMPERATURE=0.7 # AI 创造性程度 (0.0-1.0)
30+
TOP_P=0.9 # 采样阈值 (0.0-1.0)
31+
32+
# 笔记样式配置
33+
USE_EMOJI=true # 是否在内容中使用表情符号
34+
TAG_COUNT=5 # 生成的标签数量
35+
MIN_PARAGRAPHS=3 # 最少段落数
36+
MAX_PARAGRAPHS=6 # 最多段落数
37+
38+
# 调试配置
39+
DEBUG=false # 是否启用调试模式
40+
LOG_LEVEL=info # 日志级别:debug, info, warning, error

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
env/
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
wheels/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
23+
24+
# Virtual Environment
25+
venv/
26+
ENV/
27+
28+
# IDE
29+
.idea/
30+
.vscode/
31+
*.swp
32+
*.swo
33+
34+
# Project specific
35+
.env
36+
generated_notes/
37+
temp/
38+
urls.txt
39+
*.mp3
40+
*.mp4
41+
*.wav
42+
43+
# OS specific
44+
.DS_Store
45+
Thumbs.db

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# 小红书笔记生成器 (XHS Note Generator)
2+
3+
🎥 一键将视频转换为优质小红书笔记,自动优化内容和配图
4+
5+
![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)
6+
![Python](https://img.shields.io/badge/python-3.8+-green.svg)
7+
8+
## 👤 作者信息
9+
10+
- **作者**:玄清
11+
- **博客**[天天悦读](https://blog.example.com)
12+
- **Email**grow8org@gmail.com
13+
- **GitHub**[whotto/Video_note_generator](https://github.com/whotto/Video_note_generator)
14+
15+
## 🎯 应用场景
16+
17+
- **内容创作者**:快速将视频/直播内容转换为文章
18+
- **知识管理者**:自动整理视频笔记和学习要点
19+
- **社交媒体运营**:批量生成优质小红书笔记
20+
21+
## 🔄 创作流程
22+
23+
```mermaid
24+
graph TD
25+
A[视频URL] --> B[下载视频]
26+
B --> C[提取音频]
27+
C --> D[Whisper转录]
28+
D --> E[AI长文整理]
29+
E --> F[小红书风格优化]
30+
F --> G[生成标题]
31+
F --> H[生成标签]
32+
F --> I[获取配图]
33+
G & H & I --> J[生成最终笔记]
34+
```
35+
36+
## 🚀 使用方式
37+
38+
支持三种使用方式:
39+
40+
1. **处理单个视频**
41+
```bash
42+
python video_note_generator.py https://example.com/video
43+
```
44+
45+
2. **批量处理 URL 文件**
46+
```bash
47+
# urls.txt 文件,每行一个视频链接
48+
python video_note_generator.py urls.txt
49+
```
50+
51+
3. **处理 Markdown 文件**
52+
```bash
53+
# 支持 Markdown 链接和直接 URL
54+
python video_note_generator.py notes.md
55+
```
56+
57+
## 🛠️ 使用工具
58+
59+
- [FFmpeg](https://ffmpeg.org/) - 音视频转换
60+
- [Whisper](https://github.com/openai/whisper) - 语音转文字
61+
- [OpenRouter](https://openrouter.ai/) - AI 内容优化
62+
- [Unsplash](https://unsplash.com/) - 高质量图片
63+
64+
## 📦 快速开始
65+
66+
### 1. 安装依赖
67+
68+
```bash
69+
# 安装 FFmpeg
70+
# Mac: brew install ffmpeg
71+
# Windows: 从 ffmpeg.org 下载并添加到环境变量
72+
# Linux: apt install ffmpeg
73+
74+
# 安装 Python 依赖
75+
pip install -r requirements.txt
76+
77+
# 配置环境变量
78+
cp .env.example .env
79+
```
80+
81+
### 2. 配置 API 密钥
82+
83+
编辑 `.env` 文件,填入必要的 API 密钥:
84+
```ini
85+
# OpenRouter API(必需)
86+
OPENROUTER_API_KEY=your-api-key-here
87+
88+
# Unsplash API(必需)
89+
UNSPLASH_ACCESS_KEY=your-unsplash-access-key-here
90+
UNSPLASH_SECRET_KEY=your-unsplash-secret-key-here
91+
```
92+
93+
### 3. 开始使用
94+
95+
1. 创建 `urls.txt` 文件,每行一个视频链接
96+
2. 运行环境检查:
97+
```bash
98+
python check_environment.py
99+
```
100+
3. 运行生成器:
101+
```bash
102+
python video_note_generator.py
103+
```
104+
105+
## ⚙️ 配置说明
106+
107+
`.env` 文件中可以调整以下参数:
108+
109+
```ini
110+
# 内容生成配置
111+
MAX_TOKENS=2000 # 生成小红书内容的最大长度
112+
CONTENT_CHUNK_SIZE=2000 # 长文本分块大小(字符数)
113+
TEMPERATURE=0.7 # AI 创造性程度 (0.0-1.0)
114+
115+
# 代理设置(可选)
116+
# HTTP_PROXY=http://127.0.0.1:7890
117+
# HTTPS_PROXY=http://127.0.0.1:7890
118+
```
119+
120+
## 📄 许可证
121+
122+
MIT License
123+
124+
## 🙏 鸣谢
125+
126+
感谢以下开源项目:
127+
- [Whisper](https://github.com/openai/whisper)
128+
- [FFmpeg](https://ffmpeg.org/)

check_environment.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import subprocess
4+
import pkg_resources
5+
import os
6+
from pathlib import Path
7+
import platform
8+
9+
def check_python_version():
10+
print("\n检查 Python 版本...")
11+
version = sys.version_info
12+
if version.major < 3 or (version.major == 3 and version.minor < 8):
13+
print("❌ Python 版本过低。需要 Python 3.8 或更高版本")
14+
print(f"当前版本: Python {version.major}.{version.minor}.{version.micro}")
15+
return False
16+
print(f"✅ Python 版本符合要求: {version.major}.{version.minor}.{version.micro}")
17+
return True
18+
19+
def check_ffmpeg():
20+
print("\n检查 FFmpeg...")
21+
try:
22+
result = subprocess.run(['ffmpeg', '-version'],
23+
stdout=subprocess.PIPE,
24+
stderr=subprocess.PIPE)
25+
if result.returncode == 0:
26+
print("✅ FFmpeg 已安装")
27+
return True
28+
else:
29+
print("❌ FFmpeg 未安装或无法访问")
30+
return False
31+
except FileNotFoundError:
32+
print("❌ FFmpeg 未安装或未添加到系统路径")
33+
if platform.system() == "Darwin":
34+
print("建议使用 Homebrew 安装: brew install ffmpeg")
35+
elif platform.system() == "Windows":
36+
print("请从 https://ffmpeg.org/download.html 下载并添加到系统环境变量")
37+
else:
38+
print("请使用包管理器安装,如: sudo apt install ffmpeg")
39+
return False
40+
41+
def check_dependencies():
42+
print("\n检查 Python 依赖...")
43+
required = {}
44+
try:
45+
with open('requirements.txt', 'r') as f:
46+
for line in f:
47+
if line.strip() and not line.startswith('#'):
48+
# 处理包名和版本要求
49+
parts = line.strip().split('>=')
50+
if len(parts) == 2:
51+
required[parts[0]] = parts[1]
52+
else:
53+
required[line.strip()] = None
54+
except FileNotFoundError:
55+
print("❌ 未找到 requirements.txt 文件")
56+
return False
57+
58+
all_satisfied = True
59+
for package, version in required.items():
60+
try:
61+
dist = pkg_resources.get_distribution(package)
62+
if version and pkg_resources.parse_version(dist.version) < pkg_resources.parse_version(version):
63+
print(f"❌ {package} 版本过低 (当前: {dist.version}, 需要: >={version})")
64+
all_satisfied = False
65+
else:
66+
print(f"✅ {package} 已安装 (版本: {dist.version})")
67+
except pkg_resources.DistributionNotFound:
68+
print(f"❌ 缺少依赖: {package}")
69+
all_satisfied = False
70+
71+
return all_satisfied
72+
73+
def check_env_file():
74+
print("\n检查环境变量配置...")
75+
env_example = Path('.env.example')
76+
env_file = Path('.env')
77+
78+
if not env_example.exists():
79+
print("❌ 未找到 .env.example 文件")
80+
return False
81+
82+
if not env_file.exists():
83+
print("❌ 未找到 .env 文件,请复制 .env.example 并配置")
84+
return False
85+
86+
required_vars = [
87+
'OPENROUTER_API_KEY',
88+
'UNSPLASH_ACCESS_KEY',
89+
]
90+
91+
missing_vars = []
92+
with open(env_file, 'r') as f:
93+
env_content = f.read()
94+
for var in required_vars:
95+
if var not in env_content or f"{var}=your-" in env_content:
96+
missing_vars.append(var)
97+
98+
if missing_vars:
99+
print("❌ 以下环境变量未正确配置:")
100+
for var in missing_vars:
101+
print(f" - {var}")
102+
return False
103+
104+
print("✅ 环境变量文件存在并包含必要配置")
105+
return True
106+
107+
def main():
108+
print("=== 小红书笔记生成器环境检查 ===")
109+
110+
checks = [
111+
("Python 版本", check_python_version),
112+
("FFmpeg", check_ffmpeg),
113+
("Python 依赖", check_dependencies),
114+
("环境变量", check_env_file)
115+
]
116+
117+
all_passed = True
118+
for name, check in checks:
119+
if not check():
120+
all_passed = False
121+
122+
print("\n=== 检查结果 ===")
123+
if all_passed:
124+
print("✅ 所有检查通过!可以开始使用小红书笔记生成器了。")
125+
else:
126+
print("❌ 存在一些问题需要解决。请根据上述提示进行修复。")
127+
128+
if __name__ == '__main__':
129+
main()

requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openai>=1.0.0
2+
httpx>=0.24.1
3+
yt-dlp>=2023.11.16
4+
openai-whisper>=2023.11.17
5+
python-dotenv>=1.0.0
6+
requests>=2.31.0
7+
beautifulsoup4>=4.12.2
8+
python-unsplash>=1.1.0
9+
Pillow>=10.1.0
10+
urllib3>=2.1.0
11+
certifi>=2023.11.17
12+
ffmpeg-python>=0.2.0
13+
14+
# Optional dependencies for better performance
15+
torch>=2.1.0
16+
pytube>=15.0.0
17+
you-get>=0.4.1650

0 commit comments

Comments
 (0)