Merge pull request #528 from lededev/mvfailed

core.py:moveFailedFolder() just the same action as in AV_Data_Capture.py
This commit is contained in:
Yoshiko2
2021-06-26 16:46:11 +08:00
committed by GitHub
2 changed files with 44 additions and 44 deletions

View File

@@ -120,12 +120,13 @@ def create_data_and_move(file_path: str, c: config.Config, debug):
else: else:
try: try:
print("[-]Move [{}] to failed folder".format(file_path)) print("[-]Move [{}] to failed folder".format(file_path))
shutil.move(file_path, conf.failed_folder() + "/") shutil.move(file_path, conf.failed_folder() + "/" + file_name)
except Exception as err: except Exception as err:
print('[!]', err) print('[!]', err)
def create_data_and_move_with_custom_number(file_path: str, c: config.Config, custom_number): def create_data_and_move_with_custom_number(file_path: str, c: config.Config, custom_number):
file_name = os.path.basename(file_path)
try: try:
print("[!]Making Data for [{}], the number is [{}]".format(file_path, custom_number)) print("[!]Making Data for [{}], the number is [{}]".format(file_path, custom_number))
core_main(file_path, custom_number, c) core_main(file_path, custom_number, c)
@@ -136,11 +137,11 @@ def create_data_and_move_with_custom_number(file_path: str, c: config.Config, cu
if c.soft_link(): if c.soft_link():
print("[-]Link {} to failed folder".format(file_path)) print("[-]Link {} to failed folder".format(file_path))
os.symlink(file_path, conf.failed_folder() + "/") os.symlink(file_path, conf.failed_folder() + "/" + file_name)
else: else:
try: try:
print("[-]Move [{}] to failed folder".format(file_path)) print("[-]Move [{}] to failed folder".format(file_path))
shutil.move(file_path, conf.failed_folder() + "/") shutil.move(file_path, conf.failed_folder() + "/" + file_name)
except Exception as err: except Exception as err:
print('[!]', err) print('[!]', err)

81
core.py Normal file → Executable file
View File

@@ -35,17 +35,17 @@ def escape_path(path, escape_literals: str): # Remove escape literals
return path return path
def moveFailedFolder(filepath, failed_folder): def moveFailedFolder(filepath):
if config.Config().failed_move(): conf = config.Config()
root_path = str(pathlib.Path(filepath).parent) if conf.failed_move():
file_name = pathlib.Path(filepath).name failed_folder = conf.failed_folder()
destination_path = root_path + '/' + failed_folder + '/' file_name = os.path.basename(filepath)
if config.Config().soft_link(): if conf.soft_link():
print('[-]Create symlink to Failed output folder') print('[-]Create symlink to Failed output folder')
os.symlink(filepath, destination_path + '/' + file_name) os.symlink(filepath, failed_folder + '/' + file_name)
else: else:
print('[-]Move to Failed output folder') print('[-]Move to Failed output folder')
shutil.move(filepath, destination_path) shutil.move(filepath, failed_folder + '/' + file_name)
return return
@@ -130,7 +130,7 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
# Return if data not found in all sources # Return if data not found in all sources
if not json_data: if not json_data:
print('[-]Movie Data not found!') print('[-]Movie Data not found!')
moveFailedFolder(filepath, conf.failed_folder()) moveFailedFolder(filepath)
return return
# ================================================网站规则添加结束================================================ # ================================================网站规则添加结束================================================
@@ -169,7 +169,7 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
if title == '' or number == '': if title == '' or number == '':
print('[-]Movie Data not found!') print('[-]Movie Data not found!')
moveFailedFolder(filepath, conf.failed_folder()) moveFailedFolder(filepath)
return return
# if imagecut == '3': # if imagecut == '3':
@@ -316,8 +316,8 @@ def get_info(json_data): # 返回json里的数据
return title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label return title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label
def small_cover_check(path, number, cover_small, leak_word, c_word, conf: config.Config, filepath, failed_folder): def small_cover_check(path, number, cover_small, leak_word, c_word, conf: config.Config, filepath):
download_file_with_filename(cover_small, number + leak_word+ c_word + '-poster.jpg', path, conf, filepath, failed_folder) download_file_with_filename(cover_small, number + leak_word+ c_word + '-poster.jpg', path, conf, filepath)
print('[+]Image Downloaded! ' + path + '/' + number + leak_word + c_word + '-poster.jpg') print('[+]Image Downloaded! ' + path + '/' + number + leak_word + c_word + '-poster.jpg')
@@ -352,7 +352,7 @@ def trimblank(s: str):
# =====================资源下载部分=========================== # =====================资源下载部分===========================
# path = examle:photo , video.in the Project Folder! # path = examle:photo , video.in the Project Folder!
def download_file_with_filename(url, filename, path, conf: config.Config, filepath, failed_folder): def download_file_with_filename(url, filename, path, conf: config.Config, filepath):
configProxy = conf.proxy() configProxy = conf.proxy()
for i in range(configProxy.retry): for i in range(configProxy.retry):
@@ -395,17 +395,17 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
i += 1 i += 1
print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry)) print('[-]Image Download : Connect retry ' + str(i) + '/' + str(configProxy.retry))
print('[-]Connect Failed! Please check your Proxy or Network!') print('[-]Connect Failed! Please check your Proxy or Network!')
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
def trailer_download(trailer, leak_word, c_word, number, path, filepath, conf: config.Config, failed_folder): def trailer_download(trailer, leak_word, c_word, number, path, filepath, conf: config.Config):
if download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) == 'failed': if download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath) == 'failed':
return return
configProxy = conf.proxy() configProxy = conf.proxy()
for i in range(configProxy.retry): for i in range(configProxy.retry):
if os.path.getsize(path+'/' + number + leak_word + c_word + '-trailer.mp4') == 0: if os.path.getsize(path+'/' + number + leak_word + c_word + '-trailer.mp4') == 0:
print('[!]Video Download Failed! Trying again. [{}/3]', i + 1) print('[!]Video Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath)
continue continue
else: else:
break break
@@ -414,19 +414,18 @@ def trailer_download(trailer, leak_word, c_word, number, path, filepath, conf: c
print('[+]Video Downloaded!', path + '/' + number + leak_word + c_word + '-trailer.mp4') print('[+]Video Downloaded!', path + '/' + number + leak_word + c_word + '-trailer.mp4')
# 剧照下载成功否则移动到failed # 剧照下载成功否则移动到failed
def extrafanart_download(data, path, conf: config.Config, filepath, failed_folder): def extrafanart_download(data, path, conf: config.Config, filepath):
j = 1 j = 1
path = path + '/' + conf.get_extrafanart() path = path + '/' + conf.get_extrafanart()
for url in data: for url in data:
if download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath, failed_folder) == 'failed': if download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath) == 'failed':
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
configProxy = conf.proxy() configProxy = conf.proxy()
for i in range(configProxy.retry): for i in range(configProxy.retry):
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0: if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1) print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath, download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath)
failed_folder)
continue continue
else: else:
break break
@@ -438,16 +437,16 @@ def extrafanart_download(data, path, conf: config.Config, filepath, failed_folde
# 封面是否下载成功否则移动到failed # 封面是否下载成功否则移动到failed
def image_download(cover, number, leak_word, c_word, path, conf: config.Config, filepath, failed_folder): def image_download(cover, number, leak_word, c_word, path, conf: config.Config, filepath):
if download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath, failed_folder) == 'failed': if download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath) == 'failed':
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
configProxy = conf.proxy() configProxy = conf.proxy()
for i in range(configProxy.retry): for i in range(configProxy.retry):
if os.path.getsize(path + '/' + number + leak_word + c_word + '-fanart.jpg') == 0: if os.path.getsize(path + '/' + number + leak_word + c_word + '-fanart.jpg') == 0:
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1) print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath, failed_folder) download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath)
continue continue
else: else:
break break
@@ -522,12 +521,12 @@ def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, f
except IOError as e: except IOError as e:
print("[-]Write Failed!") print("[-]Write Failed!")
print(e) print(e)
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
except Exception as e1: except Exception as e1:
print(e1) print(e1)
print("[-]Write Failed!") print("[-]Write Failed!")
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
@@ -696,7 +695,7 @@ def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, leak_wo
print('[-]OS Error errno ' + oserr.errno) print('[-]OS Error errno ' + oserr.errno)
return return
def get_part(filepath, failed_folder): def get_part(filepath):
try: try:
if re.search('-CD\d+', filepath): if re.search('-CD\d+', filepath):
return re.findall('-CD\d+', filepath)[0] return re.findall('-CD\d+', filepath)[0]
@@ -704,7 +703,7 @@ def get_part(filepath, failed_folder):
return re.findall('-cd\d+', filepath)[0] return re.findall('-cd\d+', filepath)[0]
except: except:
print("[-]failed!Please rename the filename again!") print("[-]failed!Please rename the filename again!")
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath)
return return
@@ -756,7 +755,7 @@ def core_main(file_path, number_th, conf: config.Config):
# =======================================================================判断-C,-CD后缀 # =======================================================================判断-C,-CD后缀
if '-CD' in filepath or '-cd' in filepath: if '-CD' in filepath or '-cd' in filepath:
multi_part = 1 multi_part = 1
part = get_part(filepath, conf.failed_folder()) part = get_part(filepath)
if '-c.' in filepath or '-C.' in filepath or '中文' in filepath or '字幕' in filepath: if '-c.' in filepath or '-C.' in filepath or '中文' in filepath or '字幕' in filepath:
cn_sub = '1' cn_sub = '1'
c_word = '-C' # 中文字幕影片后缀 c_word = '-C' # 中文字幕影片后缀
@@ -794,21 +793,21 @@ def core_main(file_path, number_th, conf: config.Config):
# 检查小封面, 如果image cut为3则下载小封面 # 检查小封面, 如果image cut为3则下载小封面
if imagecut == 3: if imagecut == 3:
small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath, conf.failed_folder()) small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath)
# creatFolder会返回番号路径 # creatFolder会返回番号路径
image_download( json_data.get('cover'), number, leak_word, c_word, path, conf, filepath, conf.failed_folder()) image_download( json_data.get('cover'), number, leak_word, c_word, path, conf, filepath)
try: try:
# 下载预告片 # 下载预告片
if json_data.get('trailer'): if json_data.get('trailer'):
trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf, conf.failed_folder()) trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf)
except: except:
pass pass
try: try:
# 下载剧照 data, path, conf: config.Config, filepath, failed_folder # 下载剧照 data, path, conf: config.Config, filepath
if json_data.get('extrafanart'): if json_data.get('extrafanart'):
extrafanart_download(json_data.get('extrafanart'), path, conf, filepath, conf.failed_folder()) extrafanart_download(json_data.get('extrafanart'), path, conf, filepath)
except: except:
pass pass
# 裁剪图 # 裁剪图
@@ -843,18 +842,18 @@ def core_main(file_path, number_th, conf: config.Config):
# 检查小封面, 如果image cut为3则下载小封面 # 检查小封面, 如果image cut为3则下载小封面
if imagecut == 3: if imagecut == 3:
small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath, conf.failed_folder()) small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath)
# creatFolder会返回番号路径 # creatFolder会返回番号路径
image_download(json_data.get('cover'), number, leak_word, c_word, path, conf, filepath, conf.failed_folder()) image_download(json_data.get('cover'), number, leak_word, c_word, path, conf, filepath)
# 下载预告片 # 下载预告片
if json_data.get('trailer'): if json_data.get('trailer'):
trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf, conf.failed_folder()) trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf)
# 下载剧照 data, path, conf: config.Config, filepath, failed_folder # 下载剧照 data, path, conf: config.Config, filepath
if json_data.get('extrafanart'): if json_data.get('extrafanart'):
extrafanart_download(json_data.get('extrafanart'), path, conf, filepath, conf.failed_folder()) extrafanart_download(json_data.get('extrafanart'), path, conf, filepath)
# 裁剪图 # 裁剪图
cutImage(imagecut, path, number, leak_word, c_word) cutImage(imagecut, path, number, leak_word, c_word)