Skip to content

Commit

Permalink
Merge pull request mvdctop#946 from mark5231/add_jellyfin
Browse files Browse the repository at this point in the history
添加jellyfin中特有的一些设定
  • Loading branch information
mvdctop authored Jan 10, 2023
2 parents 91371e8 + eaed709 commit 68a9cc3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ImageProcessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 4 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def download_only_missing_images(self) -> bool:
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")
Expand Down Expand Up @@ -443,7 +443,7 @@ def _default_config() -> configparser.ConfigParser:
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)
Expand Down
52 changes: 34 additions & 18 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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封面图文件名规则
Expand All @@ -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)

0 comments on commit 68a9cc3

Please sign in to comment.