Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ graph TD
- Supports various custom parameters for uploading
- Supports uploading videos with YAML configuration and parsing
- Displays logs and upload progress
- Supports **automatic speed test and selection of the best route**
- Supports **automatic speed test and selection of the best route** (default)
- Supports specifying upload lines (`qn`, `bldsa`, `ws`, `bda2`, `tx`)
- `bilitool append` appends videos to existing videos (multi-part)
- `bilitool download` downloads videos
- Supports downloading with `bvid` and `avid` identifiers
Expand Down Expand Up @@ -179,10 +180,10 @@ LoginController().logout_bilibili()
LoginController().check_bilibili_login()

# Upload
UploadController().upload_video_entry(video_path: str, yaml: str, line: str, copyright: int, tid: int, title: str, desc: str, tag: str, source: str, cover: str, dynamic: str)
UploadController().upload_video_entry(video_path: str, yaml: str, line: str, copyright: int, tid: int, title: str, desc: str, tag: str, source: str, cover: str, dynamic: str, cdn: str)

# Append
UploadController().append_video_entry(video_path: str, bvid: str)
UploadController().append_video_entry(video_path: str, bvid: str, cdn: str)

# Download
DownloadController().download_video_entry(vid: str, danmaku: bool, quality: int, chunksize: int, multiple: bool)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ graph TD
- 支持多种自定义参数上传
- 支持上传视频的 yaml 配置与解析
- 显示日志与上传进度
- 支持**自动测速并且选择最佳线路**
- 支持**自动测速并且选择最佳线路**(默认)
- 支持指定上传线路(`qn`, `bldsa`, `ws`, `bda2`, `tx`)
- `bilitool append` 追加视频到已有的视频(**分p投稿**)
- `bilitool download` 下载视频
- 支持 `bvid` 和 `avid` 两种编号下载
Expand Down Expand Up @@ -178,10 +179,10 @@ LoginController().logout_bilibili()
LoginController().check_bilibili_login()

# 上传
UploadController().upload_video_entry(video_path: str, yaml: str, copyright: int, tid: int, title: str, desc: str, tag: str, source: str, cover: str, dynamic: str)
UploadController().upload_video_entry(video_path: str, yaml: str, copyright: int, tid: int, title: str, desc: str, tag: str, source: str, cover: str, dynamic: str, cdn: str)

# 追加投稿(分p)
UploadController().append_video_entry(video_path: str, bvid: str)
UploadController().append_video_entry(video_path: str, bvid: str, cdn: str)

# 下载
DownloadController().download_video_entry(vid: str, danmaku: bool, quality: int, chunksize: int, multiple: bool)
Expand Down
6 changes: 4 additions & 2 deletions bilitool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ def cli():
upload_parser.add_argument('--source', default='来源于网络', help='(default is 来源于网络) The source of video (if your video is re-print)')
upload_parser.add_argument('--cover', default='', help='(default is empty) The cover of video (if you want to customize, set it as the path to your cover image)')
upload_parser.add_argument('--dynamic', default='', help='(default is empty) The dynamic information')
upload_parser.add_argument('--cdn', default='', help='(default is auto detect) The cdn line')

# Append subcommand
append_parser = subparsers.add_parser('append', help='Append the video')
append_parser.add_argument('-v','--vid', required=True, help='(required) The bvid or avid of appended video')
append_parser.add_argument('video_path', help='(required) The path to video file')
append_parser.add_argument('--cdn', default='', help='(default is auto detect) The cdn line')

# Check login subcommand
check_login_parser = subparsers.add_parser('check', help='Check if the user is logged in')
Expand Down Expand Up @@ -108,10 +110,10 @@ def cli():
if args.subcommand == 'upload':
# print(args)
UploadController().upload_video_entry(args.video_path, args.yaml, args.copyright,
args.tid, args.title, args.desc, args.tag, args.source, args.cover, args.dynamic)
args.tid, args.title, args.desc, args.tag, args.source, args.cover, args.dynamic, args.cdn)

if args.subcommand == 'append':
UploadController().append_video_entry(args.video_path, args.vid)
UploadController().append_video_entry(args.video_path, args.vid, args.cdn)

if args.subcommand == 'download':
# print(args)
Expand Down
32 changes: 24 additions & 8 deletions bilitool/controller/upload_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ def package_upload_metadata(copyright, tid, title, desc, tag, source, cover, dyn
'dynamic': dynamic
}

def upload_video(self, file):
def upload_video(self, file, cdn=None):
"""upload and publish video on bilibili"""
upos_url, cdn, probe_version = self.bili_uploader.probe()
if cdn == "qn":
upos_url = "//upos-cs-upcdnqn.bilivideo.com/"
probe_version = "20221109"
elif cdn == "bldsa":
upos_url = "//upos-cs-upcdnbldsa.bilivideo.com/"
probe_version = "20221109"
elif cdn == "ws":
upos_url = "//upos-sz-upcdnws.bilivideo.com/"
probe_version = "20221109"
elif cdn == "bda2":
upos_url = "//upos-cs-upcdnbda2.bilivideo.com/"
probe_version = "20221109"
elif cdn == "tx":
upos_url = "//upos-cs-upcdntx.bilivideo.com/"
probe_version = "20221109"
else:
upos_url, cdn, probe_version = self.bili_uploader.probe()
file = Path(file)
assert file.exists(), f'The file {file} does not exist'
filename = file.name
Expand Down Expand Up @@ -73,8 +89,8 @@ def upload_video(self, file):
upload_id=upload_id, biz_id=biz_id, chunks=chunks, upos_url=upos_url)
return bilibili_filename

def publish_video(self, file):
bilibili_filename = self.upload_video(file)
def publish_video(self, file, cdn=None):
bilibili_filename = self.upload_video(file, cdn)
# publish video
publish_video_response = self.bili_uploader.publish_video(bilibili_filename=bilibili_filename)
if publish_video_response['code'] == 0:
Expand All @@ -87,8 +103,8 @@ def publish_video(self, file):
# reset the video title
Model().reset_upload_config()

def append_video_entry(self, video_path, bvid, video_name=None):
bilibili_filename = self.upload_video(video_path)
def append_video_entry(self, video_path, bvid, cdn=None, video_name=None):
bilibili_filename = self.upload_video(video_path, cdn)
video_name = video_name if video_name else Path(video_path).name.strip(".mp4")
video_data = self.bili_uploader.get_video_list_info(bvid)
response = self.bili_uploader.append_video(bilibili_filename, video_name, video_data).json()
Expand All @@ -101,7 +117,7 @@ def append_video_entry(self, video_path, bvid, video_name=None):
# reset the video title
Model().reset_upload_config()

def upload_video_entry(self, video_path, yaml, copyright, tid, title, desc, tag, source, cover, dynamic):
def upload_video_entry(self, video_path, yaml, copyright, tid, title, desc, tag, source, cover, dynamic, cdn=None):
if yaml:
# * is used to unpack the tuple
upload_metadata = self.package_upload_metadata(*parse_yaml(yaml))
Expand All @@ -111,5 +127,5 @@ def upload_video_entry(self, video_path, yaml, copyright, tid, title, desc, tag,
desc, tag, source, cover, dynamic
)
Model().update_multiple_config('upload', upload_metadata)
return self.publish_video(video_path)
return self.publish_video(video_path, cdn)