core.py同期

core.py同期
This commit is contained in:
ninjadogz 2019-10-31 22:15:43 +09:00
parent fb666feec5
commit 9663f7b473

89
core.py
View File

@ -178,6 +178,9 @@ def getDataFromJSON(file_number): #从JSON返回元数据
title = title.replace('<', '') title = title.replace('<', '')
title = title.replace('>', '') title = title.replace('>', '')
title = title.replace('|', '') title = title.replace('|', '')
tmpArr = cover_small.split(',')
if len(tmpArr) > 0:
cover_small = tmpArr[0].strip('\"').strip('\'')
# ====================处理异常字符 END================== #\/:*?"<>| # ====================处理异常字符 END================== #\/:*?"<>|
naming_rule = eval(config['Name_Rule']['naming_rule']) naming_rule = eval(config['Name_Rule']['naming_rule'])
@ -195,6 +198,14 @@ def smallCoverCheck():
img.save(path + '/' + number + '.png') img.save(path + '/' + number + '.png')
time.sleep(1) time.sleep(1)
os.remove(path + '/1.jpg') os.remove(path + '/1.jpg')
if option == 'kodi':
DownloadFileWithFilename(cover_small, '1.jpg', path)
img = Image.open(path + '/1.jpg')
w = img.width
h = img.height
img.save(path + '/' + number + '-poster.jpg')
time.sleep(1)
os.remove(path + '/1.jpg')
if option == 'plex': if option == 'plex':
DownloadFileWithFilename(cover_small, '1.jpg', path) DownloadFileWithFilename(cover_small, '1.jpg', path)
try: try:
@ -209,7 +220,7 @@ def creatFolder(): #创建文件夹
global actor global actor
global path global path
if len(os.getcwd()+path) > 240: #新建成功输出文件夹 if len(os.getcwd()+path) > 240: #新建成功输出文件夹
path = success_folder+'/'+location_rule.replace("'actor'","'manypeople'",3).replace("actor","'manypeople'",3) #path为影片+元数据所在目录 path = success_folder+'/'+location_rule.replace("'actor'","'超多人'",3).replace("actor","'超多人'",3) #path为影片+元数据所在目录
else: else:
path = success_folder+'/'+location_rule path = success_folder+'/'+location_rule
#print(path) #print(path)
@ -284,6 +295,11 @@ def imageDownload(filepath): #封面是否下载成功否则移动到failed
print('[+]Image Downloaded!', path + '/' + number + part + '.jpg') print('[+]Image Downloaded!', path + '/' + number + part + '.jpg')
else: else:
print('[+]Image Downloaded!', path + '/' + number + '.jpg') print('[+]Image Downloaded!', path + '/' + number + '.jpg')
elif option == 'kodi':
if DownloadFileWithFilename(cover, number + '-fanart.jpg', path) == 'failed':
moveFailedFolder()
DownloadFileWithFilename(cover, number + '-fanart.jpg', path)
print('[+]Image Downloaded!', path + '/' + number + '-fanart.jpg')
elif option == 'plex': elif option == 'plex':
if DownloadFileWithFilename(cover, 'fanart.jpg', path) == 'failed': if DownloadFileWithFilename(cover, 'fanart.jpg', path) == 'failed':
moveFailedFolder() moveFailedFolder()
@ -387,6 +403,52 @@ def PrintFiles(filepath):
print(" <website>" + "https://www.javbus.com/" + number + "</website>", file=code) print(" <website>" + "https://www.javbus.com/" + number + "</website>", file=code)
print("</movie>", file=code) print("</movie>", file=code)
print("[+]Writeed! " + path + "/" + number + ".nfo") print("[+]Writeed! " + path + "/" + number + ".nfo")
elif option == 'kodi':
with open(path + "/" + number + ".nfo", "wt", encoding='UTF-8') as code:
print("<movie>", file=code)
print(" <title>" + naming_rule + "</title>", file=code)
print(" <set>", file=code)
print(" </set>", file=code)
print(" <studio>" + studio + "+</studio>", file=code)
print(" <year>" + year + "</year>", file=code)
print(" <outline>" + outline + "</outline>", file=code)
print(" <plot>" + outline + "</plot>", file=code)
print(" <runtime>" + str(runtime).replace(" ", "") + "</runtime>", file=code)
print(" <director>" + director + "</director>", file=code)
print(" <poster>" + number + "-poster.jpg</poster>", file=code)
print(" <fanart>" + number + '-fanart.jpg' + "</fanart>", file=code)
try:
for key, value in actor_photo.items():
print(" <actor>", file=code)
print(" <name>" + key + "</name>", file=code)
if not actor_photo == '': # or actor_photo == []:
print(" <thumb>" + value + "</thumb>", file=code)
print(" </actor>", file=code)
except:
aaaa = ''
print(" <maker>" + studio + "</maker>", file=code)
print(" <label>", file=code)
print(" </label>", file=code)
if cn_sub == '1':
print(" <tag>中文字幕</tag>", file=code)
try:
for i in tag:
print(" <tag>" + i + "</tag>", file=code)
except:
aaaaa = ''
try:
for i in tag:
print(" <genre>" + i + "</genre>", file=code)
except:
aaaaaaaa = ''
if cn_sub == '1':
print(" <genre>中文字幕</genre>", file=code)
print(" <num>" + number + "</num>", file=code)
print(" <release>" + release + "</release>", file=code)
print(" <cover>" + cover + "</cover>", file=code)
print(" <website>" + "https://www.javbus.com/" + number + "</website>", file=code)
print("</movie>", file=code)
print("[+]Writeed! " + path + "/" + number + ".nfo")
except IOError as e: except IOError as e:
print("[-]Write Failed!") print("[-]Write Failed!")
print(e) print(e)
@ -428,9 +490,28 @@ def cutImage():
w = img.width w = img.width
h = img.height h = img.height
img.save(path + '/' + number + '.png') img.save(path + '/' + number + '.png')
elif option == 'kodi':
if imagecut == 1:
try:
img = Image.open(path + '/' + number + '-fanart.jpg')
imgSize = img.size
w = img.width
h = img.height
img2 = img.crop((w / 1.9, 0, w, h))
img2.save(path + '/' + number + '-poster.jpg')
except:
print('[-]Cover cut failed!')
elif imagecut == 0:
img = Image.open(path + '/' + number + '-fanart.jpg')
w = img.width
h = img.height
img.save(path + '/' + number + '-poster.jpg')
def pasteFileToFolder(filepath, path): #文件路径,番号,后缀,要移动至的位置 def pasteFileToFolder(filepath, path): #文件路径,番号,后缀,要移动至的位置
global houzhui global houzhui
houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|avi|rmvb|wmv|mov|mp4|mkv|flv|ts)$', filepath).group()) houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|avi|rmvb|wmv|mov|mp4|mkv|flv|ts)$', filepath).group())
if part == '-CD1' and option == 'kodi':
global number
number += part
try: try:
os.rename(filepath, path + '/' + number + houzhui) os.rename(filepath, path + '/' + number + houzhui)
except FileExistsError: except FileExistsError:
@ -446,6 +527,8 @@ def renameJpgToBackdrop_copy():
shutil.copy(path + '/poster.png', path + '/thumb.png') shutil.copy(path + '/poster.png', path + '/thumb.png')
if option == 'emby': if option == 'emby':
shutil.copy(path + '/' + number + '.jpg', path + '/Backdrop.jpg') shutil.copy(path + '/' + number + '.jpg', path + '/Backdrop.jpg')
if option == 'kodi':
shutil.copy(path + '/' + number + '-fanart.jpg', path + '/Backdrop.jpg')
def renameBackdropToJpg_copy(): def renameBackdropToJpg_copy():
if option == 'plex': if option == 'plex':
shutil.copy(path + '/fanart.jpg', path + '/Backdrop.jpg') shutil.copy(path + '/fanart.jpg', path + '/Backdrop.jpg')
@ -453,6 +536,8 @@ def renameBackdropToJpg_copy():
if option == 'emby': if option == 'emby':
shutil.copy(path + '/Backdrop.jpg', path + '/' + number + '.jpg') shutil.copy(path + '/Backdrop.jpg', path + '/' + number + '.jpg')
print('[+]Image Downloaded!', path + '/' + number + '.jpg') print('[+]Image Downloaded!', path + '/' + number + '.jpg')
if option == 'kodi':
print('跳过分集图片下载')
def get_part(filepath): def get_part(filepath):
try: try:
if re.search('-CD\d+', filepath): if re.search('-CD\d+', filepath):
@ -500,7 +585,7 @@ if __name__ == '__main__':
if part == '-CD1' or multi_part == 0: if part == '-CD1' or multi_part == 0:
smallCoverCheck() smallCoverCheck()
imageDownload(filepath) # creatFoder会返回番号路径 imageDownload(filepath) # creatFoder会返回番号路径
if multi_part == 1: if multi_part == 1 and option != 'kodi':
number += part number += part
PrintFiles(filepath) # 打印文件 PrintFiles(filepath) # 打印文件
cutImage() # 裁剪图 cutImage() # 裁剪图