diff --git a/ADC_function.py b/ADC_function.py index aa0acc6..91f311f 100755 --- a/ADC_function.py +++ b/ADC_function.py @@ -64,7 +64,9 @@ def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None) return result.content else: return result.text - + except requests.exceptions.ProxyError: + print("[-]Proxy error! Please check your Proxy") + return except Exception as e: print("[-]Connect retry {}/{}".format(i + 1, retry_count)) print("[-]" + str(e)) diff --git a/AV_Data_Capture.py b/AV_Data_Capture.py index aa1d97f..dedbcd6 100755 --- a/AV_Data_Capture.py +++ b/AV_Data_Capture.py @@ -1,34 +1,37 @@ import argparse +import json import os +import re import sys +import shutil +import config +from ADC_function import get_html from number_parser import get_number -from core import * +from core import core_main def check_update(local_version): try: data = json.loads(get_html("https://api.github.com/repos/yoshiko2/AV_Data_Capture/releases/latest")) - except Exception as e: - print("[-] Failed to update! Please check new version manually:") - print("[-] https://github.com/yoshiko2/AV_Data_Capture/releases") + except: + print("[-]Failed to update! Please check new version manually:") + print("[-]https://github.com/yoshiko2/AV_Data_Capture/releases") print("[*]======================================================") return remote = data["tag_name"] - local = local_version - - if not local == remote: - line1 = "* New update " + str(remote) + " *" - print("[*]" + line1.center(54)) + if not local_version == remote: + print("[*]" + ("* New update " + str(remote) + " *").center(54)) print("[*]" + "↓ Download ↓".center(54)) - print("[*] https://github.com/yoshiko2/AV_Data_Capture/releases") + print("[*]https://github.com/yoshiko2/AV_Data_Capture/releases") print("[*]======================================================") def argparse_function(ver: str) -> [str, str, bool]: parser = argparse.ArgumentParser() parser.add_argument("file", default='', nargs='?', help="Single Movie file path.") + parser.add_argument("-p","--path",default='',nargs='?',help="Analysis folder path.") parser.add_argument("-c", "--config", default='config.ini', nargs='?', help="The config file Path.") parser.add_argument("-n", "--number", default='', nargs='?', help="Custom file number") parser.add_argument("-a", "--auto-exit", dest='autoexit', action="store_true", @@ -36,13 +39,12 @@ def argparse_function(ver: str) -> [str, str, bool]: parser.add_argument("-v", "--version", action="version", version=ver) args = parser.parse_args() - return args.file, args.config, args.number, args.autoexit + return args.file, args.path, args.config, args.number, args.autoexit def movie_lists(root, escape_folder): - for folder in escape_folder: - if folder in root: - return [] + if os.path.basename(root) in escape_folder: + return [] total = [] file_type = conf.media_type().upper().split(",") dirs = os.listdir(root) @@ -51,7 +53,7 @@ def movie_lists(root, escape_folder): if os.path.isdir(f): total += movie_lists(f, escape_folder) elif os.path.splitext(f)[1].upper() in file_type: - total.append(f) + total.append(os.path.abspath(f)) return total @@ -71,12 +73,13 @@ def rm_empty_folder(path): os.rmdir(path + '/' + file) # 删除这个空文件夹 print('[+]Deleting empty folder', path + '/' + file) except: - a = '' + pass def create_data_and_move(file_path: str, c: config.Config, debug): # Normalized number, eg: 111xxx-222.mp4 -> xxx-222.mp4 - n_number = get_number(debug, file_path) + n_number = get_number(debug, os.path.basename(file_path)) + file_path = os.path.abspath(file_path) if debug == True: print("[!]Making Data for [{}], the number is [{}]".format(file_path, n_number)) @@ -132,53 +135,45 @@ if __name__ == '__main__': version = '4.3.2' # Parse command line args - single_file_path, config_file, custom_number, auto_exit = argparse_function(version) + single_file_path, folder_path, config_file, custom_number, auto_exit = argparse_function(version) # Read config.ini conf = config.Config(path=config_file) - version_print = 'Version ' + version - print('[*]================== AV Data Capture ===================') - print('[*]' + version_print.center(54)) print('[*]======================================================') + print('[*]' + ('AV Data Capture ver.' + version).center(54)) if conf.update_check(): check_update(version) + if conf.debug(): + print('[+]Enable debug') + if conf.soft_link(): + print('[!]Enable soft link') + create_failed_folder(conf.failed_folder()) - # ========== Single File ========== - if not single_file_path == '': + if not single_file_path == '': #Single File print('[+]==================== Single File =====================') create_data_and_move_with_custom_number(single_file_path, conf, custom_number) - rm_empty_folder(conf.success_folder()) - rm_empty_folder(conf.failed_folder()) - print("[+]All finished!!!") - input("[+][+]Press enter key exit, you can check the error messge before you exit.") - sys.exit(0) - # ========== Single File ========== + else: + if folder_path == '': + folder_path = os.path.abspath(".") - movie_list = movie_lists(".", re.split("[,,]", conf.escape_folder())) + movie_list = movie_lists(folder_path, re.split("[,,]", conf.escape_folder())) - count = 0 - count_all = str(len(movie_list)) - print('[+]Find', count_all, 'movies') - if conf.debug() == True: - print('[+]' + ' DEBUG MODE ON '.center(54, '-')) - if conf.soft_link(): - print('[!] --- Soft link mode is ENABLE! ----') - for movie_path in movie_list: # 遍历电影列表 交给core处理 - count = count + 1 - percentage = str(count / int(count_all) * 100)[:4] + '%' - print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -') - create_data_and_move(movie_path, conf, conf.debug()) + count = 0 + count_all = str(len(movie_list)) + print('[+]Find', count_all, 'movies') + for movie_path in movie_list: # 遍历电影列表 交给core处理 + count = count + 1 + percentage = str(count / int(count_all) * 100)[:4] + '%' + print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -') + create_data_and_move(movie_path, conf, conf.debug()) rm_empty_folder(conf.success_folder()) rm_empty_folder(conf.failed_folder()) print("[+]All finished!!!") - if conf.auto_exit(): - sys.exit(0) - if auto_exit: - sys.exit(0) - input("Press enter key exit, you can check the error message before you exit...") + if not (conf.auto_exit() or auto_exit): + input("Press enter key exit, you can check the error message before you exit...") sys.exit(0)