Merge pull request #946 from mark5231/add_jellyfin

添加jellyfin中特有的一些设定
This commit is contained in:
Yoshiko2
2023-01-10 17:15:30 +08:00
committed by GitHub
4 changed files with 43 additions and 25 deletions

View File

@@ -60,9 +60,9 @@ def face_crop_height(filename, width, height):
return (0, 0, width, cropHeight)
def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False):
def cutImage(imagecut, path, thumb_path, poster_path, skip_facerec=False):
conf = config.getInstance()
fullpath_fanart = os.path.join(path, fanart_path)
fullpath_fanart = os.path.join(path, thumb_path)
fullpath_poster = os.path.join(path, poster_path)
aspect_ratio = conf.face_aspect_ratio()
if conf.face_aways_imagecut():

View File

@@ -21,8 +21,10 @@ nfo_skip_days = 30
ignore_failed_list = 0
download_only_missing_images = 1
mapping_table_validity = 7
; jellyfin中tags和genres重复因此可以只保存genres到nfo中
donot_save_tags = 0
; 一些jellyfin中特有的设置 (0:不开启, 1开启) 比如
; 在jellyfin中tags和genres重复因此可以只需保存genres到nfo中
; jellyfin中只需要保存thumb不需要保存fanart
jellyfin = 0
; 开启后tag和genere只显示演员
actor_only_tag = 0
sleep = 3

View File

@@ -213,8 +213,8 @@ class Config:
def mapping_table_validity(self) -> int:
return self.conf.getint("common", "mapping_table_validity")
def donot_save_tags(self) -> int:
return self.conf.getint("common", "donot_save_tags")
def jellyfin(self) -> int:
return self.conf.getint("common", "jellyfin")
def actor_only_tag(self) -> bool:
return self.conf.getboolean("common", "actor_only_tag")
@@ -443,7 +443,7 @@ class Config:
conf.set(sec1, "ignore_failed_list", 0)
conf.set(sec1, "download_only_missing_images", 1)
conf.set(sec1, "mapping_table_validity", 7)
conf.set(sec1, "donot_save_tags", 0)
conf.set(sec1, "jellyfin", 0)
sec2 = "advenced_sleep"
conf.add_section(sec2)

52
core.py
View File

