diff --git a/config.py b/config.py index e06547c..9c5303a 100644 --- a/config.py +++ b/config.py @@ -74,3 +74,5 @@ API_COUNTER = 0 IMG_API_COUNTER = 0 IMG_CURRENT_TIME = 0 + +ARGS = {} diff --git a/main.py b/main.py index d1de33e..355fc0e 100644 --- a/main.py +++ b/main.py @@ -67,24 +67,19 @@ def parse_args(): return parser.parse_args() -# 命令行参数全局化 - -ARGS = parse_args() - - # 命令行模式 def command_mode(): - if ARGS.UseOSCdn or ARGS.UseWebp: - config.API_HEADER['use_oversea_cdn'] = ARGS.UseOSCdn - config.API_HEADER['use_webp'] = ARGS.UseWebp - if ARGS.Proxy: + if config.ARGS.UseOSCdn or config.ARGS.UseWebp: + config.API_HEADER['use_oversea_cdn'] = config.ARGS.UseOSCdn + config.API_HEADER['use_webp'] = config.ARGS.UseWebp + if config.ARGS.Proxy: config.PROXIES = { - "http": ARGS.Proxy, - "https": ARGS.Proxy + "http": config.ARGS.Proxy, + "https": config.ARGS.Proxy } - if ARGS.Output: - config.SETTINGS['download_path'] = ARGS.Output - manga_chapter_json = manga_chapter(ARGS.MangaPath, ARGS.MangaGroup) + if config.ARGS.Output: + config.SETTINGS['download_path'] = config.ARGS.Output + manga_chapter_json = manga_chapter(config.ARGS.MangaPath, config.ARGS.MangaGroup) chapter_allocation(manga_chapter_json) print(f"[bold green][:white_check_mark: ]漫画已经下载完成![/]") @@ -501,9 +496,9 @@ def manga_chapter(manga_path_word, group_path_word): sys.exit() # 询问应该如何下载 # 如果是命令行参数就直接返回对应 - if ARGS: - return_json["start"] = int(ARGS.MangaStart) - 1 - return_json["end"] = int(ARGS.MangaEnd) + if config.ARGS: + return_json["start"] = int(config.ARGS.MangaStart) - 1 + return_json["end"] = int(config.ARGS.MangaEnd) return return_json want_to = int(Prompt.ask(f"获取到{manga_chapter_json['results']['total']}话内容,请问如何下载?" f"[italic yellow](0:全本下载,1:范围下载,2:单话下载)[/]", @@ -589,7 +584,7 @@ def chapter_allocation(manga_chapter_json): t.join() threads.clear() # 实施添加下载进度 - if ARGS and ARGS.subscribe == "1": + if config.ARGS and config.ARGS.subscribe == "1": save_new_update(manga_chapter_info_json['results']['chapter']['comic_path_word'], manga_chapter_info_json['results']['chapter']['index'] + 1) @@ -632,27 +627,30 @@ def download(url, filename, overwrite=False): def main(): - global ARGS loaded_settings = load_settings() if not loaded_settings[0]: print(f"[bold red]{loaded_settings[1]},我们将重新为您设置[/]") set_settings() - parse_args() - if ARGS: - if ARGS.subscribe == "1": + config.ARGS = parse_args() + if config.ARGS and len(sys.argv) != 1: + if config.ARGS.subscribe == "1": print( "[bold purple]请注意!此模式下可能会导致部分img下载失败,如果遇见报错还请您自行删除更新列表然后重新添加后运行,此程序会重新下载并跳过已下载内容[/]") update_download() sys.exit() - if ARGS.MangaPath and ARGS.MangaEnd and ARGS.MangaStart: + if config.ARGS.MangaPath and config.ARGS.MangaEnd and config.ARGS.MangaStart: command_mode() # 防止运行完成后又触发正常模式 sys.exit() else: print("[bold red]命令行参数中缺少必要字段,将切换到普通模式[/]") - ARGS = None + config.ARGS = None welcome() if __name__ == '__main__': - main() + try: + main() + except KeyboardInterrupt: + print("\n[bold green]正在关闭,感谢您使用本程序[/]") + exit(0) diff --git a/settings.py b/settings.py index 559a5b2..2f8ae10 100644 --- a/settings.py +++ b/settings.py @@ -219,7 +219,8 @@ def change_settings(): else: res = loginhelper(username, password, api_urls[choice - 1]) if res["token"]: - config.SETTINGS["username"] = f"Token {res['token']}" + config.SETTINGS["authorization"] = f"Token {res['token']}" + config.SETTINGS["username"] = username config.SETTINGS["salt"] = res["salt"] config.SETTINGS["password"] = res["password_enc"] break