Update core.py
This commit is contained in:
171
core.py
171
core.py
@@ -238,6 +238,7 @@ def get_info(json_data): # 返回json里的数据
|
|||||||
release = json_data.get('release')
|
release = json_data.get('release')
|
||||||
number = json_data.get('number')
|
number = json_data.get('number')
|
||||||
cover = json_data.get('cover')
|
cover = json_data.get('cover')
|
||||||
|
trailer = json_data.get('trailer')
|
||||||
website = json_data.get('website')
|
website = json_data.get('website')
|
||||||
series = json_data.get('series')
|
series = json_data.get('series')
|
||||||
label = json_data.get('label', "")
|
label = json_data.get('label', "")
|
||||||
@@ -326,6 +327,44 @@ 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):
|
||||||
|
if download_file_with_filename(trailer, number + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) == 'failed':
|
||||||
|
return
|
||||||
|
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
|
||||||
|
for i in range(retry):
|
||||||
|
if os.path.getsize(path+'/' + number + c_word + '-trailer.mp4') == 0:
|
||||||
|
print('[!]Video Download Failed! Trying again. [{}/3]', i + 1)
|
||||||
|
download_file_with_filename(trailer, number + c_word + '-trailer.mp4', path, conf, filepath, failed_folder)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
if os.path.getsize(path + '/' + number + c_word + '-trailer.mp4') == 0:
|
||||||
|
return
|
||||||
|
print('[+]Video Downloaded!', path + '/' + number + c_word + '-trailer.mp4')
|
||||||
|
|
||||||
|
# 剧照下载成功,否则移动到failed
|
||||||
|
def extrafanart_download(data, path, conf: config.Config, filepath, failed_folder):
|
||||||
|
j = 1
|
||||||
|
path = path + '/' + conf.get_extrafanart()
|
||||||
|
for url in data:
|
||||||
|
if download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath, failed_folder) == 'failed':
|
||||||
|
moveFailedFolder(filepath, failed_folder)
|
||||||
|
return
|
||||||
|
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
|
||||||
|
for i in range(retry):
|
||||||
|
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
|
||||||
|
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
|
||||||
|
download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath,
|
||||||
|
failed_folder)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
|
||||||
|
return
|
||||||
|
print('[+]Image Downloaded!', path + '/extrafanart-' + str(j) + '.jpg')
|
||||||
|
j += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 封面是否下载成功,否则移动到failed
|
# 封面是否下载成功,否则移动到failed
|
||||||
def image_download(cover, number, c_word, path, conf: config.Config, filepath, failed_folder):
|
def image_download(cover, number, c_word, path, conf: config.Config, filepath, failed_folder):
|
||||||
@@ -397,6 +436,7 @@ def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, fa
|
|||||||
print(" <num>" + number + "</num>", file=code)
|
print(" <num>" + number + "</num>", file=code)
|
||||||
print(" <premiered>" + release + "</premiered>", file=code)
|
print(" <premiered>" + release + "</premiered>", file=code)
|
||||||
print(" <cover>" + cover + "</cover>", file=code)
|
print(" <cover>" + cover + "</cover>", 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 + c_word + ".nfo")
|
||||||
@@ -428,9 +468,70 @@ def cutImage(imagecut, path, number, c_word):
|
|||||||
shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + c_word + '-poster.jpg')
|
shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + c_word + '-poster.jpg')
|
||||||
print('[+]Image Copyed! ' + path + '/' + number + c_word + '-poster.jpg')
|
print('[+]Image Copyed! ' + path + '/' + number + c_word + '-poster.jpg')
|
||||||
|
|
||||||
|
# 此函数从gui版copy过来用用
|
||||||
|
# 参数说明
|
||||||
|
# poster_path
|
||||||
|
# thumb_path
|
||||||
|
# cn_sub 中文字幕 参数值为 1 0
|
||||||
|
# leak 流出 参数值为 1 0
|
||||||
|
# uncensored 无码 参数值为 1 0
|
||||||
|
# ========================================================================加水印
|
||||||
|
def add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf:config.Config):
|
||||||
|
mark_type = ''
|
||||||
|
if cn_sub:
|
||||||
|
mark_type += ',字幕'
|
||||||
|
if leak:
|
||||||
|
mark_type += ',流出'
|
||||||
|
if uncensored:
|
||||||
|
mark_type += ',无码'
|
||||||
|
add_mark_thread(thumb_path, cn_sub, leak, uncensored, conf)
|
||||||
|
print('[+]Thumb Add Mark: ' + mark_type.strip(','))
|
||||||
|
add_mark_thread(poster_path, cn_sub, leak, uncensored, conf)
|
||||||
|
print('[+]Poster Add Mark: ' + mark_type.strip(','))
|
||||||
|
|
||||||
|
def add_mark_thread(pic_path, cn_sub, leak, uncensored, conf):
|
||||||
|
size = 14
|
||||||
|
img_pic = Image.open(pic_path)
|
||||||
|
# 获取自定义位置,取余配合pos达到顺时针添加的效果
|
||||||
|
# 左上 0, 右上 1, 右下 2, 左下 3
|
||||||
|
count = conf.watermark_type()
|
||||||
|
if cn_sub == 1 or cn_sub == '1':
|
||||||
|
add_to_pic(pic_path, img_pic, size, count, 1) # 添加
|
||||||
|
count = (count + 1) % 4
|
||||||
|
if leak == 1 or leak == '1':
|
||||||
|
add_to_pic(pic_path, img_pic, size, count, 2)
|
||||||
|
count = (count + 1) % 4
|
||||||
|
if uncensored == 1 or uncensored == '1':
|
||||||
|
add_to_pic(pic_path, img_pic, size, count, 3)
|
||||||
|
img_pic.close()
|
||||||
|
|
||||||
|
def add_to_pic(pic_path, img_pic, size, count, mode):
|
||||||
|
mark_pic_path = ''
|
||||||
|
if mode == 1:
|
||||||
|
mark_pic_path = 'Img/SUB.png'
|
||||||
|
elif mode == 2:
|
||||||
|
mark_pic_path = 'Img/LEAK.png'
|
||||||
|
elif mode == 3:
|
||||||
|
mark_pic_path = 'Img/UNCENSORED.png'
|
||||||
|
img_subt = Image.open(mark_pic_path)
|
||||||
|
scroll_high = int(img_pic.height / size)
|
||||||
|
scroll_wide = int(scroll_high * img_subt.width / img_subt.height)
|
||||||
|
img_subt = img_subt.resize((scroll_wide, scroll_high), Image.ANTIALIAS)
|
||||||
|
r, g, b, a = img_subt.split() # 获取颜色通道,保持png的透明性
|
||||||
|
# 封面四个角的位置
|
||||||
|
pos = [
|
||||||
|
{'x': 0, 'y': 0},
|
||||||
|
{'x': img_pic.width - scroll_wide, 'y': 0},
|
||||||
|
{'x': img_pic.width - scroll_wide, 'y': img_pic.height - scroll_high},
|
||||||
|
{'x': 0, 'y': img_pic.height - scroll_high},
|
||||||
|
]
|
||||||
|
img_pic.paste(img_subt, (pos[count]['x'], pos[count]['y']), mask=a)
|
||||||
|
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, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置
|
||||||
houzhui = str(re.search('[.](iso|ISO|AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm)$', filepath).group())
|
media_res = conf.media_rule()
|
||||||
|
houzhui = str(re.search(media_res + '$', filepath).group())
|
||||||
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 使用软链接
|
||||||
@@ -438,15 +539,14 @@ def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config):
|
|||||||
os.symlink(filepath, path + '/' + number + c_word + houzhui)
|
os.symlink(filepath, path + '/' + number + c_word + houzhui)
|
||||||
else:
|
else:
|
||||||
os.rename(filepath, path + '/' + number + c_word + houzhui)
|
os.rename(filepath, path + '/' + number + c_word + houzhui)
|
||||||
if os.path.exists(file_parent_origin_path + '/' + number + c_word + '.srt'): # 字幕移动
|
sub_res = conf.sub_rule()
|
||||||
os.rename(file_parent_origin_path + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt')
|
|
||||||
print('[+]Sub moved!')
|
for subname in sub_res:
|
||||||
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.ssa'):
|
if os.path.exists(os.getcwd() + '/' + number + c_word + subname): # 字幕移动
|
||||||
os.rename(file_parent_origin_path + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa')
|
os.rename(os.getcwd() + '/' + number + c_word + subname, path + '/' + number + c_word + subname)
|
||||||
print('[+]Sub moved!')
|
print('[+]Sub moved!')
|
||||||
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.sub'):
|
return True
|
||||||
os.rename(file_parent_origin_path + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub')
|
|
||||||
print('[+]Sub moved!')
|
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
print('[-]File Exists! Please check your movie!')
|
print('[-]File Exists! Please check your movie!')
|
||||||
print('[-]move to the root folder of the program.')
|
print('[-]move to the root folder of the program.')
|
||||||
@@ -459,23 +559,22 @@ def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config):
|
|||||||
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, c_word, conf): # 文件路径,番号,后缀,要移动至的位置
|
||||||
if multi_part == 1:
|
if multi_part == 1:
|
||||||
number += part # 这时number会被附加上CD1后缀
|
number += part # 这时number会被附加上CD1后缀
|
||||||
houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm|iso|ISO)$', filepath).group())
|
media_res = conf.media_rule()
|
||||||
|
houzhui = str(re.search(media_res + '$', filepath).group())
|
||||||
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 + c_word + houzhui)
|
||||||
else:
|
else:
|
||||||
os.rename(filepath, path + '/' + number + part + c_word + houzhui)
|
os.rename(filepath, path + '/' + number + part + c_word + houzhui)
|
||||||
if os.path.exists(file_parent_origin_path + '/' + number + '.srt'): # 字幕移动
|
|
||||||
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt')
|
sub_res = conf.sub_rule()
|
||||||
print('[+]Sub moved!')
|
for subname in sub_res:
|
||||||
elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.ass'):
|
if os.path.exists(os.getcwd() + '/' + number + c_word + subname): # 字幕移动
|
||||||
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.ass', path + '/' + number + part + c_word + '.ass')
|
os.rename(os.getcwd() + '/' + number + c_word + subname, path + '/' + number + c_word + subname)
|
||||||
print('[+]Sub moved!')
|
print('[+]Sub moved!')
|
||||||
elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.sub'):
|
print('[!]Success')
|
||||||
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.sub', path + '/' + number + part + c_word + '.sub')
|
return True
|
||||||
print('[+]Sub moved!')
|
|
||||||
print('[!]Success')
|
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
print('[-]File Exists! Please check your movie!')
|
print('[-]File Exists! Please check your movie!')
|
||||||
print('[-]move to the root folder of the program.')
|
print('[-]move to the root folder of the program.')
|
||||||
@@ -546,8 +645,19 @@ def core_main(file_path, number_th, conf: config.Config):
|
|||||||
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' # 中文字幕影片后缀
|
||||||
|
|
||||||
|
# 判断是否无码
|
||||||
|
if is_uncensored(number):
|
||||||
|
uncensored = 1
|
||||||
|
else:
|
||||||
|
uncensored = 0
|
||||||
|
|
||||||
|
|
||||||
if '流出' in filepath:
|
if '流出' in filepath:
|
||||||
liuchu = '流出'
|
liuchu = '流出'
|
||||||
|
leak = 1
|
||||||
|
else:
|
||||||
|
leak = 0
|
||||||
|
|
||||||
# 调试模式检测
|
# 调试模式检测
|
||||||
if conf.debug():
|
if conf.debug():
|
||||||
@@ -570,6 +680,14 @@ def core_main(file_path, number_th, conf: config.Config):
|
|||||||
# creatFolder会返回番号路径
|
# creatFolder会返回番号路径
|
||||||
image_download( json_data.get('cover'), number, c_word, path, conf, filepath, conf.failed_folder())
|
image_download( json_data.get('cover'), number, c_word, path, conf, filepath, conf.failed_folder())
|
||||||
|
|
||||||
|
# 下载预告片
|
||||||
|
if json_data.get('trailer'):
|
||||||
|
trailer_download(json_data.get('trailer'), c_word, number, path, filepath, conf, conf.failed_folder())
|
||||||
|
|
||||||
|
# 下载剧照 data, path, conf: config.Config, filepath, failed_folder
|
||||||
|
if json_data.get('extrafanart'):
|
||||||
|
extrafanart_download(json_data.get('extrafanart'), path, conf, filepath, conf.failed_folder())
|
||||||
|
|
||||||
# 裁剪图
|
# 裁剪图
|
||||||
cutImage(imagecut, path, number, c_word)
|
cutImage(imagecut, path, number, c_word)
|
||||||
|
|
||||||
@@ -578,6 +696,17 @@ def core_main(file_path, number_th, conf: config.Config):
|
|||||||
|
|
||||||
# 移动文件
|
# 移动文件
|
||||||
paste_file_to_folder(filepath, path, number, c_word, conf)
|
paste_file_to_folder(filepath, path, number, c_word, conf)
|
||||||
|
|
||||||
|
poster_path = path + '/' + number + c_word + '-poster.jpg'
|
||||||
|
thumb_path = path + '/' + number + c_word + '-thumb.jpg'
|
||||||
|
if conf.is_watermark():
|
||||||
|
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)
|
||||||
|
|
||||||
elif conf.main_mode() == 2:
|
elif conf.main_mode() == 2:
|
||||||
# 移动文件
|
# 移动文件
|
||||||
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, c_word, conf)
|
||||||
|
poster_path = path + '/' + number + c_word + '-poster.jpg'
|
||||||
|
thumb_path = path + '/' + number + c_word + '-thumb.jpg'
|
||||||
|
if conf.is_watermark():
|
||||||
|
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user