From f9ca96a7976b085872c4502a9c9013518f2983a7 Mon Sep 17 00:00:00 2001 From: John Howe <89397553+timerring@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:12:16 +0800 Subject: [PATCH 1/2] fix: remove lines --- README.md | 2 +- bilitool/cli.py | 5 ++--- bilitool/controller/upload_controller.py | 7 +++---- bilitool/model/model.py | 1 - bilitool/utils/parse_yaml.py | 23 +++++++++-------------- docs/upload.md | 5 ++--- template/example-config.yaml | 20 ++++++++------------ 7 files changed, 25 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index d05e85d..c3e1699 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ LoginController().logout_bilibili() LoginController().check_bilibili_login() # 上传 -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, copyright: int, tid: int, title: str, desc: str, tag: str, source: str, cover: str, dynamic: str) # 追加投稿(分p) UploadController().append_video_entry(video_path: str, bvid: str) diff --git a/bilitool/cli.py b/bilitool/cli.py index 75f4d27..da5d663 100644 --- a/bilitool/cli.py +++ b/bilitool/cli.py @@ -51,7 +51,6 @@ def cli(): upload_parser.add_argument('--desc', default='', help='(default is empty) The description of video') upload_parser.add_argument('--tid', type=int, default=138, help='(default is 138) For more info to the type id, refer to https://biliup.github.io/tid-ref.html') upload_parser.add_argument('--tag', default='bilitool', help='(default is bilitool) Video tags, separated by comma') - upload_parser.add_argument('--line', default='bda2', help='(default is bda2) Line refer to https://biliup.github.io/upload-systems-analysis.html') 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') @@ -109,8 +108,8 @@ def cli(): if args.subcommand == 'upload': # print(args) - UploadController().upload_video_entry(args.video_path, args.yaml, args.line, - args.copyright, args.tid, args.title, args.desc, args.tag, args.source, args.cover, args.dynamic) + 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) if args.subcommand == 'append': UploadController().append_video_entry(args.video_path, args.vid) diff --git a/bilitool/controller/upload_controller.py b/bilitool/controller/upload_controller.py index b734258..c90691c 100644 --- a/bilitool/controller/upload_controller.py +++ b/bilitool/controller/upload_controller.py @@ -15,9 +15,8 @@ def __init__(self): self.bili_uploader = BiliUploader(self.logger) @staticmethod - def package_upload_metadata(line, copyright, tid, title, desc, tag, source, cover, dynamic): + def package_upload_metadata(copyright, tid, title, desc, tag, source, cover, dynamic): return { - 'line': line, 'copyright': copyright, 'tid': tid, 'title': title, @@ -98,13 +97,13 @@ def append_video_entry(self, video_path, bvid): # reset the video title Model().update_specific_config("upload", "title", "") - def upload_video_entry(self, video_path, yaml, line, copyright, tid, title, desc, tag, source, cover, dynamic): + def upload_video_entry(self, video_path, yaml, copyright, tid, title, desc, tag, source, cover, dynamic): if yaml: # * is used to unpack the tuple upload_metadata = self.package_upload_metadata(*parse_yaml(yaml)) else: upload_metadata = self.package_upload_metadata( - line, copyright, tid, title, + copyright, tid, title, desc, tag, source, cover, dynamic ) Model().update_multiple_config('upload', upload_metadata) diff --git a/bilitool/model/model.py b/bilitool/model/model.py index 14510f3..d1419ff 100644 --- a/bilitool/model/model.py +++ b/bilitool/model/model.py @@ -42,7 +42,6 @@ def __init__(self, path=None) -> None: "desc": "", "tid": 138, "tag": "bilitool", - "line": "bda2", "source": "\u6765\u6e90\u4e8e\u4e92\u8054\u7f51", "cover": "", "dynamic": "" diff --git a/bilitool/utils/parse_yaml.py b/bilitool/utils/parse_yaml.py index b6f18e4..46f129a 100644 --- a/bilitool/utils/parse_yaml.py +++ b/bilitool/utils/parse_yaml.py @@ -6,21 +6,16 @@ def parse_yaml(yaml_path): with open(yaml_path, 'r', encoding='utf-8') as file: data = yaml.safe_load(file) - # Extracting the required values - line = data.get('line') - streamers = data.get('streamers', {}) - # Assuming there's only one streamer entry - for streamer_path, streamer_info in streamers.items(): - copyright = streamer_info.get('copyright') - tid = streamer_info.get('tid') - title = streamer_info.get('title') - desc = streamer_info.get('desc') - tag = streamer_info.get('tag') - source = streamer_info.get('source') - cover = streamer_info.get('cover') - dynamic = streamer_info.get('dynamic') - return line, copyright, tid, title, desc, tag, source, cover, dynamic + copyright = data.get('copyright') + tid = data.get('tid') + title = data.get('title') + desc = data.get('desc') + tag = data.get('tag') + source = data.get('source') + cover = data.get('cover') + dynamic = data.get('dynamic') + return copyright, tid, title, desc, tag, source, cover, dynamic if __name__ == '__main__': res = parse_yaml('') diff --git a/docs/upload.md b/docs/upload.md index cc57ff3..4c1dedc 100644 --- a/docs/upload.md +++ b/docs/upload.md @@ -5,7 +5,7 @@ `bilitool upload -h ` 打印帮助信息: ```bash -usage: bilitool upload [-h] [-y YAML] [--copyright COPYRIGHT] [--title TITLE] [--desc DESC] [--tid TID] [--tag TAG] [--line LINE] [--source SOURCE] [--cover COVER] +usage: bilitool upload [-h] [-y YAML] [--copyright COPYRIGHT] [--title TITLE] [--desc DESC] [--tid TID] [--tag TAG] [--source SOURCE] [--cover COVER] [--dynamic DYNAMIC] video_path @@ -21,7 +21,6 @@ options: --desc DESC (default is empty) The description of video --tid TID (default is 138) For more info to the type id, refer to https://biliup.github.io/tid-ref.html --tag TAG (default is bilitool) video tags, separated by comma - --line LINE (default is bda2) line refer to https://biliup.github.io/upload-systems-analysis.html --source SOURCE (default is 来源于网络) The source of video (if your video is re-print) --cover COVER (default is empty) The cover of video (if you want to customize, set it as the path to your cover image) --dynamic DYNAMIC (default is empty) The dynamic information @@ -36,7 +35,7 @@ options: bilitool upload /path/to/your/video.mp4 # 使用命令行参数上传视频 -bilitool upload /path/to/your/video.mp4 --title "test" --desc "test" --tid 138 --tag "test" --line bda2 +bilitool upload /path/to/your/video.mp4 --title "test" --desc "test" --tid 138 --tag "test" # 使用 yaml 配置上传视频 bilitool upload /path/to/your/video.mp4 -y /path/to/your/upload/template.yaml diff --git a/template/example-config.yaml b/template/example-config.yaml index c760fe8..449dfbb 100644 --- a/template/example-config.yaml +++ b/template/example-config.yaml @@ -1,12 +1,8 @@ -line: bda2 # the cdn upload line(don't change this) -limit: 5 # the limit of video upload threads -streamers: - patterns-example: # the pattern matching(WIP, you can ignore this field and just leave it as this example) - copyright: 1 # the copyright of video (1 for original, 2 for reprint) - source: https://live.bilibili.com/xxxxxxxx # the source of video (required if your video is re-print) - title: "your video title" - desc: "your video description" - tid: 138 # the type id of video - tag: "your, video, tags" # the tags of video, separated by comma - cover: '' # the cover of video (if you want to customize, set it as the path to your cover image) - dynamic: '' # the dynamic information of video \ No newline at end of file +copyright: 1 # the copyright of video (1 for original, 2 for reprint) +source: https://live.bilibili.com/xxxxxxxx # the source of video (required if your video is re-print) +title: "your video title" +desc: "your video description" +tid: 138 # the type id of video +tag: "your, video, tags" # the tags of video, separated by comma +cover: '' # the cover of video (if you want to customize, set it as the path to your cover image) +dynamic: '' # the dynamic information of video \ No newline at end of file From 0ebf855bdec8fc980738b5054246955b3e977f90 Mon Sep 17 00:00:00 2001 From: John Howe <89397553+timerring@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:29:24 +0800 Subject: [PATCH 2/2] fix: add reset function --- bilitool/controller/upload_controller.py | 4 ++-- bilitool/model/config.json | 1 - bilitool/model/model.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bilitool/controller/upload_controller.py b/bilitool/controller/upload_controller.py index c90691c..11b494e 100644 --- a/bilitool/controller/upload_controller.py +++ b/bilitool/controller/upload_controller.py @@ -83,7 +83,7 @@ def publish_video(self, file): else: self.logger.error(publish_video_response['message']) # reset the video title - Model().update_specific_config("upload", "title", "") + Model().reset_upload_config() def append_video_entry(self, video_path, bvid): bilibili_filename = self.upload_video(video_path) @@ -95,7 +95,7 @@ def append_video_entry(self, video_path, bvid): else: self.logger.error(response['message']) # reset the video title - Model().update_specific_config("upload", "title", "") + Model().reset_upload_config() def upload_video_entry(self, video_path, yaml, copyright, tid, title, desc, tag, source, cover, dynamic): if yaml: diff --git a/bilitool/model/config.json b/bilitool/model/config.json index 1778b48..60feb9d 100644 --- a/bilitool/model/config.json +++ b/bilitool/model/config.json @@ -11,7 +11,6 @@ "sid": "" }, "upload": { - "line": "bda2", "copyright": 2, "title": "", "desc": "", diff --git a/bilitool/model/model.py b/bilitool/model/model.py index d1419ff..6ff17ba 100644 --- a/bilitool/model/model.py +++ b/bilitool/model/model.py @@ -89,6 +89,18 @@ def update_multiple_config(self, action, updates: dict): config_info[action][key] = value self.write(config_info) + def reset_upload_config(self): + config_info = self.get_config() + config_info['upload']['copyright'] = 2 + config_info['upload']['title'] = "" + config_info['upload']['desc'] = "" + config_info['upload']['tid'] = 138 + config_info['upload']['tag'] = "bilitool" + config_info['upload']['source'] = "\u6765\u6e90\u4e8e\u4e92\u8054\u7f51" + config_info['upload']['cover'] = "" + config_info['upload']['dynamic'] = "" + self.write(config_info) + def reset_cookies(self): config_info = self.get_config() config_info['cookies']['access_key'] = ""