Skip to content

Commit

Permalink
新增别名设置#167
Browse files Browse the repository at this point in the history
  • Loading branch information
musnow committed Dec 30, 2023
1 parent 78f4261 commit 752e292
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
28 changes: 28 additions & 0 deletions actors/items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "横宮七海",
"alias": [
"横宮七海",
"横山七海",
"積木舞美",
"真島奈央",
"白石もえ"
]
},
{
"name": "上原亚衣",
"alias": [
"上原亚衣",
"上原亜衣",
"吉原麻衣"
]
},
{
"name": "波多野結衣",
"alias": [
"波多野結衣",
"酒井愛美",
"水谷結衣"
]
}
]
2 changes: 2 additions & 0 deletions core/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ bing_key =
[NFO]
# 同时将genre写入到tag?
add_genre_to_tag = yes
# 是否开启别名替换
is_replace_actor_alias = no

[Other]
# 是否允许检查更新。如果允许,在有新版本时会显示提示信息和新版功能
Expand Down
25 changes: 21 additions & 4 deletions core/nfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""与操作nfo文件相关的功能"""
import os
import sys
import json
import logging
from lxml.etree import tostring
from lxml.builder import E

Expand All @@ -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文件中"""
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 752e292

Please sign in to comment.