Files
meijiaka-zy/docs/anytocopy-integration.md
T

129 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AnyToCopy 视频文案提取集成
## 功能概述
脚本生成 API 现已支持自动识别视频链接并提取文案。
- **自动检测**:输入创作主题时自动检测是否为视频链接
- **智能提取**:支持小红书、抖音、快手等 50+ 平台
- **无缝集成**:提取的文案自动用于脚本生成
## 支持平台
| 平台 | 示例链接 |
|------|----------|
| 小红书 | `https://xhslink.com/xxx` |
| 抖音 | `https://v.douyin.com/xxx` |
| 快手 | `https://v.kuaishou.com/xxx` |
| 哔哩哔哩 | `https://b23.tv/xxx` |
| 微博 | `https://weibo.com/xxx` |
## 使用方式
### 1. 普通文案生成(原有功能)
```json
POST /api/v1/ai/scripts/generate
{
"topic": "家装验收的5个细节",
"duration": 60,
"script_type": "professional"
}
```
### 2. 视频链接提取文案后生成
```json
POST /api/v1/ai/scripts/generate
{
"topic": "https://v.douyin.com/AbC123",
"duration": 60,
"script_type": "professional"
}
```
**流程**
1. 检测输入为视频链接
2. 调用 AnyToCopy API 提取视频文案
3. 使用提取的文案作为创作主题生成脚本
### 3. 混合输入(链接 + 说明)
```json
POST /api/v1/ai/scripts/generate
{
"topic": "参考这个视频的风格 https://v.douyin.com/AbC123,写一个关于装修验收的脚本",
"duration": 60,
"script_type": "professional"
}
```
**流程**
1. 从文本中提取视频链接
2. 提取视频文案
3. 将提取的文案与原始说明结合生成脚本
## 流式生成(SSE
视频提取过程会显示在进度中:
```
data: {"type": "analyzing", "progress": 5, "message": "检测到视频链接,正在提取文案..."}
data: {"type": "analyzing", "progress": 10, "message": "视频文案提取成功,共 1200 字符"}
data: {"type": "generating", "progress": 15, "message": "正在创作脚本..."}
...
```
## 配置
`.env` 文件中配置 AnyToCopy API
```bash
# AnyToCopy 视频文案提取服务
ANYTOCOPY_API_KEY=your-api-key
ANYTOCOPY_API_SECRET=your-api-secret
ANYTOCOPY_BASE_URL=https://api.anytocopy.com/vip/open-api/v1
```
## 注意事项
1. **API Key**:需要从 AnyToCopy 官网获取 API Key
2. **并发限制**:AnyToCopy 限制并发任务数为 5
3. **提取时间**:视频文案提取通常需要 10-30 秒
4. **失败处理**:如果提取失败,会自动使用原始输入继续生成脚本
## 代码集成
### 服务层
```python
from app.services.anytocopy_service import get_anytocopy_service
anytocopy = get_anytocopy_service()
result = await anytocopy.extract_text_from_input("https://v.douyin.com/xxx")
if result["is_video_url"]:
extracted_text = result["extracted_text"]
# 使用提取的文案
```
### 独立使用 AnyToCopy 服务
```python
from app.services.anytocopy_service import AnyToCopyService
service = AnyToCopyService({
"api_key": "your-key",
"api_secret": "your-secret",
})
# 提交任务
result = await service.submit_task("https://v.douyin.com/xxx")
task_id = result["data"]
# 查询结果
query_result = await service.query_task(task_id)
```