From 49eae01e089b4003a00985f761cf278ea86fd8f7 Mon Sep 17 00:00:00 2001 From: John Howe <89397553+timerring@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:16:46 +0800 Subject: [PATCH 1/2] feat: custom cdn line --- bilitool/cli.py | 6 +++-- bilitool/controller/upload_controller.py | 32 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/bilitool/cli.py b/bilitool/cli.py index bf5d31d..55c165a 100644 --- a/bilitool/cli.py +++ b/bilitool/cli.py @@ -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') @@ -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) diff --git a/bilitool/controller/upload_controller.py b/bilitool/controller/upload_controller.py index cd92520..ac3a848 100644 --- a/bilitool/controller/upload_controller.py +++ b/bilitool/controller/upload_controller.py @@ -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 @@ -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: @@ -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() @@ -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)) @@ -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) \ No newline at end of file From 19e36f5101b87207c94cf03e040cb43bc71dd6a4 Mon Sep 17 00:00:00 2001 From: John Howe <89397553+timerring@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:21:34 +0800 Subject: [PATCH 2/2] docs: update docs --- README-en.md | 7 ++++--- README.md | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README-en.md b/README-en.md index bbdb26e..2cbc285 100644 --- a/README-en.md +++ b/README-en.md @@ -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 @@ -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) diff --git a/README.md b/README.md index d8c9df0..d81c5a9 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ graph TD - 支持多种自定义参数上传 - 支持上传视频的 yaml 配置与解析 - 显示日志与上传进度 - - 支持**自动测速并且选择最佳线路** + - 支持**自动测速并且选择最佳线路**(默认) + - 支持指定上传线路(`qn`, `bldsa`, `ws`, `bda2`, `tx`) - `bilitool append` 追加视频到已有的视频(**分p投稿**) - `bilitool download` 下载视频 - 支持 `bvid` 和 `avid` 两种编号下载 @@ -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)