From 752e2926a737c9ab8a3de42043afdc1c5c1eff5d Mon Sep 17 00:00:00 2001 From: musnow <775130834@qq.com> Date: Sat, 30 Dec 2023 15:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=AB=E5=90=8D=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE#167?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actors/items.json | 28 ++++++++++++++++++++++++++++ core/config.ini | 2 ++ core/nfo.py | 25 +++++++++++++++++++++---- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 actors/items.json diff --git a/actors/items.json b/actors/items.json new file mode 100644 index 000000000..c2891a792 --- /dev/null +++ b/actors/items.json @@ -0,0 +1,28 @@ +[ + { + "name": "横宮七海", + "alias": [ + "横宮七海", + "横山七海", + "積木舞美", + "真島奈央", + "白石もえ" + ] + }, + { + "name": "上原亚衣", + "alias": [ + "上原亚衣", + "上原亜衣", + "吉原麻衣" + ] + }, + { + "name": "波多野結衣", + "alias": [ + "波多野結衣", + "酒井愛美", + "水谷結衣" + ] + } +] \ No newline at end of file diff --git a/core/config.ini b/core/config.ini index 90b685a1d..0b98d5b98 100644 --- a/core/config.ini +++ b/core/config.ini @@ -121,6 +121,8 @@ bing_key = [NFO] # 同时将genre写入到tag? add_genre_to_tag = yes +# 是否开启别名替换 +is_replace_actor_alias = no [Other] # 是否允许检查更新。如果允许,在有新版本时会显示提示信息和新版功能 diff --git a/core/nfo.py b/core/nfo.py index 1e1763fce..640bd3275 100644 --- a/core/nfo.py +++ b/core/nfo.py @@ -1,6 +1,8 @@ """与操作nfo文件相关的功能""" import os import sys +import json +import logging from lxml.etree import tostring from lxml.builder import E @@ -9,6 +11,19 @@ from core.datatype import MovieInfo from core.config import cfg +logger = logging.getLogger(__name__) + +def setActor(name): + # 引入文件还需要处理一下 + actorsFile = f"{os.path.join(os.path.dirname(__file__), '..')}/actors/items.json" + with open(actorsFile, "r", encoding="utf-8") as file: + actress = json.load(file) + for actor in actress: + if name in actor['alias']: + logger.debug(f"按照alias设置,将演员名[{name}]替换为[{actor['name']}]") + return actor['name'] + + return name def write_nfo(info: MovieInfo, nfo_file): """将存储了影片信息的'info'写入到nfo文件中""" @@ -90,11 +105,13 @@ def write_nfo(info: MovieInfo, nfo_file): # 写入演员名。Kodi支持用thumb显示演员头像,如果能获取到演员头像也一并写入 if info.actress: - for i in info.actress: - if (info.actress_pics) and (i in info.actress_pics): - nfo.append(E.actor(E.name(i), E.thumb(info.actress_pics[i]))) + for name in info.actress: + if (cfg.NFO.is_replace_actor_alias): + name = setActor(name) + if (info.actress_pics) and (name in info.actress_pics): + nfo.append(E.actor(E.name(name), E.thumb(info.actress_pics[name]))) else: - nfo.append(E.actor(E.name(i))) + nfo.append(E.actor(E.name(name))) with open(nfo_file, 'wt', encoding='utf-8') as f: f.write(tostring(nfo, encoding='unicode', pretty_print=True,