@@ -279,15 +279,15 @@ def image_ext(url):
# 封面是否下载成功否则移动到failed
def image_download(cover, fanart_path, thumb_path, path, filepath, json_headers=None):
full_filepath = os.path.join(path, fanart_path)
full_filepath = os.path.join(path, thumb_path)
if config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(full_filepath):
return
if json_headers != None:
if download_file_with_filename(cover, fanart_path, path, filepath, json_headers['headers']) == 'failed':
if download_file_with_filename(cover, thumb_path, path, filepath, json_headers['headers']) == 'failed':
moveFailedFolder(filepath)
return
else:
if download_file_with_filename(cover, fanart_path, path, filepath) == 'failed':
if download_file_with_filename(cover, thumb_path, path, filepath) == 'failed':
moveFailedFolder(filepath)
return
@@ -296,16 +296,17 @@ def image_download(cover, fanart_path, thumb_path, path, filepath, json_headers=
if file_not_exist_or_empty(full_filepath):
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
if json_headers != None:
download_file_with_filename(cover, fanart_path, path, filepath, json_headers['headers'])
download_file_with_filename(cover, thumb_path, path, filepath, json_headers['headers'])
else:
download_file_with_filename(cover, fanart_path, path, filepath)
download_file_with_filename(cover, thumb_path, path, filepath)
continue
else:
break
if file_not_exist_or_empty(full_filepath):
return
print('[+]Image Downloaded!', Path(full_filepath).name)
shutil.copyfile(full_filepath, os.path.join(path, thumb_path))
if not config.getInstance().jellyfin():
shutil.copyfile(full_filepath, os.path.join(path, fanart_path))
def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, filepath, tag, actor_list, liuchu,
@@ -332,13 +333,23 @@ def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, f
pass
# KODI内查看影片信息时找不到number配置naming_rule=number+'#'+title虽可解决
# 但使得标题太长放入时常为空的outline内会更适合软件给outline留出的显示版面也较大
outline = f"{number}#{outline}"
if not outline:
pass
elif json_data['source'] == 'pissplay':
outline = f"{outline}"
else:
outline = f"{number}#{outline}"
with open(nfo_path, "wt", encoding='UTF-8') as code:
print('<?xml version="1.0" encoding="UTF-8" ?>', file=code)
print("<movie>", file=code)
print(" <title><![CDATA[" + naming_rule + "]]></title>", file=code)
print(" <originaltitle><![CDATA[" + naming_rule + "]]></originaltitle>", file=code)
print(" <sorttitle><![CDATA[" + naming_rule + "]]></sorttitle>", file=code)
if not config.getInstance().jellyfin():
print(" <title><![CDATA[" + naming_rule + "]]></title>", file=code)
print(" <originaltitle><![CDATA[" + naming_rule + "]]></originaltitle>", file=code)
print(" <sorttitle><![CDATA[" + naming_rule + "]]></sorttitle>", file=code)
else:
print(" <title>" + naming_rule + "</title>", file=code)
print(" <originaltitle>" + naming_rule + "</originaltitle>", file=code)
print(" <sorttitle>" + naming_rule + "</sorttitle>", file=code)
print(" <customrating>JP-18+</customrating>", file=code)
print(" <mpaa>JP-18+</mpaa>", file=code)
try:
@@ -347,13 +358,18 @@ def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, f
print(" <set></set>", file=code)
print(" <studio>" + studio + "</studio>", file=code)
print(" <year>" + year + "</year>", file=code)
print(" <outline><![CDATA[" + outline + "]]></outline>", file=code)
print(" <plot><![CDATA[" + outline + "]]></plot>", file=code)
if not config.getInstance().jellyfin():
print(" <outline><![CDATA[" + outline + "]]></outline>", file=code)
print(" <plot><![CDATA[" + outline + "]]></plot>", file=code)
else:
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>" + poster_path + "</poster>", file=code)
print(" <thumb>" + thumb_path + "</thumb>", file=code)
print(" <fanart>" + fanart_path + "</fanart>", file=code)
if not config.getInstance().jellyfin(): # jellyfin 不需要保存fanart
print(" <fanart>" + fanart_path + "</fanart>", file=code)
try:
for key in actor_list:
print(" <actor>", file=code)
@@ -368,8 +384,8 @@ def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, f
print(" <maker>" + studio + "</maker>", file=code)
print(" <label>" + label + "</label>", file=code)
skip_tags = config.getInstance().donot_save_tags()
if not skip_tags:
jellyfin = config.getInstance().jellyfin()
if not jellyfin:
if config.getInstance().actor_only_tag():
for key in actor_list:
try:
@@ -920,7 +936,7 @@ def core_main(movie_path, number_th, oCC, specified_source=None, specified_url=N
pass
# 裁剪图
cutImage(imagecut, path, fanart_path, poster_path, bool(conf.face_uncensored_only() and not uncensored))
cutImage(imagecut, path, thumb_path, poster_path, bool(conf.face_uncensored_only() and not uncensored))
# 兼容Jellyfin封面图文件名规则
if multi_part and conf.jellyfin_multi_part_fanart():
@@ -998,7 +1014,7 @@ def core_main(movie_path, number_th, oCC, specified_source=None, specified_url=N
# 添加水印
if conf.is_watermark():
add_mark(os.path.join(path, poster_path), os.path.join(path, thumb_path), cn_sub, leak, uncensored, hack,
add_mark(os.path.join(path, poster_path), os.path.join(path, fanart_path), cn_sub, leak, uncensored, hack,
_4k)
# 兼容Jellyfin封面图文件名规则
@@ -1008,4 +1024,4 @@ def core_main(movie_path, number_th, oCC, specified_source=None, specified_url=N
# 最后输出.nfo元数据文件以完成.nfo文件创建作为任务成功标志
print_files(path, leak_word, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, movie_path,
tag, json_data.get('actor_list'), liuchu, uncensored, hack_word, fanart_path, poster_path,
thumb_path)
_4k, thumb_path)