diff --git a/ADC_function.py b/ADC_function.py index 16887a1..25c7fd2 100644 --- a/ADC_function.py +++ b/ADC_function.py @@ -522,9 +522,9 @@ def download_one_file(args) -> str: wrapped for map function """ - (url, save_path, json_data) = args - if json_data != None: - filebytes = get_html(url, return_type='content', json_headers=json_data['headers']) + (url, save_path, json_headers) = args + if json_headers != None: + filebytes = get_html(url, return_type='content', json_headers=json_headers['headers']) else: filebytes = get_html(url, return_type='content') if isinstance(filebytes, bytes) and len(filebytes): @@ -533,7 +533,7 @@ def download_one_file(args) -> str: return str(save_path) -def parallel_download_files(dn_list: typing.Iterable[typing.Sequence], parallel: int = 0, json_data=None): +def parallel_download_files(dn_list: typing.Iterable[typing.Sequence], parallel: int = 0, json_headers=None): """ download files in parallel 多线程下载文件 @@ -552,7 +552,7 @@ def parallel_download_files(dn_list: typing.Iterable[typing.Sequence], parallel: and fullpath and isinstance(fullpath, (str, Path)) and len(str(fullpath)): fullpath = Path(fullpath) fullpath.parent.mkdir(parents=True, exist_ok=True) - mp_args.append((url, fullpath, json_data)) + mp_args.append((url, fullpath, json_headers)) if not len(mp_args): return [] if not isinstance(parallel, int) or parallel not in range(1, 200): diff --git a/core.py b/core.py index 515ea4c..397b8b9 100644 --- a/core.py +++ b/core.py @@ -71,11 +71,14 @@ def get_info(json_data): # 返回json里的数据 return title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label -def small_cover_check(path, filename, cover_small, movie_path, json_data=None): +def small_cover_check(path, filename, cover_small, movie_path, json_headers=None): full_filepath = Path(path) / filename if config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(str(full_filepath)): return - download_file_with_filename(cover_small, filename, path, movie_path, json_data) + if json_headers != None: + download_file_with_filename(cover_small, filename, path, movie_path, json_headers['headers']) + else: + download_file_with_filename(cover_small, filename, path, movie_path) print('[+]Image Downloaded! ' + full_filepath.name) @@ -119,57 +122,36 @@ def download_file_with_filename(url, filename, path, filepath, json_headers=None for i in range(configProxy.retry): try: - if configProxy.enable: - if not os.path.exists(path): - try: - os.makedirs(path) - except: - print(f"[-]Fatal error! Can not make folder '{path}'") - os._exit(0) + if not os.path.exists(path): + try: + os.makedirs(path) + except: + print(f"[-]Fatal error! Can not make folder '{path}'") + os._exit(0) + headers = {'User-Agent': G_USER_AGENT} + if not json_headers == None: + if 'headers' in json_headers: + headers.update(json_headers) + if configProxy: proxies = configProxy.proxies() - headers = {'User-Agent': G_USER_AGENT} - if json_headers != None: - headers.update(json_headers) r = requests.get(url, headers=headers, timeout=configProxy.timeout, proxies=proxies) - if r == '': - print('[-]Movie Download Data not found!') - return - with open(os.path.join(path, filename), "wb") as code: - code.write(r.content) - return else: - if not os.path.exists(path): - try: - os.makedirs(path) - except: - print(f"[-]Fatal error! Can not make folder '{path}'") - os._exit(0) - headers = {'User-Agent': G_USER_AGENT} - if json_headers != None: - headers.update(json_headers) - r = requests.get(url, timeout=configProxy.timeout, headers=headers) - if r == '': - print('[-]Movie Download Data not found!') - return - with open(os.path.join(path, filename), "wb") as code: - code.write(r.content) + r = requests.get(url, headers=headers, timeout=configProxy.timeout) + if r == '': + print('[-]Movie Download Data not found!') return - except requests.exceptions.RequestException: - i += 1 - print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry)) - except requests.exceptions.ConnectionError: - i += 1 - print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry)) + with open(os.path.join(path, filename), "wb") as code: + code.write(r.content) + return except requests.exceptions.ProxyError: i += 1 - print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry)) - except requests.exceptions.ConnectTimeout: - i += 1 - print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry)) - except IOError: - print(f"[-]Create Directory '{path}' failed!") - moveFailedFolder(filepath) - return + print('[-]Image Download : Proxy error ' + str(i) + '/' + str(configProxy.retry)) + # except IOError: + # print(f"[-]Create Directory '{path}' failed!") + # moveFailedFolder(filepath) + # return + except Exception as e: + print('[-]Image Download :Error',e) print('[-]Connect Failed! Please check your Proxy or Network!') moveFailedFolder(filepath) return @@ -302,12 +284,12 @@ def image_ext(url): # 封面是否下载成功,否则移动到failed -def image_download(cover, fanart_path, thumb_path, path, filepath, json_data): +def image_download(cover, fanart_path, thumb_path, path, filepath, json_headers=None): full_filepath = os.path.join(path, fanart_path) if config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(full_filepath): return - if "headers" in json_data: - if download_file_with_filename(cover, fanart_path, path, filepath, json_data['headers']) == 'failed': + if json_headers != None: + if download_file_with_filename(cover, fanart_path, path, filepath, json_headers['headers']) == 'failed': moveFailedFolder(filepath) return else: @@ -319,8 +301,8 @@ def image_download(cover, fanart_path, thumb_path, path, filepath, json_data): for i in range(configProxy.retry): if file_not_exist_or_empty(full_filepath): print('[!]Image Download Failed! Trying again. [{}/3]', i + 1) - if "headers" in json_data: - download_file_with_filename(cover, fanart_path, path, filepath, json_data['headers']) + if json_headers != None: + download_file_with_filename(cover, fanart_path, path, filepath, json_headers['headers']) else: download_file_with_filename(cover, fanart_path, path, filepath) continue @@ -863,10 +845,16 @@ def core_main(movie_path, number_th, oCC): # 检查小封面, 如果image cut为3,则下载小封面 if imagecut == 3: - small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path, json_data) + if 'headers' in json_data: + small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path, json_data['headers']) + else: + small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path) # creatFolder会返回番号路径 - image_download( cover, fanart_path,thumb_path, path, movie_path, json_data) + if 'headers' in json_data: + image_download(cover, fanart_path, thumb_path, path, movie_path, json_data['headers']) + else: + image_download(cover, fanart_path, thumb_path, path, movie_path) if not multi_part or part.lower() == '-cd1': try: @@ -917,10 +905,16 @@ def core_main(movie_path, number_th, oCC): # 检查小封面, 如果image cut为3,则下载小封面 if imagecut == 3: - small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path, json_data) + if 'headers' in json_data: + small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path, json_data['headers']) + else: + small_cover_check(path, poster_path, json_data.get('cover_small'), movie_path) # creatFolder会返回番号路径 - image_download( cover, fanart_path, thumb_path, path, movie_path) + if 'headers' in json_data: + image_download(cover, fanart_path, thumb_path, path, movie_path, json_data['headers']) + else: + image_download(cover, fanart_path, thumb_path, path, movie_path) if not multi_part or part.lower() == '-cd1': try: