Implementation:869413421 Ai moive studio BilibiliService upload video
| Knowledge Sources | |
|---|---|
| Domains | Distribution |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Service that uploads a video to Bilibili via the biliup CLI subprocess, with cookie-based authentication and BV/AV number extraction.
Description
'BilibiliService.upload_video constructs a biliup CLI command with the cookie file (-u flag), upload subcommand, video path, and publishing metadata (title, description, category, tags, copyright, cover). The command is executed as an asyncio.create_subprocess_exec subprocess.
On success, the BV and AV numbers are extracted from stdout via regex. On failure, the error message from stderr is returned.
Usage
Import when uploading videos to Bilibili. Called by BilibiliPublishService.upload_chapter_task.
Code Reference
Source Location
- Repository: ai-moive-studio
- File: backend/src/services/bilibili.py:L157-264
Signature
class BilibiliService(BaseService):
async def upload_video(
self,
video_path: str,
title: str,
desc: str,
tid: int,
cover: Optional[str] = None,
tag: Optional[str] = None,
copyright: int = 1,
source: Optional[str] = None,
dynamic: Optional[str] = None,
dtime: Optional[int] = None,
cookie_file: Optional[str] = None,
line: str = "bda2",
limit: int = 3
) -> Dict[str, Any]:
"""
Returns:
Dict with success, bvid, aid (or error)
"""
Import
from src.services.bilibili import BilibiliService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| video_path | str | Yes | Local video file path |
| title | str | Yes | Video title |
| desc | str | Yes | Video description |
| tid | int | Yes | Bilibili category ID |
| cookie_file | str | Yes | Cookie file path for auth |
| cover | str | No | Cover image path |
| tag | str | No | Tags (comma-separated) |
| copyright | int | No | 1=original, 2=repost (default 1) |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | dict | {success, bvid, aid, output} or {success: False, error} |
Usage Examples
Uploading a Video
from src.services.bilibili import BilibiliService
service = BilibiliService(db_session)
result = await service.upload_video(
video_path="/tmp/video.mp4",
title="My AI Video",
desc="Generated by AI",
tid=171, # tech category
tag="AI,video",
copyright=1,
cookie_file="./data/bilibili_cookies/account-uuid.json",
)
if result["success"]:
print(f"Published: BV{result['bvid']}")
Related Pages
Implements Principle
- Principle:869413421_Ai_moive_studio_Content_Distribution
- Principle:869413421_Ai_moive_studio_Publish_Task_Tracking