fix: add tencent cli and original declaration handling

This commit is contained in:
tianqi
2026-05-28 17:14:03 +08:00
parent 721476f7b4
commit 1cba88de15
2 changed files with 195 additions and 11 deletions
+123
View File
@@ -26,6 +26,13 @@ from uploader.ks_uploader.main import (
cookie_auth as kuaishou_cookie_auth,
ks_setup,
)
from uploader.tencent_uploader.main import (
TENCENT_PUBLISH_STRATEGY_IMMEDIATE,
TENCENT_PUBLISH_STRATEGY_SCHEDULED,
TencentVideo,
cookie_auth as tencent_cookie_auth,
tencent_setup,
)
from uploader.xiaohongshu_uploader.main import (
XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE,
XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED,
@@ -132,6 +139,23 @@ class BilibiliVideoUploadRequest:
publish_date: datetime | int
@dataclass(slots=True)
class TencentVideoUploadRequest:
account_name: str
video_file: Path
title: str
description: str
tags: list[str]
publish_date: datetime | int
thumbnail_file: Path | None = None
short_title: str | None = None
category: str | None = None
is_draft: bool = False
publish_strategy: str = TENCENT_PUBLISH_STRATEGY_IMMEDIATE
debug: bool = True
headless: bool = True
def has_interactive_terminal() -> bool:
return sys.stdin.isatty() and sys.stdout.isatty()
@@ -234,6 +258,18 @@ async def check_bilibili_account(account_name: str) -> bool:
return result.returncode == 0
async def login_tencent_account(account_name: str, headless: bool = True) -> dict:
account_file = resolve_account_file("tencent", account_name)
return await tencent_setup(str(account_file), handle=True, return_detail=True, headless=headless)
async def check_tencent_account(account_name: str) -> bool:
account_file = resolve_account_file("tencent", account_name)
if not account_file.exists():
return False
return await tencent_cookie_auth(str(account_file))
async def upload_video(request: DouyinVideoUploadRequest) -> Path:
account_file = resolve_account_file("douyin", request.account_name)
is_ready = await douyin_setup(str(account_file), handle=False)
@@ -408,6 +444,34 @@ async def upload_bilibili_video(request: BilibiliVideoUploadRequest) -> Path:
return account_file
async def upload_tencent_video(request: TencentVideoUploadRequest) -> Path:
account_file = resolve_account_file("tencent", request.account_name)
is_ready = await tencent_setup(str(account_file), handle=False)
if not is_ready:
raise RuntimeError(
f"Tencent/WeChat Channels cookie is missing or expired: {account_file}. "
f"Run `sau tencent login --account {request.account_name}` first."
)
app = TencentVideo(
title=request.title,
file_path=str(request.video_file),
tags=request.tags,
publish_date=request.publish_date,
account_file=str(account_file),
category=request.category,
is_draft=request.is_draft,
desc=request.description,
thumbnail_path=str(request.thumbnail_file) if request.thumbnail_file else None,
short_title=request.short_title,
publish_strategy=request.publish_strategy,
debug=request.debug,
headless=request.headless,
)
await app.tencent_upload_video()
return account_file
def existing_file_path(value: str) -> Path:
path = Path(value)
if not path.is_file():
@@ -541,6 +605,28 @@ def build_parser() -> argparse.ArgumentParser:
bilibili_upload_video_parser.add_argument("--tid", required=True, type=int, help="Bilibili category id")
bilibili_upload_video_parser.add_argument("--tags", default="", help="Comma-separated tags, such as tag1,tag2")
bilibili_upload_video_parser.add_argument("--schedule", type=schedule_value, help=f"Schedule time in {schedule_help}")
tencent_parser = platform_parsers.add_parser("tencent", help="Tencent/WeChat Channels operations")
tencent_actions = tencent_parser.add_subparsers(dest="action", required=True)
for action_name in ("login", "check"):
action_parser = tencent_actions.add_parser(action_name, help=f"Tencent/WeChat Channels {action_name}")
action_parser.add_argument("--account", required=True, help="Tencent user-defined account_name")
if action_name == "login":
add_runtime_flags(action_parser)
tencent_upload_video_parser = tencent_actions.add_parser("upload-video", help="Upload one video to WeChat Channels")
tencent_upload_video_parser.add_argument("--account", required=True, help="Tencent user-defined account_name")
tencent_upload_video_parser.add_argument("--file", required=True, type=existing_file_path, help="Video file path")
tencent_upload_video_parser.add_argument("--title", required=True, help="Video title")
tencent_upload_video_parser.add_argument("--desc", default="", help="Optional video description")
tencent_upload_video_parser.add_argument("--tags", default="", help="Comma-separated tags, such as tag1,tag2")
tencent_upload_video_parser.add_argument("--schedule", type=schedule_value, help=f"Schedule time in {schedule_help}")
tencent_upload_video_parser.add_argument("--thumbnail", type=existing_file_path, help="Optional thumbnail path")
tencent_upload_video_parser.add_argument("--short-title", help="Optional WeChat Channels short title")
tencent_upload_video_parser.add_argument("--category", help="Optional original content category")
tencent_upload_video_parser.add_argument("--draft", action="store_true", help="Save as draft instead of publishing")
add_runtime_flags(tencent_upload_video_parser)
return parser
@@ -728,6 +814,43 @@ async def dispatch(args: argparse.Namespace) -> int:
raise RuntimeError(f"Unsupported Bilibili action: {args.action}")
if args.platform == "tencent":
if args.action == "login":
result = await login_tencent_account(args.account, headless=args.headless)
if not result["success"]:
raise RuntimeError(result["message"])
print(f"Tencent/WeChat Channels login flow completed: {result['account_file']}")
return 0
if args.action == "check":
is_valid = await check_tencent_account(args.account)
print("valid" if is_valid else "invalid")
return 0 if is_valid else 1
publish_strategy = TENCENT_PUBLISH_STRATEGY_SCHEDULED if args.schedule else TENCENT_PUBLISH_STRATEGY_IMMEDIATE
if args.action == "upload-video":
request = TencentVideoUploadRequest(
account_name=args.account,
video_file=args.file,
title=args.title,
description=args.desc,
tags=parse_tags(args.tags),
publish_date=args.schedule or 0,
thumbnail_file=args.thumbnail,
short_title=args.short_title,
category=args.category,
is_draft=args.draft,
publish_strategy=publish_strategy,
debug=args.debug,
headless=args.headless,
)
await upload_tencent_video(request)
print(f"Tencent/WeChat Channels video upload submitted: {request.video_file}")
return 0
raise RuntimeError(f"Unsupported Tencent/WeChat Channels action: {args.action}")
raise RuntimeError(f"Unsupported platform: {args.platform}")