Skip to main content

支持抖音开放平台官方 OpenAPI 的命令行工具。

Project description

douyin

douyin-cli

面向抖音开放平台官方 OpenAPI 的命令行工具,提供 OAuth 授权、token 管理、常用官方接口封装和通用 OpenAPI 请求能力。

功能

  • 官方 OAuth 授权链接生成、code 换 token、token 刷新
  • 官方 client_tokenaccess_token 管理
  • 授权用户信息查询
  • 官方评论列表、评论回复列表、评论回复
  • 任意官方 OpenAPI 路径请求
  • 可选本地字幕生成
  • Obscura/自动化运行时集成

安装

作为 Python 库安装:

uv add douyin-cli

命令行安装:

uv tool install douyin-cli

开发安装:

uv tool install -e .
uv tool install -e '.[subtitle-mac]'

字幕可选依赖:

uv tool install 'douyin-cli[subtitle]'
uv tool install 'douyin-cli[subtitle-cuda]'
uv tool install 'douyin-cli[subtitle-mac]'

Python 库调用示例:

from douyin_cli.douyin import Douyin
from douyin_cli.douyin.openapi import DouyinOpenAPIClient

with DouyinOpenAPIClient() as client:
    token_data = client.client_token("client_key", "client_secret")

douyin = Douyin(target="二手车", type="search", limit=5, cookie="sessionid=...")
douyin.run()

Agent Skill

安装本仓库配套 skill:

bunx skills add LIghtJUNction/douyin -g
npx skills add LIghtJUNction/douyin -g

官方 OAuth 接入

准备抖音开放平台应用的 client_keyclient_secret、回调地址和所需 scope。

douyin auth login \
  --client-key "$DOUYIN_CLIENT_KEY" \
  --client-secret "$DOUYIN_CLIENT_SECRET" \
  --redirect-uri "https://example.com/callback" \
  --scope user_info \
  --scope item.comment

命令会输出官方授权链接。用户授权后,将回调中的 code 保存为 token:

douyin auth code --code "授权码"

也可以一步完成:

douyin auth login \
  --client-key "$DOUYIN_CLIENT_KEY" \
  --client-secret "$DOUYIN_CLIENT_SECRET" \
  --redirect-uri "https://example.com/callback" \
  --scope user_info \
  --code "授权码"

检查和刷新授权:

douyin auth status
douyin auth refresh
douyin auth logout

授权后,官方 OpenAPI 命令会自动读取已保存的 token 和 open_id,自动化调用不需要重复传参:

douyin api userinfo
douyin api comment-list --item-id "$DOUYIN_ITEM_ID"

Obscura 集成

douyin 提供稳定的 JSON 输出和集成 manifest,Obscura 可以直接发现命令能力并调用官方 OpenAPI。

douyin obscura manifest
douyin obscura status
douyin auth status --json

推荐接入顺序:

douyin auth login \
  --client-key "$DOUYIN_CLIENT_KEY" \
  --client-secret "$DOUYIN_CLIENT_SECRET" \
  --redirect-uri "https://example.com/callback" \
  --scope user_info

douyin auth code --code "授权码"
douyin auth status --json

官方 OpenAPI

douyin api client-token \
  --client-key "$DOUYIN_CLIENT_KEY" \
  --client-secret "$DOUYIN_CLIENT_SECRET"

douyin api userinfo \
  --token "$DOUYIN_ACCESS_TOKEN" \
  --open-id "$DOUYIN_OPEN_ID"

douyin api comment-list \
  --token "$DOUYIN_ACCESS_TOKEN" \
  --open-id "$DOUYIN_OPEN_ID" \
  --item-id "$DOUYIN_ITEM_ID"

douyin api comment-reply \
  --token "$DOUYIN_ACCESS_TOKEN" \
  --open-id "$DOUYIN_OPEN_ID" \
  --item-id "$DOUYIN_ITEM_ID" \
  --comment-id "$DOUYIN_COMMENT_ID" \
  --content "谢谢反馈"

通用请求:

douyin api request GET /oauth/userinfo/ \
  --token "$DOUYIN_ACCESS_TOKEN" \
  --param open_id="$DOUYIN_OPEN_ID"

本地字幕

douyin subtitle video.mp4 --language zh
douyin subtitle video.mp4 --model small --format srt

首次使用模型时会自动从 Hugging Face 下载。CUDA 模式需要 CUDA 12 运行库;如果系统只提供 CUDA 13,可安装 douyin-cli[subtitle-cuda],或使用 CPU 模式:

douyin subtitle video.mp4 --device cpu --compute-type int8 --language zh

macOS Apple Silicon 可安装 MLX 后端使用本机 GPU:

uv tool install 'douyin-cli[subtitle-mac]'
douyin subtitle video.mp4 --backend mlx-whisper --language zh

--backend auto 会在 macOS arm64 上优先使用 mlx-whisper,其他平台默认使用 faster-whisper--device--compute-type 只影响 faster-whisper 后端。

环境变量

  • DOUYIN_CLIENT_KEY
  • DOUYIN_CLIENT_SECRET
  • DOUYIN_ACCESS_TOKEN

技术栈

  • Python 3.13
  • Click
  • niquests
  • uv / uv-build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

douyin_cli-2026.5.30.2.tar.gz (48.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

douyin_cli-2026.5.30.2-py3-none-any.whl (62.1 kB view details)

Uploaded Python 3

File details

Details for the file douyin_cli-2026.5.30.2.tar.gz.

File metadata

  • Download URL: douyin_cli-2026.5.30.2.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for douyin_cli-2026.5.30.2.tar.gz
Algorithm Hash digest
SHA256 88eb57f2eca82ae40076a01ad7a02e98520041f11cc2032b6499b31137419dc8
MD5 39e0c5cfd1d1243e81a9d2acfc1e8fb8
BLAKE2b-256 2b5730e588b1c71df5d224089f0d8d67464e3e0ebadb0f63d00d97c47c412e8a

See more details on using hashes here.

File details

Details for the file douyin_cli-2026.5.30.2-py3-none-any.whl.

File metadata

  • Download URL: douyin_cli-2026.5.30.2-py3-none-any.whl
  • Upload date:
  • Size: 62.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for douyin_cli-2026.5.30.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17e7cc9f7766721f046df0ab95553545be1d1793a307616d15a9ea310d58af1e
MD5 46e1db3578b5317cf732ea8f6368fc24
BLAKE2b-256 6d2e3b6d56aa8fbd24c282d9bf588b76a2966c01ee891900ce3ca713e37f82dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page