diff --git a/backend/app/main.py b/backend/app/main.py index 3038fa1..1498fb4 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1069,6 +1069,8 @@ async def tiktok_job_upload_now(job_id: str) -> dict[str, Any]: job = await tiktok_pipeline.upload_job_now(job_id) except ValueError as exc: raise HTTPException(400, str(exc)) from exc + except Exception as exc: + raise HTTPException(400, str(exc) or "上传失败") from exc return {"ok": True, "job": _enrich_tiktok_job(job)} diff --git a/backend/app/tiktok_upload.py b/backend/app/tiktok_upload.py index 3361349..6006042 100644 --- a/backend/app/tiktok_upload.py +++ b/backend/app/tiktok_upload.py @@ -44,16 +44,14 @@ def _upload_sync( raise ValueError("Cookie 缺少 sessionid") tiktok_session.configure_vendor_paths() - from tiktok_uploader import tiktok as ttuploader - - # Ensure cookie file exists where upstream loader expects it. from tiktok_uploader.cookies import save_cookies_to_file + from tiktok_uploader.tiktok import upload_video save_cookies_to_file(cookies, tiktok_session.session_filename(channel_pk), str(tiktok_session.cookies_dir())) session_user = channel_pk visibility = _privacy_to_visibility(privacy_level) - ok = ttuploader.upload_video( + ok = upload_video( session_user, str(path.resolve()), (title or "video")[:2200], diff --git a/backend/requirements.txt b/backend/requirements.txt index 1cd5705..f14948f 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -10,4 +10,5 @@ boto3==1.35.99 fake-useragent>=1.4 requests-auth-aws-sigv4>=0.7 requests>=2.31 +python-dotenv>=1.0 diff --git a/scripts/setup_tiktok_uploader.py b/scripts/setup_tiktok_uploader.py index 6a7a84e..07ccfab 100644 --- a/scripts/setup_tiktok_uploader.py +++ b/scripts/setup_tiktok_uploader.py @@ -30,11 +30,36 @@ def main() -> int: def _patch_vendor_upload() -> None: - """Use visibility_type from upload_video args (upstream hardcodes public).""" + """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' @@ -52,7 +77,11 @@ def _patch_vendor_upload() -> None: "\t\t\t\t}" ) if old in text and new not in text: - path.write_text(text.replace(old, new), encoding="utf-8") + text = text.replace(old, new) + changed = True + + if changed: + path.write_text(text, encoding="utf-8") print("patched:", path)