add meta_nfo module function
This commit is contained in:
@ -315,3 +315,14 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
||||
season=meta.begin_season
|
||||
)
|
||||
return None
|
||||
|
||||
def meta_nfo(self, meta: MetaBase, mediainfo: MediaInfo,
|
||||
season: int = None, episode: int = None) -> Optional[str]:
|
||||
"""
|
||||
获取NFO文件内容文本
|
||||
:param meta: 元数据
|
||||
:param mediainfo: 媒体信息
|
||||
:param season: 季号
|
||||
:param episode: 集号
|
||||
"""
|
||||
return self.run_module("meta_nfo", meta=meta, mediainfo=mediainfo, season=season, episode=episode)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
from typing import Union, Optional
|
||||
from xml.dom import minidom
|
||||
|
||||
from requests import RequestException
|
||||
@ -26,6 +26,48 @@ class TmdbScraper:
|
||||
def __init__(self, tmdb):
|
||||
self.tmdb = tmdb
|
||||
|
||||
def meta_nfo(self, meta: MetaBase, mediainfo: MediaInfo,
|
||||
season: int = None, episode: int = None) -> Optional[str]:
|
||||
"""
|
||||
获取NFO文件内容文本
|
||||
:param meta: 元数据
|
||||
:param mediainfo: 媒体信息
|
||||
:param season: 季号
|
||||
:param episode: 集号
|
||||
"""
|
||||
if mediainfo.type == MediaType.MOVIE:
|
||||
# 电影元数据文件
|
||||
doc = self.__gen_movie_nfo_file(mediainfo=mediainfo)
|
||||
else:
|
||||
if season:
|
||||
# 查询季信息
|
||||
seasoninfo = self.tmdb.get_tv_season_detail(mediainfo.tmdb_id, meta.begin_season)
|
||||
if episode:
|
||||
# 集元数据文件
|
||||
episodeinfo = self.__get_episode_detail(seasoninfo, meta.begin_episode)
|
||||
doc = self.__gen_tv_episode_nfo_file(episodeinfo=episodeinfo, tmdbid=mediainfo.tmdb_id,
|
||||
season=season, episode=episode)
|
||||
else:
|
||||
# 季元数据文件
|
||||
doc = self.__gen_tv_season_nfo_file(seasoninfo=seasoninfo, season=season)
|
||||
else:
|
||||
# 电视剧元数据文件
|
||||
doc = self.__gen_tv_nfo_file(mediainfo=mediainfo)
|
||||
if doc:
|
||||
return doc.toprettyxml(indent=" ", encoding="utf-8")
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def __get_episode_detail(seasoninfo: dict, episode: int) -> dict:
|
||||
"""
|
||||
根据季信息获取集的信息
|
||||
"""
|
||||
for _episode_info in seasoninfo.get("episodes") or []:
|
||||
if _episode_info.get("episode_number") == episode:
|
||||
return _episode_info
|
||||
return {}
|
||||
|
||||
def gen_scraper_files(self, mediainfo: MediaInfo, file_path: Path, transfer_type: str,
|
||||
metainfo: MetaBase = None, force_nfo: bool = False, force_img: bool = False):
|
||||
"""
|
||||
@ -45,15 +87,6 @@ class TmdbScraper:
|
||||
self._force_nfo = force_nfo
|
||||
self._force_img = force_img
|
||||
|
||||
def __get_episode_detail(_seasoninfo: dict, _episode: int):
|
||||
"""
|
||||
根据季信息获取集的信息
|
||||
"""
|
||||
for _episode_info in _seasoninfo.get("episodes") or []:
|
||||
if _episode_info.get("episode_number") == _episode:
|
||||
return _episode_info
|
||||
return {}
|
||||
|
||||
try:
|
||||
# 电影,路径为文件名 名称/名称.xxx 或者蓝光原盘目录 名称/名称
|
||||
if mediainfo.type == MediaType.MOVIE:
|
||||
@ -131,7 +164,7 @@ class TmdbScraper:
|
||||
self.__save_image(url=attr_value,
|
||||
file_path=image_path)
|
||||
# 查询集详情
|
||||
episodeinfo = __get_episode_detail(seasoninfo, meta.begin_episode)
|
||||
episodeinfo = self.__get_episode_detail(seasoninfo, meta.begin_episode)
|
||||
if episodeinfo:
|
||||
# 集NFO
|
||||
if self._force_nfo or not file_path.with_suffix(".nfo").exists():
|
||||
@ -153,7 +186,7 @@ class TmdbScraper:
|
||||
logger.error(f"{file_path} 刮削失败:{str(e)} - {traceback.format_exc()}")
|
||||
|
||||
@staticmethod
|
||||
def __gen_common_nfo(mediainfo: MediaInfo, doc, root):
|
||||
def __gen_common_nfo(mediainfo: MediaInfo, doc: minidom.Document, root: minidom.Element):
|
||||
"""
|
||||
生成公共NFO
|
||||
"""
|
||||
@ -207,7 +240,7 @@ class TmdbScraper:
|
||||
|
||||
def __gen_movie_nfo_file(self,
|
||||
mediainfo: MediaInfo,
|
||||
file_path: Path):
|
||||
file_path: Path = None) -> minidom.Document:
|
||||
"""
|
||||
生成电影的NFO描述文件
|
||||
:param mediainfo: 识别后的媒体信息
|
||||
@ -229,11 +262,13 @@ class TmdbScraper:
|
||||
# 年份
|
||||
DomUtils.add_node(doc, root, "year", mediainfo.year or "")
|
||||
# 保存
|
||||
self.__save_nfo(doc, file_path.with_suffix(".nfo"))
|
||||
if file_path:
|
||||
self.__save_nfo(doc, file_path.with_suffix(".nfo"))
|
||||
return doc
|
||||
|
||||
def __gen_tv_nfo_file(self,
|
||||
mediainfo: MediaInfo,
|
||||
dir_path: Path):
|
||||
dir_path: Path = None) -> minidom.Document:
|
||||
"""
|
||||
生成电视剧的NFO描述文件
|
||||
:param mediainfo: 媒体信息
|
||||
@ -257,9 +292,13 @@ class TmdbScraper:
|
||||
DomUtils.add_node(doc, root, "season", "-1")
|
||||
DomUtils.add_node(doc, root, "episode", "-1")
|
||||
# 保存
|
||||
self.__save_nfo(doc, dir_path.joinpath("tvshow.nfo"))
|
||||
if dir_path:
|
||||
self.__save_nfo(doc, dir_path.joinpath("tvshow.nfo"))
|
||||
|
||||
def __gen_tv_season_nfo_file(self, seasoninfo: dict, season: int, season_path: Path):
|
||||
return doc
|
||||
|
||||
def __gen_tv_season_nfo_file(self, seasoninfo: dict,
|
||||
season: int, season_path: Path = None) -> minidom.Document:
|
||||
"""
|
||||
生成电视剧季的NFO描述文件
|
||||
:param seasoninfo: TMDB季媒体信息
|
||||
@ -285,14 +324,16 @@ class TmdbScraper:
|
||||
# seasonnumber
|
||||
DomUtils.add_node(doc, root, "seasonnumber", str(season))
|
||||
# 保存
|
||||
self.__save_nfo(doc, season_path.joinpath("season.nfo"))
|
||||
if season_path:
|
||||
self.__save_nfo(doc, season_path.joinpath("season.nfo"))
|
||||
return doc
|
||||
|
||||
def __gen_tv_episode_nfo_file(self,
|
||||
tmdbid: int,
|
||||
episodeinfo: dict,
|
||||
season: int,
|
||||
episode: int,
|
||||
file_path: Path):
|
||||
file_path: Path = None) -> minidom.Document:
|
||||
"""
|
||||
生成电视剧集的NFO描述文件
|
||||
:param tmdbid: TMDBID
|
||||
@ -348,7 +389,9 @@ class TmdbScraper:
|
||||
DomUtils.add_node(doc, xactor, "profile",
|
||||
f"https://www.themoviedb.org/person/{actor.get('id')}")
|
||||
# 保存文件
|
||||
self.__save_nfo(doc, file_path.with_suffix(".nfo"))
|
||||
if file_path:
|
||||
self.__save_nfo(doc, file_path.with_suffix(".nfo"))
|
||||
return doc
|
||||
|
||||
@retry(RequestException, logger=logger)
|
||||
def __save_image(self, url: str, file_path: Path):
|
||||
@ -371,7 +414,7 @@ class TmdbScraper:
|
||||
except Exception as err:
|
||||
logger.error(f"{file_path.stem}图片下载失败:{str(err)}")
|
||||
|
||||
def __save_nfo(self, doc, file_path: Path):
|
||||
def __save_nfo(self, doc: minidom.Document, file_path: Path):
|
||||
"""
|
||||
保存NFO
|
||||
"""
|
||||
|
Reference in New Issue
Block a user