Skip to content

Commit

Permalink
修复重新设置登录问题以及优化args (#102)
Browse files Browse the repository at this point in the history
* 修复重新设置登录问题以及优化args

* Update python-app.yml (#103)
  • Loading branch information
misaka10843 authored Oct 9, 2024
1 parent 3f0666b commit c76919a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@
API_COUNTER = 0
IMG_API_COUNTER = 0
IMG_CURRENT_TIME = 0

ARGS = {}
48 changes: 23 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ]漫画已经下载完成![/]")

Expand Down Expand Up @@ -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:单话下载)[/]",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c76919a

Please sign in to comment.