feat(weibo): add Sina Weibo video uploader
- New uploader/weibo_uploader module: passport QR-code cookie login, upload flow with title/desc/tags, cover and collection support - sau_cli: add 'weibo login/check/upload-video' subcommands - utils/log.py: register weibo logger
This commit is contained in:
+104
@@ -33,6 +33,11 @@ from uploader.tencent_uploader.main import (
|
||||
cookie_auth as tencent_cookie_auth,
|
||||
tencent_setup,
|
||||
)
|
||||
from uploader.weibo_uploader.main import (
|
||||
WeiBoVideo,
|
||||
weibo_setup,
|
||||
cookie_auth as weibo_cookie_auth,
|
||||
)
|
||||
from uploader.xiaohongshu_uploader.main import (
|
||||
XIAOHONGSHU_PUBLISH_STRATEGY_IMMEDIATE,
|
||||
XIAOHONGSHU_PUBLISH_STRATEGY_SCHEDULED,
|
||||
@@ -168,6 +173,19 @@ class TencentVideoUploadRequest:
|
||||
headless: bool = True
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class WeiboVideoUploadRequest:
|
||||
account_name: str
|
||||
video_file: Path
|
||||
title: str
|
||||
description: str
|
||||
tags: list[str]
|
||||
thumbnail_file: Path | None = None
|
||||
collection_name: str | None = None
|
||||
debug: bool = True
|
||||
headless: bool = True
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class YouTubeVideoUploadRequest:
|
||||
account_name: str
|
||||
@@ -549,6 +567,41 @@ async def upload_tencent_video(request: TencentVideoUploadRequest) -> Path:
|
||||
return account_file
|
||||
|
||||
|
||||
async def login_weibo_account(account_name: str, headless: bool = True, qrcode_callback=None) -> dict:
|
||||
account_file = resolve_account_file("weibo", account_name)
|
||||
return await weibo_setup(str(account_file), handle=True, return_detail=True, headless=headless, qrcode_callback=qrcode_callback)
|
||||
|
||||
|
||||
async def check_weibo_account(account_name: str) -> bool:
|
||||
account_file = resolve_account_file("weibo", account_name)
|
||||
if not account_file.exists():
|
||||
return False
|
||||
return await weibo_cookie_auth(str(account_file))
|
||||
|
||||
|
||||
async def upload_weibo_video(request: WeiboVideoUploadRequest) -> Path:
|
||||
account_file = resolve_account_file("weibo", request.account_name)
|
||||
is_ready = await weibo_setup(str(account_file), handle=False)
|
||||
if not is_ready:
|
||||
raise RuntimeError(
|
||||
f"Weibo cookie is missing or expired: {account_file}. Run `sau weibo login --account {request.account_name}` first."
|
||||
)
|
||||
|
||||
app = WeiBoVideo(
|
||||
title=request.title,
|
||||
file_path=str(request.video_file),
|
||||
tags=request.tags,
|
||||
account_file=str(account_file),
|
||||
desc=request.description,
|
||||
thumbnail_path=str(request.thumbnail_file) if request.thumbnail_file else None,
|
||||
collection_name=request.collection_name,
|
||||
debug=request.debug,
|
||||
headless=request.headless,
|
||||
)
|
||||
await app.main()
|
||||
return account_file
|
||||
|
||||
|
||||
def existing_file_path(value: str) -> Path:
|
||||
path = Path(value)
|
||||
if not path.is_file():
|
||||
@@ -716,6 +769,26 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
tencent_upload_video_parser.add_argument("--draft", action="store_true", help="Save as draft instead of publishing")
|
||||
add_runtime_flags(tencent_upload_video_parser)
|
||||
|
||||
# ── Weibo ──
|
||||
weibo_parser = platform_parsers.add_parser("weibo", help="Sina Weibo operations")
|
||||
weibo_actions = weibo_parser.add_subparsers(dest="action", required=True)
|
||||
|
||||
for action_name in ("login", "check"):
|
||||
action_parser = weibo_actions.add_parser(action_name, help=f"Weibo {action_name}")
|
||||
action_parser.add_argument("--account", required=True, help="Weibo user-defined account_name")
|
||||
if action_name == "login":
|
||||
add_runtime_flags(action_parser)
|
||||
|
||||
weibo_upload_video_parser = weibo_actions.add_parser("upload-video", help="Upload one video to Weibo")
|
||||
weibo_upload_video_parser.add_argument("--account", required=True, help="Weibo user-defined account_name")
|
||||
weibo_upload_video_parser.add_argument("--file", required=True, type=existing_file_path, help="Video file path")
|
||||
weibo_upload_video_parser.add_argument("--title", required=True, help="Video title (max 30 chars)")
|
||||
weibo_upload_video_parser.add_argument("--desc", default="", help="Optional video description")
|
||||
weibo_upload_video_parser.add_argument("--tags", default="", help="Comma-separated tags, such as tag1,tag2")
|
||||
weibo_upload_video_parser.add_argument("--thumbnail", type=existing_file_path, help="Optional cover image path (<5MB)")
|
||||
weibo_upload_video_parser.add_argument("--collection", default=None, help="Optional collection name")
|
||||
add_runtime_flags(weibo_upload_video_parser)
|
||||
|
||||
youtube_parser = platform_parsers.add_parser("youtube", help="YouTube operations")
|
||||
youtube_actions = youtube_parser.add_subparsers(dest="action", required=True)
|
||||
|
||||
@@ -984,6 +1057,37 @@ async def dispatch(args: argparse.Namespace) -> int:
|
||||
|
||||
raise RuntimeError(f"Unsupported Tencent/WeChat Channels action: {args.action}")
|
||||
|
||||
if args.platform == "weibo":
|
||||
if args.action == "login":
|
||||
result = await login_weibo_account(args.account, headless=args.headless)
|
||||
if not result["success"]:
|
||||
raise RuntimeError(result["message"])
|
||||
print(f"Weibo login flow completed: {result['account_file']}")
|
||||
return 0
|
||||
|
||||
if args.action == "check":
|
||||
is_valid = await check_weibo_account(args.account)
|
||||
print("valid" if is_valid else "invalid")
|
||||
return 0 if is_valid else 1
|
||||
|
||||
if args.action == "upload-video":
|
||||
request = WeiboVideoUploadRequest(
|
||||
account_name=args.account,
|
||||
video_file=args.file,
|
||||
title=args.title,
|
||||
description=args.desc,
|
||||
tags=parse_tags(args.tags),
|
||||
thumbnail_file=args.thumbnail,
|
||||
collection_name=args.collection,
|
||||
debug=args.debug,
|
||||
headless=args.headless,
|
||||
)
|
||||
await upload_weibo_video(request)
|
||||
print(f"Weibo video upload submitted: {request.video_file}")
|
||||
return 0
|
||||
|
||||
raise RuntimeError(f"Unsupported Weibo action: {args.action}")
|
||||
|
||||
if args.platform == "youtube":
|
||||
if args.action == "login":
|
||||
result = await login_youtube_account(args.account, headless=args.headless)
|
||||
|
||||
Reference in New Issue
Block a user