Update core.py

文件中有 uncensored 也辨認為流出
命名流出添加 -流出
This commit is contained in:
mcdull
2021-03-28 20:02:43 +08:00
committed by GitHub
parent 53487bbfe6
commit d4247c967a

116
core.py
View File

@@ -294,9 +294,9 @@ 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, c_word, conf: config.Config, filepath, failed_folder): def small_cover_check(path, number, cover_small, leak_word, c_word, conf: config.Config, filepath, failed_folder):
download_file_with_filename(cover_small, number + 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, failed_folder)
print('[+]Image Downloaded! ' + path + '/' + number + c_word + '-poster.jpg') print('[+]Image Downloaded! ' + path + '/' + number + leak_word + c_word + '-poster.jpg')
def create_folder(success_folder, location_rule, json_data, conf: config.Config): # 创建文件夹 def create_folder(success_folder, location_rule, json_data, conf: config.Config): # 创建文件夹
@@ -376,20 +376,20 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath, failed_folder)
return return
def trailer_download(trailer, c_word, number, path, filepath, conf: config.Config, failed_folder): def trailer_download(trailer, leak_word, c_word, number, path, filepath, conf: config.Config, failed_folder):
if download_file_with_filename(trailer, number + 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_folder) == 'failed':
return return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy() switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry): for i in range(retry):
if os.path.getsize(path+'/' + number + 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 + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) download_file_with_filename(trailer, number + leak_word + c_word + '-trailer.mp4', path, conf, filepath, failed_folder)
continue continue
else: else:
break break
if os.path.getsize(path + '/' + number + c_word + '-trailer.mp4') == 0: if os.path.getsize(path + '/' + number + leak_word + c_word + '-trailer.mp4') == 0:
return return
print('[+]Video Downloaded!', path + '/' + number + 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, failed_folder):
@@ -416,32 +416,32 @@ def extrafanart_download(data, path, conf: config.Config, filepath, failed_folde
# 封面是否下载成功否则移动到failed # 封面是否下载成功否则移动到failed
def image_download(cover, number, c_word, path, conf: config.Config, filepath, failed_folder): def image_download(cover, number, leak_word, c_word, path, conf: config.Config, filepath, failed_folder):
if download_file_with_filename(cover, number + 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_folder) == 'failed':
moveFailedFolder(filepath, failed_folder) moveFailedFolder(filepath, failed_folder)
return return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy() switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry): for i in range(retry):
if os.path.getsize(path + '/' + number + 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 + c_word + '-fanart.jpg', path, conf, filepath, failed_folder) download_file_with_filename(cover, number + leak_word + c_word + '-fanart.jpg', path, conf, filepath, failed_folder)
continue continue
else: else:
break break
if os.path.getsize(path + '/' + number + c_word + '-fanart.jpg') == 0: if os.path.getsize(path + '/' + number + leak_word + c_word + '-fanart.jpg') == 0:
return return
print('[+]Image Downloaded!', path + '/' + number + c_word + '-fanart.jpg') print('[+]Image Downloaded!', path + '/' + number + leak_word + c_word + '-fanart.jpg')
shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + c_word + '-thumb.jpg') shutil.copyfile(path + '/' + number + leak_word + c_word + '-fanart.jpg',path + '/' + number + leak_word + c_word + '-thumb.jpg')
def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, failed_folder, tag, actor_list, liuchu): def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, filepath, failed_folder, tag, actor_list, liuchu):
title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label = get_info(json_data) title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label = get_info(json_data)
try: try:
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path) os.makedirs(path)
with open(path + "/" + number + part + c_word + ".nfo", "wt", encoding='UTF-8') as code: with open(path + "/" + number + part + leak_word + c_word + ".nfo", "wt", encoding='UTF-8') as code:
print('<?xml version="1.0" encoding="UTF-8" ?>', file=code) print('<?xml version="1.0" encoding="UTF-8" ?>', file=code)
print("<movie>", file=code) print("<movie>", file=code)
print(" <title>" + naming_rule + "</title>", file=code) print(" <title>" + naming_rule + "</title>", file=code)
@@ -453,9 +453,9 @@ def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, fa
print(" <plot>" + outline + "</plot>", file=code) print(" <plot>" + outline + "</plot>", file=code)
print(" <runtime>" + str(runtime).replace(" ", "") + "</runtime>", file=code) print(" <runtime>" + str(runtime).replace(" ", "") + "</runtime>", file=code)
print(" <director>" + director + "</director>", file=code) print(" <director>" + director + "</director>", file=code)
print(" <poster>" + number + c_word + "-poster.jpg</poster>", file=code) print(" <poster>" + number + leak_word + c_word + "-poster.jpg</poster>", file=code)
print(" <thumb>" + number + c_word + "-thumb.jpg</thumb>", file=code) print(" <thumb>" + number + leak_word + c_word + "-thumb.jpg</thumb>", file=code)
print(" <fanart>" + number + c_word + '-fanart.jpg' + "</fanart>", file=code) print(" <fanart>" + number + leak_word + c_word + '-fanart.jpg' + "</fanart>", file=code)
try: try:
for key in actor_list: for key in actor_list:
print(" <actor>", file=code) print(" <actor>", file=code)
@@ -489,7 +489,7 @@ def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, fa
print(" <trailer>" + trailer + "</trailer>", file=code) print(" <trailer>" + trailer + "</trailer>", file=code)
print(" <website>" + website + "</website>", file=code) print(" <website>" + website + "</website>", file=code)
print("</movie>", file=code) print("</movie>", file=code)
print("[+]Wrote! " + path + "/" + number + part + c_word + ".nfo") print("[+]Wrote! " + path + "/" + number + part + leak_word + c_word + ".nfo")
except IOError as e: except IOError as e:
print("[-]Write Failed!") print("[-]Write Failed!")
print(e) print(e)
@@ -502,21 +502,21 @@ def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, fa
return return
def cutImage(imagecut, path, number, c_word): def cutImage(imagecut, path, number, leak_word, c_word):
if imagecut == 1: # 剪裁大封面 if imagecut == 1: # 剪裁大封面
try: try:
img = Image.open(path + '/' + number + c_word + '-fanart.jpg') img = Image.open(path + '/' + number + leak_word + c_word + '-fanart.jpg')
imgSize = img.size imgSize = img.size
w = img.width w = img.width
h = img.height h = img.height
img2 = img.crop((w / 1.9, 0, w, h)) img2 = img.crop((w / 1.9, 0, w, h))
img2.save(path + '/' + number + c_word + '-poster.jpg') img2.save(path + '/' + number + leak_word + c_word + '-poster.jpg')
print('[+]Image Cutted! ' + path + '/' + number + c_word + '-poster.jpg') print('[+]Image Cutted! ' + path + '/' + number + leak_word + c_word + '-poster.jpg')
except: except:
print('[-]Cover cut failed!') print('[-]Cover cut failed!')
elif imagecut == 0: # 复制封面 elif imagecut == 0: # 复制封面
shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + c_word + '-poster.jpg') shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + leak_word + c_word + '-poster.jpg')
print('[+]Image Copyed! ' + path + '/' + number + c_word + '-poster.jpg') print('[+]Image Copyed! ' + path + '/' + number + leak_word + c_word + '-poster.jpg')
# 此函数从gui版copy过来用用 # 此函数从gui版copy过来用用
# 参数说明 # 参数说明
@@ -581,20 +581,20 @@ def add_to_pic(pic_path, img_pic, size, count, mode):
img_pic.save(pic_path, quality=95) img_pic.save(pic_path, quality=95)
# ========================结束================================= # ========================结束=================================
def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置 def paste_file_to_folder(filepath, path, number, leak_word, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置
houzhui = os.path.splitext(filepath)[1].replace(",","") houzhui = os.path.splitext(filepath)[1].replace(",","")
file_parent_origin_path = str(pathlib.Path(filepath).parent) file_parent_origin_path = str(pathlib.Path(filepath).parent)
try: try:
# 如果soft_link=1 使用软链接 # 如果soft_link=1 使用软链接
if conf.soft_link(): if conf.soft_link():
os.symlink(filepath, path + '/' + number + c_word + houzhui) os.symlink(filepath, path + '/' + number + leak_word + c_word + houzhui)
else: else:
os.rename(filepath, path + '/' + number + c_word + houzhui) os.rename(filepath, path + '/' + number + leak_word + c_word + houzhui)
sub_res = conf.sub_rule() sub_res = conf.sub_rule()
for subname in sub_res: for subname in sub_res:
if os.path.exists(number + c_word + subname): # 字幕移动 if os.path.exists(number + leak_word + c_word + subname): # 字幕移动
os.rename(number + c_word + subname, path + '/' + number + c_word + subname) os.rename(number + leak_word + c_word + subname, path + '/' + number + leak_word + c_word + subname)
print('[+]Sub moved!') print('[+]Sub moved!')
return True return True
@@ -607,21 +607,21 @@ def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config):
return return
def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, c_word, conf): # 文件路径,番号,后缀,要移动至的位置 def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, leak_word, c_word, conf): # 文件路径,番号,后缀,要移动至的位置
if multi_part == 1: if multi_part == 1:
number += part # 这时number会被附加上CD1后缀 number += part # 这时number会被附加上CD1后缀
houzhui = os.path.splitext(filepath)[1].replace(",","") houzhui = os.path.splitext(filepath)[1].replace(",","")
file_parent_origin_path = str(pathlib.Path(filepath).parent) file_parent_origin_path = str(pathlib.Path(filepath).parent)
try: try:
if conf.soft_link(): if conf.soft_link():
os.symlink(filepath, path + '/' + number + part + c_word + houzhui) os.symlink(filepath, path + '/' + number + part + leak_word + c_word + houzhui)
else: else:
os.rename(filepath, path + '/' + number + part + c_word + houzhui) os.rename(filepath, path + '/' + number + part + leak_word + c_word + houzhui)
sub_res = conf.sub_rule() sub_res = conf.sub_rule()
for subname in sub_res: for subname in sub_res:
if os.path.exists(os.getcwd() + '/' + number + c_word + subname): # 字幕移动 if os.path.exists(os.getcwd() + '/' + number + leak_word + c_word + subname): # 字幕移动
os.rename(os.getcwd() + '/' + number + c_word + subname, path + '/' + number + c_word + subname) os.rename(os.getcwd() + '/' + number + leak_word + c_word + subname, path + '/' + number + leak_word + c_word + subname)
print('[+]Sub moved!') print('[+]Sub moved!')
print('[!]Success') print('[!]Success')
return True return True
@@ -665,6 +665,7 @@ def core_main(file_path, number_th, conf: config.Config):
# =======================================================================初始化所需变量 # =======================================================================初始化所需变量
multi_part = 0 multi_part = 0
part = '' part = ''
leak_word = ''
c_word = '' c_word = ''
cn_sub = '' cn_sub = ''
liuchu = '' liuchu = ''
@@ -704,9 +705,10 @@ def core_main(file_path, number_th, conf: config.Config):
uncensored = 0 uncensored = 0
if '流出' in filepath: if '流出' in filepath or 'uncensored' in filepath:
liuchu = '流出' liuchu = '流出'
leak = 1 leak = 1
leak_word = '-流出' # 流出影片后缀
else: else:
leak = 0 leak = 0
@@ -729,14 +731,14 @@ 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'), c_word, conf, filepath, conf.failed_folder()) small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath, conf.failed_folder())
# creatFolder会返回番号路径 # creatFolder会返回番号路径
image_download( json_data.get('cover'), number, c_word, path, conf, filepath, conf.failed_folder()) image_download( json_data.get('cover'), number, leak_word, c_word, path, conf, filepath, conf.failed_folder())
try: try:
# 下载预告片 # 下载预告片
if json_data.get('trailer'): if json_data.get('trailer'):
trailer_download(json_data.get('trailer'), c_word, number, path, filepath, conf, conf.failed_folder()) trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf, conf.failed_folder())
except: except:
pass pass
@@ -747,16 +749,16 @@ def core_main(file_path, number_th, conf: config.Config):
except: except:
pass pass
# 裁剪图 # 裁剪图
cutImage(imagecut, path, number, c_word) cutImage(imagecut, path, number, leak_word, c_word)
# 打印文件 # 打印文件
print_files(path, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, filepath, conf.failed_folder(), tag, json_data.get('actor_list'), liuchu) print_files(path, leak_word, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, filepath, conf.failed_folder(), tag, json_data.get('actor_list'), liuchu)
# 移动文件 # 移动文件
paste_file_to_folder(filepath, path, number, c_word, conf) paste_file_to_folder(filepath, path, number, leak_word, c_word, conf)
poster_path = path + '/' + number + c_word + '-poster.jpg' poster_path = path + '/' + number + leak_word + c_word + '-poster.jpg'
thumb_path = path + '/' + number + c_word + '-thumb.jpg' thumb_path = path + '/' + number + leak_word + c_word + '-thumb.jpg'
if conf.is_watermark(): if conf.is_watermark():
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf) add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)
@@ -764,9 +766,9 @@ def core_main(file_path, number_th, conf: config.Config):
# 创建文件夹 # 创建文件夹
path = create_folder(conf.success_folder(), json_data.get('location_rule'), json_data, conf) path = create_folder(conf.success_folder(), json_data.get('location_rule'), json_data, conf)
# 移动文件 # 移动文件
paste_file_to_folder_mode2(filepath, path, multi_part, number, part, c_word, conf) paste_file_to_folder_mode2(filepath, path, multi_part, number, part, leak_word, c_word, conf)
poster_path = path + '/' + number + c_word + '-poster.jpg' poster_path = path + '/' + number + leak_word + c_word + '-poster.jpg'
thumb_path = path + '/' + number + c_word + '-thumb.jpg' thumb_path = path + '/' + number + leak_word + c_word + '-thumb.jpg'
if conf.is_watermark(): if conf.is_watermark():
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf) add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)
@@ -778,27 +780,27 @@ 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'), c_word, conf, filepath, conf.failed_folder()) small_cover_check(path, number, json_data.get('cover_small'), leak_word, c_word, conf, filepath, conf.failed_folder())
# creatFolder会返回番号路径 # creatFolder会返回番号路径
image_download(json_data.get('cover'), number, c_word, path, conf, filepath, conf.failed_folder()) image_download(json_data.get('cover'), number, leak_word, c_word, path, conf, filepath, conf.failed_folder())
# 下载预告片 # 下载预告片
if json_data.get('trailer'): if json_data.get('trailer'):
trailer_download(json_data.get('trailer'), c_word, number, path, filepath, conf, conf.failed_folder()) trailer_download(json_data.get('trailer'), leak_word, c_word, number, path, filepath, conf, conf.failed_folder())
# 下载剧照 data, path, conf: config.Config, filepath, failed_folder # 下载剧照 data, path, conf: config.Config, filepath, failed_folder
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, conf.failed_folder())
# 裁剪图 # 裁剪图
cutImage(imagecut, path, number, c_word) cutImage(imagecut, path, number, leak_word, c_word)
# 打印文件 # 打印文件
print_files(path, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, filepath, conf.failed_folder(), print_files(path, leak_word, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, filepath, conf.failed_folder(),
tag, json_data.get('actor_list'), liuchu) tag, json_data.get('actor_list'), liuchu)
poster_path = path + '/' + number + c_word + '-poster.jpg' poster_path = path + '/' + number + leak_word + c_word + '-poster.jpg'
thumb_path = path + '/' + number + c_word + '-thumb.jpg' thumb_path = path + '/' + number + leak_word + c_word + '-thumb.jpg'
if conf.is_watermark(): if conf.is_watermark():
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf) add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)