Merge pull request #218 from 68cdrBxM8YdoJ/fix-single-file-input
Fix single movie input
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -102,3 +102,10 @@ venv.bak/
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# movie files
|
||||
*.mp4
|
||||
|
||||
# success/failed folder
|
||||
JAV_output/**/*
|
||||
failed/*
|
||||
@@ -5,6 +5,9 @@ import config
|
||||
|
||||
|
||||
def get_data_state(data: dict) -> bool: # 元数据获取失败检测
|
||||
if "title" not in data or "number" not in data:
|
||||
return False
|
||||
|
||||
if data["title"] is None or data["title"] == "" or data["title"] == "null":
|
||||
return False
|
||||
|
||||
|
||||
@@ -16,19 +16,14 @@ def check_update(current_version):
|
||||
print("[*]======================================================")
|
||||
|
||||
|
||||
def argparse_function(switch):
|
||||
def argparse_function() -> [str, str, bool]:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", default='',nargs='?', help="Single Movie file path.")
|
||||
parser.add_argument("file", default='', nargs='?', help="Single Movie file path.")
|
||||
parser.add_argument("-c", "--config", default='config.ini', nargs='?', help="The config file Path.")
|
||||
parser.add_argument("-a", "--auto-exit", dest='autoexit', action="store_true", help="Auto exit after program complete")
|
||||
args = parser.parse_args()
|
||||
if switch == 1:
|
||||
if args.file == '':
|
||||
return ''
|
||||
elif switch == 2:
|
||||
return args.config
|
||||
elif switch == 3:
|
||||
return args.autoexit
|
||||
|
||||
return args.file, args.config, args.autoexit
|
||||
|
||||
def movie_lists(root, escape_folder):
|
||||
for folder in escape_folder:
|
||||
@@ -86,10 +81,36 @@ def getNumber(filepath,absolute_path = False):
|
||||
return re.search(r'(.+?)\.', filepath)[0]
|
||||
|
||||
|
||||
def create_data_and_move(file_path: str, c: config.Config):
|
||||
# Normalized number, eg: 111xxx-222.mp4 -> xxx-222.mp4
|
||||
n_number = getNumber(file_path, absolute_path=True)
|
||||
|
||||
try:
|
||||
print("[!]Making Data for [{}], the number is [{}]".format(file_path, n_number))
|
||||
core_main(file_path, n_number, c)
|
||||
print("[*]======================================================")
|
||||
except Exception as err:
|
||||
print("[-] [{}] ERROR:".format(file_path))
|
||||
print('[-]', err)
|
||||
|
||||
if c.soft_link():
|
||||
print("[-]Link {} to failed folder".format(file_path))
|
||||
os.symlink(file_path, str(os.getcwd()) + "/" + conf.failed_folder() + "/")
|
||||
else:
|
||||
try:
|
||||
print("[-]Move [{}] to failed folder".format(file_path))
|
||||
shutil.move(file_path, str(os.getcwd()) + "/" + conf.failed_folder() + "/")
|
||||
except Exception as err:
|
||||
print('[!]', err)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
version = '3.2'
|
||||
|
||||
config_file = argparse_function(2)
|
||||
# Parse command line args
|
||||
single_file_path, config_file, auto_exit = argparse_function()
|
||||
|
||||
# Read config.ini
|
||||
conf = config.Config(path=config_file)
|
||||
|
||||
version_print = 'Version ' + version
|
||||
@@ -104,17 +125,14 @@ if __name__ == '__main__':
|
||||
os.chdir(os.getcwd())
|
||||
movie_list = movie_lists(".", re.split("[,,]", conf.escape_folder()))
|
||||
|
||||
#========== 野鸡番号拖动 ==========
|
||||
number_argparse = argparse_function(1)
|
||||
if not number_argparse == '':
|
||||
print("[!]Making Data for [" + number_argparse + "], the number is [" + getNumber(number_argparse,absolute_path = True) + "]")
|
||||
core_main(number_argparse, getNumber(number_argparse,absolute_path = True))
|
||||
print("[*]======================================================")
|
||||
# ========== 野鸡番号拖动 ==========
|
||||
if not single_file_path == '':
|
||||
create_data_and_move(single_file_path, conf)
|
||||
CEF(conf.success_folder())
|
||||
CEF(conf.failed_folder())
|
||||
print("[+]All finished!!!")
|
||||
input("[+][+]Press enter key exit, you can check the error messge before you exit.")
|
||||
os._exit(0)
|
||||
exit()
|
||||
# ========== 野鸡番号拖动 ==========
|
||||
|
||||
count = 0
|
||||
@@ -122,34 +140,15 @@ if __name__ == '__main__':
|
||||
print('[+]Find', count_all, 'movies')
|
||||
if conf.soft_link():
|
||||
print('[!] --- Soft link mode is ENABLE! ----')
|
||||
for i in movie_list: # 遍历电影列表 交给core处理
|
||||
for movie_path in movie_list: # 遍历电影列表 交给core处理
|
||||
count = count + 1
|
||||
percentage = str(count / int(count_all) * 100)[:4] + '%'
|
||||
print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -')
|
||||
# print("[!]Making Data for [" + i + "], the number is [" + getNumber(i) + "]")
|
||||
# core_main(i, getNumber(i))
|
||||
# print("[*]======================================================")
|
||||
try:
|
||||
print("[!]Making Data for [" + i + "], the number is [" + getNumber(i) + "]")
|
||||
core_main(i, getNumber(i), conf)
|
||||
print("[*]======================================================")
|
||||
except Exception as e: # 番号提取异常
|
||||
print('[-]' + i + ' ERROR :')
|
||||
print('[-]',e)
|
||||
if conf.soft_link():
|
||||
print('[-]Link', i, 'to failed folder')
|
||||
os.symlink(i, str(os.getcwd()) + '/' + conf.failed_folder() + '/')
|
||||
else:
|
||||
try:
|
||||
print('[-]Move ' + i + ' to failed folder')
|
||||
shutil.move(i, str(os.getcwd()) + '/' + conf.failed_folder() + '/')
|
||||
except Exception as e2:
|
||||
print('[!]', e2)
|
||||
continue
|
||||
create_data_and_move(movie_path, conf)
|
||||
|
||||
CEF(conf.success_folder())
|
||||
CEF(conf.failed_folder())
|
||||
print("[+]All finished!!!")
|
||||
if argparse_function(3) == True:
|
||||
os._exit(0)
|
||||
input("[+][+]Press enter key exit, you can check the error messge before you exit.")
|
||||
if auto_exit:
|
||||
exit(0)
|
||||
input("[+][+]Press enter key exit, you can check the error message before you exit.")
|
||||
20
core.py
20
core.py
@@ -52,14 +52,14 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
|
||||
"javbus": javbus.main,
|
||||
"mgstage": mgstage.main,
|
||||
"jav321": jav321.main,
|
||||
"xcity" : xcity.main,
|
||||
"xcity": xcity.main,
|
||||
}
|
||||
|
||||
# default fetch order list, from the begining to the end
|
||||
# default fetch order list, from the beginning to the end
|
||||
sources = conf.sources().split(',')
|
||||
|
||||
# if the input file name matches centain rules,
|
||||
# move some web service to the begining of the list
|
||||
# if the input file name matches certain rules,
|
||||
# move some web service to the beginning of the list
|
||||
if re.match(r"^\d{5,}", file_number) or (
|
||||
"HEYZO" in file_number or "heyzo" in file_number or "Heyzo" in file_number
|
||||
):
|
||||
@@ -71,12 +71,19 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
|
||||
elif "fc2" in file_number or "FC2" in file_number:
|
||||
sources.insert(0, sources.pop(sources.index("fc2")))
|
||||
|
||||
json_data = {}
|
||||
for source in sources:
|
||||
json_data = json.loads(func_mapping[source](file_number))
|
||||
# if any service return a valid return, break
|
||||
if get_data_state(json_data):
|
||||
break
|
||||
|
||||
# Return if data not found in all sources
|
||||
if not json_data:
|
||||
print('[-]Movie Data not found!')
|
||||
moveFailedFolder(filepath, conf.failed_folder())
|
||||
return
|
||||
|
||||
# ================================================网站规则添加结束================================================
|
||||
|
||||
title = json_data['title']
|
||||
@@ -424,6 +431,11 @@ def core_main(file_path, number_th, conf: config.Config):
|
||||
filepath = file_path # 影片的路径
|
||||
number = number_th
|
||||
json_data = get_data_from_json(number, filepath, conf) # 定义番号
|
||||
|
||||
# Return if blank dict returned (data not found)
|
||||
if not json_data:
|
||||
return
|
||||
|
||||
if json_data["number"] != number:
|
||||
# fix issue #119
|
||||
# the root cause is we normalize the search id
|
||||
|
||||
Reference in New Issue
Block a user