重构douyin上传,增加douyin图文

修复douyin视频封面上传
This commit is contained in:
home-dev-pookz
2026-03-24 23:02:22 +08:00
parent fe6e9f4af9
commit 90845f50ad
18 changed files with 1303 additions and 230 deletions
+63
View File
@@ -0,0 +1,63 @@
---
name: douyin-upload
description: 当 agent 需要通过已安装的 `sau` CLI 完成抖音登录、cookie 校验、视频上传或图文发布时使用这个 skill。该 skill 适用于已经安装 `social-auto-upload` 且可调用 `sau` 命令的环境。优先使用这个 skill 进行稳定的命令式抖音工作流,而不是一开始就阅读 uploader 源码。
---
# 抖音上传 Skill
优先把 `sau` 作为主接口。
不要假设当前环境一定能读取仓库源码。
不要一开始就去读 `uploader/`。
只有在命令不可用或 CLI 执行失败时,才回退到故障排查说明。
## 功能概览
| 功能 | 命令入口 | 说明 |
| --- | --- | --- |
| 抖音登录 | `sau douyin login --account <name>` | 生成或刷新指定账号的 cookie |
| cookie 校验 | `sau douyin check --account <name>` | 检查指定账号 cookie 是否有效 |
| 视频上传 | `sau douyin upload-video ...` | 上传并发布抖音视频 |
| 图文上传 | `sau douyin upload-note ...` | 上传并发布抖音图文 |
## 默认工作流
1. 先确认 `references/runtime-requirements.md` 里的运行前提。
2. 再确认 `references/cli-contract.md` 里的命令契约。
3. 执行匹配的 `sau douyin ...` 命令。
4. 如果命令失败,再看 `references/troubleshooting.md`。
## 支持动作
- 使用 `sau douyin login --account <name>` 登录抖音
- 使用 `sau douyin check --account <name>` 校验 cookie 是否有效
- 使用 `sau douyin upload-video ...` 上传抖音视频
- 使用 `sau douyin upload-note ...` 上传抖音图文
## 命令选择建议
- 当用户需要新的 cookie,或现有 cookie 已失效时,使用 `login`
- 当用户只需要确认 cookie 状态时,使用 `check`
- 当用户要发布视频时,使用 `upload-video`
- 当用户要发布图文时,使用 `upload-note`
## 执行前检查
- 先确认当前 shell 里是否可以调用 `sau`
- 如果 `sau` 不可用,按 `references/runtime-requirements.md` 里的回退方式处理
- 当用户明确指定无头或有头模式时,显式传 `--headless` 或 `--headed`
- 只有用户明确要求定时发布时,才使用 `--schedule`
## 模板文件
当你需要稳定的命令模板时,使用 `scripts/examples/` 下的文件:
- `douyin_commands.ps1`
- `douyin_commands.sh`
- `douyin_cli_template.py`
## 参考文档
- 运行前提:`references/runtime-requirements.md`
- CLI 契约:`references/cli-contract.md`
- 故障排查:`references/troubleshooting.md`
@@ -0,0 +1,99 @@
# 抖音 CLI 契约
这个 skill 默认假设当前环境已经安装并可调用 `sau` 命令。
## 命令列表
### 登录
```bash
sau douyin login --account <account>
```
- 必填参数:
- `--account`
- 作用:
- 启动抖音登录流程,为指定账号生成或刷新 cookie 文件
### 校验 cookie
```bash
sau douyin check --account <account>
```
- 必填参数:
- `--account`
- 预期输出:
- `valid`:cookie 可用
- `invalid`:cookie 缺失或已失效
### 上传视频
```bash
sau douyin upload-video \
--account <account> \
--file <video-path> \
--title "<title>" \
[--tags tag1,tag2] \
[--schedule "YYYY-MM-DD HH:MM"] \
[--thumbnail <image-path>] \
[--product-link <url>] \
[--product-title "<title>"] \
[--debug] \
[--headless | --headed]
```
- 必填参数:
- `--account`
- `--file`
- `--title`
- 可选参数:
- `--tags`
- `--schedule`
- `--thumbnail`
- `--product-link`
- `--product-title`
- `--debug`
- `--headless`
- `--headed`
### 上传图文
```bash
sau douyin upload-note \
--account <account> \
--images <image-1> [image-2 ...] \
--note "<content>" \
[--tags tag1,tag2] \
[--schedule "YYYY-MM-DD HH:MM"] \
[--debug] \
[--headless | --headed]
```
- 必填参数:
- `--account`
- `--images`
- `--note`
- 可选参数:
- `--tags`
- `--schedule`
- `--debug`
- `--headless`
- `--headed`
## 发布策略
- 如果不传 `--schedule`,CLI 使用立即发布
- 如果传了 `--schedule`,CLI 自动切换为定时发布
- 时间格式为:
```text
YYYY-MM-DD HH:MM
```
## 额外说明
- `upload-video` 每次命令只支持一个视频文件
- `upload-note` 每次命令支持多张图片
- `upload-note` 当前不支持 GIF
- `upload-note` 当前最多支持 35 张图片
@@ -0,0 +1,66 @@
# 运行前提
这个 skill 默认假设当前环境已经具备:
- 已安装 `social-auto-upload`
- 可以调用 `sau` 命令,或至少有等效调用方式
- 已为 `patchright` 安装 Chromium
## 推荐安装方式
在项目根目录执行:
```bash
uv pip install -e .
```
## 安装 patchright 浏览器
Windows PowerShell:
```powershell
$env:PLAYWRIGHT_DOWNLOAD_HOST="https://npmmirror.com/mirrors/playwright"; patchright install chromium
```
Linux / macOS(bash / zsh):
```bash
PLAYWRIGHT_DOWNLOAD_HOST="https://npmmirror.com/mirrors/playwright" patchright install chromium
```
## 常见调用方式
### 如果 `sau` 已经在 PATH 中
```bash
sau douyin --help
```
### 如果虚拟环境存在,但还没有激活
PowerShell:
```powershell
.\.venv\Scripts\Activate.ps1
sau douyin --help
```
### 如果你想直接调用可执行文件
PowerShell:
```powershell
.\.venv\Scripts\sau.exe douyin --help
```
### 如果你更倾向于使用 uv
```bash
uv run sau douyin --help
```
## 无头和有头模式
- 使用 `--headless` 表示无头模式
- 使用 `--headed` 表示有头模式
- 如果用户明确要求无头登录,也要预期 CLI 会通过控制台输出或临时图片路径提供二维码相关提示
@@ -0,0 +1,84 @@
# 故障排查
## 找不到 `sau` 命令
可以尝试以下方式:
```powershell
.\.venv\Scripts\Activate.ps1
sau douyin --help
```
```powershell
.\.venv\Scripts\sau.exe douyin --help
```
```bash
uv run sau douyin --help
```
如果当前环境还没有安装项目:
```bash
uv pip install -e .
```
## cookie 无效或已过期
先检查 cookie 状态:
```bash
sau douyin check --account <account>
```
如果无效,就重新登录:
```bash
sau douyin login --account <account>
```
## 无头登录二维码处理
如果用户无法使用终端二维码输出:
- 查找 CLI 打印出来的临时二维码图片路径
- 让用户直接用抖音 APP 扫描该图片
如果终端二维码显示不正常,优先使用保存下来的图片路径,而不是反复尝试随机的终端设置。
## 上传参数缺失
### 视频上传
最少需要:
- `--account`
- `--file`
- `--title`
### 图文上传
最少需要:
- `--account`
- `--images`
- `--note`
## 图片限制
对 `upload-note` 来说:
- 不支持 GIF
- 最多 35 张图片
如果超出这些限制,先减少图片数量或替换文件格式,再重试。
## 定时发布
时间格式使用:
```text
YYYY-MM-DD HH:MM
```
如果不需要定时发布,去掉 `--schedule` 即可改为立即发布。
@@ -0,0 +1,56 @@
from __future__ import annotations
import shlex
import subprocess
def run_command(command: list[str]) -> None:
print("Running:", " ".join(shlex.quote(part) for part in command))
subprocess.run(command, check=True)
def main() -> None:
account = "creator"
commands = [
["sau", "douyin", "login", "--account", account, "--headless"],
["sau", "douyin", "check", "--account", account],
[
"sau",
"douyin",
"upload-video",
"--account",
account,
"--file",
"videos/demo.mp4",
"--title",
"Douyin video from Python",
"--tags",
"cli,video",
"--thumbnail",
"videos/demo.png",
"--headless",
],
[
"sau",
"douyin",
"upload-note",
"--account",
account,
"--images",
"videos/1.png",
"videos/2.png",
"--note",
"Douyin note from Python",
"--tags",
"cli,note",
"--headless",
],
]
for command in commands:
run_command(command)
if __name__ == "__main__":
main()
@@ -0,0 +1,24 @@
# PowerShell examples for the installed sau CLI.
$account = "creator"
$video = "videos/demo.mp4"
$thumbnail = "videos/demo.png"
$noteImages = @("videos/1.png", "videos/2.png")
sau douyin login --account $account --headless
sau douyin check --account $account
sau douyin upload-video `
--account $account `
--file $video `
--title "Douyin video from PowerShell" `
--tags "cli,video" `
--thumbnail $thumbnail `
--headless
sau douyin upload-note `
--account $account `
--images $noteImages `
--note "Douyin note from PowerShell" `
--tags "cli,note" `
--headless
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
account="creator"
video="videos/demo.mp4"
thumbnail="videos/demo.png"
sau douyin login --account "$account" --headless
sau douyin check --account "$account"
sau douyin upload-video \
--account "$account" \
--file "$video" \
--title "Douyin video from bash" \
--tags "cli,video" \
--thumbnail "$thumbnail" \
--headless
sau douyin upload-note \
--account "$account" \
--images "videos/1.png" "videos/2.png" \
--note "Douyin note from bash" \
--tags "cli,note" \
--headless