douyinWEB/scripts/setup_tiktok_uploader.py
eric d8fdeaa71c TikTok: Cookie 上传(TiktokAutoUploader),替代开发者 OAuth
账号粘贴 sessionid 即可上传;TikTok 模块独立,默认关闭不影响监控/Shorts。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 10:16:20 -05:00

61 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
"""Clone TiktokAutoUploader vendor + install tiktok-signature npm deps."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
VENDOR = ROOT / "backend" / "third_party" / "TiktokAutoUploader"
SIG = VENDOR / "tiktok_uploader" / "tiktok-signature"
REPO = "https://github.com/makiisthenes/TiktokAutoUploader.git"
def run(cmd: list[str], cwd: Path | None = None) -> None:
print("$", " ".join(cmd))
subprocess.check_call(cmd, cwd=str(cwd) if cwd else None)
def main() -> int:
if not VENDOR.is_dir():
VENDOR.parent.mkdir(parents=True, exist_ok=True)
run(["git", "clone", "--depth", "1", REPO, str(VENDOR)])
_patch_vendor_upload()
if SIG.is_dir():
run(["npm", "install"], cwd=SIG)
run(["npx", "playwright", "install", "chromium"], cwd=SIG)
print("OK:", VENDOR)
return 0
def _patch_vendor_upload() -> None:
"""Use visibility_type from upload_video args (upstream hardcodes public)."""
path = VENDOR / "tiktok_uploader" / "tiktok.py"
if not path.is_file():
return
text = path.read_text(encoding="utf-8")
old = (
'\t\t\t\t"privacy_setting_info": {\n'
'\t\t\t\t\t"visibility_type": 0,\n'
'\t\t\t\t\t"allow_duet": 1,\n'
'\t\t\t\t\t"allow_stitch": 1,\n'
'\t\t\t\t\t"allow_comment": 1\n'
"\t\t\t\t}"
)
new = (
'\t\t\t\t"privacy_setting_info": {\n'
'\t\t\t\t\t"visibility_type": visibility_type,\n'
'\t\t\t\t\t"allow_duet": allow_duet,\n'
'\t\t\t\t\t"allow_stitch": allow_stitch,\n'
'\t\t\t\t\t"allow_comment": allow_comment,\n'
"\t\t\t\t}"
)
if old in text and new not in text:
path.write_text(text.replace(old, new), encoding="utf-8")
print("patched:", path)
if __name__ == "__main__":
sys.exit(main())