Update mapping table when github connection is successful

This commit is contained in:
yoshiko2
2023-05-08 05:50:12 +08:00
parent 0e0dedbfc1
commit 04feaf6d20

View File

@@ -23,14 +23,7 @@ from core import core_main, core_main_no_net_op, moveFailedFolder, debug_print
def check_update(local_version): def check_update(local_version):
htmlcode = "" htmlcode = get_html("https://apai.github.com/repos/yoshiko2/Movie_Data_Capture/releases/latest")
try:
htmlcode = get_html("https://api.github.com/repos/yoshiko2/Movie_Data_Capture/releases/latest")
except:
print("===== Failed to connect to github =====")
print("========== AUTO EXIT IN 60s ===========")
time.sleep(60)
os._exit(-1)
data = json.loads(htmlcode) data = json.loads(htmlcode)
remote = int(data["tag_name"].replace(".", "")) remote = int(data["tag_name"].replace(".", ""))
local_version = int(local_version.replace(".", "")) local_version = int(local_version.replace(".", ""))
@@ -41,7 +34,7 @@ def check_update(local_version):
print("[*]======================================================") print("[*]======================================================")
def argparse_function(ver: str) -> typing.Tuple[str, str, str, str, bool, bool]: def argparse_function(ver: str) -> typing.Tuple[str, str, str, str, bool, bool, str, str]:
conf = config.getInstance() conf = config.getInstance()
parser = argparse.ArgumentParser(epilog=f"Load Config file '{conf.ini_path}'.") parser = argparse.ArgumentParser(epilog=f"Load Config file '{conf.ini_path}'.")
parser.add_argument("file", default='', nargs='?', help="Single Movie file path.") parser.add_argument("file", default='', nargs='?', help="Single Movie file path.")
@@ -564,16 +557,9 @@ def main(args: tuple) -> Path:
if conf.update_check(): if conf.update_check():
try: try:
check_update(version) check_update(version)
except Exception as e:
print('[-]Update check failed!',e)
create_failed_folder(conf.failed_folder())
# Download Mapping Table, parallel version # Download Mapping Table, parallel version
def fmd(f) -> typing.Tuple[str, Path]: def fmd(f) -> typing.Tuple[str, Path]:
"""
"""
return ('https://raw.githubusercontent.com/yoshiko2/Movie_Data_Capture/master/MappingTable/' + f, return ('https://raw.githubusercontent.com/yoshiko2/Movie_Data_Capture/master/MappingTable/' + f,
Path.home() / '.local' / 'share' / 'mdc' / f) Path.home() / '.local' / 'share' / 'mdc' / f)
@@ -583,22 +569,20 @@ def main(args: tuple) -> Path:
if file_modification_days(str(v)) >= conf.mapping_table_validity(): if file_modification_days(str(v)) >= conf.mapping_table_validity():
print("[+]Mapping Table Out of date! Remove", str(v)) print("[+]Mapping Table Out of date! Remove", str(v))
os.remove(str(v)) os.remove(str(v))
try:
res = parallel_download_files(((k, v) for k, v in map_tab if not v.exists())) res = parallel_download_files(((k, v) for k, v in map_tab if not v.exists()))
for i, fp in enumerate(res, start=1): for i, fp in enumerate(res, start=1):
if fp and len(fp): if fp and len(fp):
print(f"[+] [{i}/{len(res)}] Mapping Table Downloaded to {fp}") print(f"[+] [{i}/{len(res)}] Mapping Table Downloaded to {fp}")
else: else:
print(f"[-] [{i}/{len(res)}] Mapping Table Download failed") print(f"[-] [{i}/{len(res)}] Mapping Table Download failed")
except Exception as e: except:
print("[!] ==================== ERROR ====================") print("[!]======================= WARNING ======================")
print("[!] " + "Mapping Table Download FAILED".center(47)) print('[!]' + '-- GITHUB CONNECTION FAILED --'.center(54))
print("[!] " + "无法连接github".center(47)) print('[!]' + 'Failed to check for updates'.center(54))
print("[!] " + "请过几小时再试试".center(47)) print('[!]' + '& update the mapping table'.center(54))
print("[!]", e) print("[!]======================================================")
print("[-] " + "------ AUTO EXIT AFTER 30s !!! ------ ".center(47))
time.sleep(30) create_failed_folder(conf.failed_folder())
os._exit(-1)
# create OpenCC converter # create OpenCC converter
ccm = conf.cc_convert_mode() ccm = conf.cc_convert_mode()