# -*- 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: """Cookie upload patches: visibility args + no top-level Browser/Video imports.""" path = VENDOR / "tiktok_uploader" / "tiktok.py" if not path.is_file(): return text = path.read_text(encoding="utf-8") changed = False old_imports = ( "from tiktok_uploader.Browser import Browser\n" "from tiktok_uploader.bot_utils import *\n" "from tiktok_uploader import Config, Video, eprint\n" ) new_imports = ( "from tiktok_uploader.bot_utils import *\n" "from tiktok_uploader.Config import Config\n" "from tiktok_uploader.basics import eprint\n" ) if old_imports in text: text = text.replace(old_imports, new_imports) changed = True login_marker = '\tbrowser = Browser.get()\n\tbrowser.driver.get(os.getenv("TIKTOK_LOGIN_URL"))' login_patch = ( '\tfrom tiktok_uploader.Browser import Browser\n\n' '\tbrowser = Browser.get()\n\tbrowser.driver.get(os.getenv("TIKTOK_LOGIN_URL"))' ) if login_marker in text and login_patch not in text: text = text.replace(login_marker, login_patch) changed = True 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: text = text.replace(old, new) changed = True if changed: path.write_text(text, encoding="utf-8") print("patched:", path) if __name__ == "__main__": sys.exit(main())