Merge pull request #1882 from WangEdward/main
fix: metainfo for manual transfer
This commit is contained in:
commit
8cd0dd4198
@ -14,6 +14,7 @@ from app.core.context import Context
|
|||||||
from app.core.context import MediaInfo, TorrentInfo
|
from app.core.context import MediaInfo, TorrentInfo
|
||||||
from app.core.event import EventManager
|
from app.core.event import EventManager
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
from app.core.module import ModuleManager
|
from app.core.module import ModuleManager
|
||||||
from app.db.message_oper import MessageOper
|
from app.db.message_oper import MessageOper
|
||||||
from app.helper.message import MessageHelper
|
from app.helper.message import MessageHelper
|
||||||
@ -477,7 +478,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
return self.run_module("post_torrents_message", message=message, torrents=torrents)
|
return self.run_module("post_torrents_message", message=message, torrents=torrents)
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
force_nfo: bool = False, force_img: bool = False) -> None:
|
metainfo: MetaInfo = None, force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
@ -488,7 +489,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
:return: 成功或失败
|
:return: 成功或失败
|
||||||
"""
|
"""
|
||||||
self.run_module("scrape_metadata", path=path, mediainfo=mediainfo,
|
self.run_module("scrape_metadata", path=path, mediainfo=mediainfo,
|
||||||
transfer_type=transfer_type, force_nfo=force_nfo, force_img=force_img)
|
metainfo=metainfo, transfer_type=transfer_type, force_nfo=force_nfo, force_img=force_img)
|
||||||
|
|
||||||
def register_commands(self, commands: Dict[str, dict]) -> None:
|
def register_commands(self, commands: Dict[str, dict]) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -223,6 +223,8 @@ class TransferChain(ChainBase):
|
|||||||
# 合并季
|
# 合并季
|
||||||
if season is not None:
|
if season is not None:
|
||||||
file_meta.begin_season = season
|
file_meta.begin_season = season
|
||||||
|
elif file_meta.begin_season is None:
|
||||||
|
file_meta.begin_season = 1
|
||||||
|
|
||||||
if not file_meta:
|
if not file_meta:
|
||||||
logger.error(f"{file_path} 无法识别有效信息")
|
logger.error(f"{file_path} 无法识别有效信息")
|
||||||
@ -278,9 +280,10 @@ class TransferChain(ChainBase):
|
|||||||
|
|
||||||
# 获取集数据
|
# 获取集数据
|
||||||
if file_mediainfo.type == MediaType.TV:
|
if file_mediainfo.type == MediaType.TV:
|
||||||
|
file_mediainfo.season = file_mediainfo.season or file_meta.begin_season
|
||||||
episodes_info = self.tmdbchain.tmdb_episodes(
|
episodes_info = self.tmdbchain.tmdb_episodes(
|
||||||
tmdbid=file_mediainfo.tmdb_id,
|
tmdbid=file_mediainfo.tmdb_id,
|
||||||
season=1 if file_meta.begin_season is None else file_meta.begin_season
|
season=file_mediainfo.season
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
episodes_info = None
|
episodes_info = None
|
||||||
@ -357,7 +360,8 @@ class TransferChain(ChainBase):
|
|||||||
if settings.SCRAP_METADATA:
|
if settings.SCRAP_METADATA:
|
||||||
self.scrape_metadata(path=transferinfo.target_path,
|
self.scrape_metadata(path=transferinfo.target_path,
|
||||||
mediainfo=file_mediainfo,
|
mediainfo=file_mediainfo,
|
||||||
transfer_type=transfer_type)
|
transfer_type=transfer_type,
|
||||||
|
metainfo=file_meta)
|
||||||
# 更新进度
|
# 更新进度
|
||||||
processed_num += 1
|
processed_num += 1
|
||||||
self.progress.update(value=processed_num / total_num * 100,
|
self.progress.update(value=processed_num / total_num * 100,
|
||||||
|
@ -629,7 +629,7 @@ class DoubanModule(_ModuleBase):
|
|||||||
return infos.get("subject_collection_items")
|
return infos.get("subject_collection_items")
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
force_nfo: bool = False, force_img: bool = False) -> None:
|
metainfo: MetaInfo = None, force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
|
@ -7,6 +7,7 @@ from app import schemas
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo
|
from app.core.context import MediaInfo
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.modules import _ModuleBase
|
from app.modules import _ModuleBase
|
||||||
from app.modules.themoviedb.category import CategoryHelper
|
from app.modules.themoviedb.category import CategoryHelper
|
||||||
@ -262,7 +263,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||||
force_nfo: bool = False, force_img: bool = False) -> None:
|
metainfo: MetaInfo = None, force_nfo: bool = False, force_img: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
刮削元数据
|
刮削元数据
|
||||||
:param path: 媒体文件路径
|
:param path: 媒体文件路径
|
||||||
@ -282,6 +283,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=scrape_path,
|
file_path=scrape_path,
|
||||||
transfer_type=transfer_type,
|
transfer_type=transfer_type,
|
||||||
|
metainfo=metainfo,
|
||||||
force_nfo=force_nfo,
|
force_nfo=force_nfo,
|
||||||
force_img=force_img)
|
force_img=force_img)
|
||||||
elif path.is_file():
|
elif path.is_file():
|
||||||
@ -290,6 +292,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=path,
|
file_path=path,
|
||||||
transfer_type=transfer_type,
|
transfer_type=transfer_type,
|
||||||
|
metainfo=metainfo,
|
||||||
force_nfo=force_nfo,
|
force_nfo=force_nfo,
|
||||||
force_img=force_img)
|
force_img=force_img)
|
||||||
else:
|
else:
|
||||||
@ -301,6 +304,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
self.scraper.gen_scraper_files(mediainfo=mediainfo,
|
||||||
file_path=file,
|
file_path=file,
|
||||||
transfer_type=transfer_type,
|
transfer_type=transfer_type,
|
||||||
|
metainfo=metainfo,
|
||||||
force_nfo=force_nfo,
|
force_nfo=force_nfo,
|
||||||
force_img=force_img)
|
force_img=force_img)
|
||||||
logger.info(f"{path} 刮削完成")
|
logger.info(f"{path} 刮削完成")
|
||||||
|
@ -26,7 +26,7 @@ class TmdbScraper:
|
|||||||
self.tmdb = tmdb
|
self.tmdb = tmdb
|
||||||
|
|
||||||
def gen_scraper_files(self, mediainfo: MediaInfo, file_path: Path, transfer_type: str,
|
def gen_scraper_files(self, mediainfo: MediaInfo, file_path: Path, transfer_type: str,
|
||||||
force_nfo: bool = False, force_img: bool = False):
|
metainfo: MetaInfo = None, force_nfo: bool = False, force_img: bool = False):
|
||||||
"""
|
"""
|
||||||
生成刮削文件,包括NFO和图片,传入路径为文件路径
|
生成刮削文件,包括NFO和图片,传入路径为文件路径
|
||||||
:param mediainfo: 媒体信息
|
:param mediainfo: 媒体信息
|
||||||
@ -75,8 +75,8 @@ class TmdbScraper:
|
|||||||
file_path=image_path)
|
file_path=image_path)
|
||||||
# 电视剧,路径为每一季的文件名 名称/Season xx/名称 SxxExx.xxx
|
# 电视剧,路径为每一季的文件名 名称/Season xx/名称 SxxExx.xxx
|
||||||
else:
|
else:
|
||||||
# 识别
|
# 如果有上游传入的元信息则使用,否则使用文件名识别
|
||||||
meta = MetaInfo(file_path.stem)
|
meta = metainfo or MetaInfo(file_path.stem)
|
||||||
# 根目录不存在时才处理
|
# 根目录不存在时才处理
|
||||||
if self._force_nfo or not file_path.parent.with_name("tvshow.nfo").exists():
|
if self._force_nfo or not file_path.parent.with_name("tvshow.nfo").exists():
|
||||||
# 根目录描述文件
|
# 根目录描述文件
|
||||||
@ -96,7 +96,7 @@ class TmdbScraper:
|
|||||||
self.__save_image(url=attr_value,
|
self.__save_image(url=attr_value,
|
||||||
file_path=image_path)
|
file_path=image_path)
|
||||||
# 查询季信息
|
# 查询季信息
|
||||||
seasoninfo = self.tmdb.get_tv_season_detail(mediainfo.tmdb_id, meta.begin_season)
|
seasoninfo = self.tmdb.get_tv_season_detail(mediainfo.tmdb_id, meta.begin_season or mediainfo.season)
|
||||||
if seasoninfo:
|
if seasoninfo:
|
||||||
# 季目录NFO
|
# 季目录NFO
|
||||||
if self._force_nfo or not file_path.with_name("season.nfo").exists():
|
if self._force_nfo or not file_path.with_name("season.nfo").exists():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user