fix: TikTok Cookie 上传不再依赖 undetected_chromedriver
Cookie 路径直接 import tiktok.upload_video,vendor 补丁将 Browser 改为 login 内 lazy import,避免服务器缺 Chrome 驱动导致上传失败。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9b9fb57491
commit
1515783760
@ -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)}
|
||||
|
||||
|
||||
|
||||
@ -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],
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user