diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 677cce588..6b07e91c6 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -512,7 +512,7 @@ def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str, def media_category(self) -> Optional[Dict[str, list]]: """ 获取媒体分类 - :return: 获取二级分类配置字典项,需包括电影、电视剧、动漫 + :return: 获取二级分类配置字典项,需包括电影、电视剧 """ return self.run_module("media_category") diff --git a/app/chain/transfer.py b/app/chain/transfer.py index e20459b32..f481b1c8f 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -16,6 +16,7 @@ from app.db.models.transferhistory import TransferHistory from app.db.systemconfig_oper import SystemConfigOper from app.db.transferhistory_oper import TransferHistoryOper +from app.helper.directory import DirectoryHelper from app.helper.format import FormatParser from app.helper.progress import ProgressHelper from app.log import logger @@ -41,6 +42,7 @@ def __init__(self): self.mediachain = MediaChain() self.tmdbchain = TmdbChain() self.systemconfig = SystemConfigOper() + self.directoryhelper = DirectoryHelper() def process(self) -> bool: """ @@ -625,8 +627,7 @@ def send_transfer_message(self, meta: MetaBase, mediainfo: MediaInfo, mtype=NotificationType.Organize, title=msg_title, text=msg_str, image=mediainfo.get_message_image())) - @staticmethod - def delete_files(path: Path) -> Tuple[bool, str]: + def delete_files(self, path: Path) -> Tuple[bool, str]: """ 删除转移后的文件以及空目录 :param path: 文件路径 @@ -657,16 +658,12 @@ def delete_files(path: Path) -> Tuple[bool, str]: # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 if not SystemUtils.exits_files(path.parent, settings.RMT_MEDIAEXT): # 媒体库二级分类根路径 - library_root_names = [ - settings.LIBRARY_MOVIE_NAME or '电影', - settings.LIBRARY_TV_NAME or '电视剧', - settings.LIBRARY_ANIME_NAME or '动漫', - ] - + library_roots = self.directoryhelper.get_library_dirs() + library_root_names = [Path(library_root.path).name for library_root in library_roots if library_root.path] # 判断父目录是否为空, 为空则删除 for parent_path in path.parents: # 遍历父目录到媒体库二级分类根路径 - if str(parent_path.name) in library_root_names: + if parent_path.name in library_root_names: break if str(parent_path.parent) != str(path.root): # 父目录非根目录,才删除父目录 diff --git a/app/helper/directory.py b/app/helper/directory.py index e68bd68d7..a90c1641c 100644 --- a/app/helper/directory.py +++ b/app/helper/directory.py @@ -41,10 +41,7 @@ def get_download_dir(self, media: MediaInfo = None) -> Optional[schemas.MediaDir :param media: 媒体信息 """ # 处理类型 - if media and media.genre_ids \ - and set(media.genre_ids).intersection(set(settings.ANIME_GENREIDS)): - media_type = "动漫" - elif media: + if media: media_type = media.type.value else: media_type = MediaType.UNKNOWN.value @@ -72,10 +69,7 @@ def get_library_dir(self, media: MediaInfo = None, in_path: Path = None) -> Opti :param in_path: 源目录 """ # 处理类型 - if media and media.genre_ids \ - and set(media.genre_ids).intersection(set(settings.ANIME_GENREIDS)): - media_type = "动漫" - elif media: + if media: media_type = media.type.value else: media_type = MediaType.UNKNOWN.value diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 61335cca4..9e9f48dd6 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -228,12 +228,11 @@ def tmdb_info(self, tmdbid: int, mtype: MediaType) -> Optional[dict]: def media_category(self) -> Optional[Dict[str, list]]: """ 获取媒体分类 - :return: 获取二级分类配置字典项,需包括电影、电视剧、动漫 + :return: 获取二级分类配置字典项,需包括电影、电视剧 """ return { - "电影": list(self.category.movie_categorys), - "电视剧": list(self.category.tv_categorys), - "动漫": list(self.category.anime_categorys) + MediaType.MOVIE.value: list(self.category.movie_categorys), + MediaType.TV.value: list(self.category.tv_categorys) } def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]: diff --git a/app/modules/themoviedb/category.py b/app/modules/themoviedb/category.py index ff3ff459d..012009162 100644 --- a/app/modules/themoviedb/category.py +++ b/app/modules/themoviedb/category.py @@ -15,7 +15,6 @@ class CategoryHelper(metaclass=Singleton): _categorys = {} _movie_categorys = {} _tv_categorys = {} - _anime_categorys = {} def __init__(self): self._category_path: Path = settings.CONFIG_PATH / "category.yaml" @@ -44,7 +43,6 @@ def init(self): if self._categorys: self._movie_categorys = self._categorys.get('movie') self._tv_categorys = self._categorys.get('tv') - self._anime_categorys = self._categorys.get('anime') logger.info(f"已加载二级分类策略 category.yaml") @property @@ -83,15 +81,6 @@ def tv_categorys(self) -> list: return [] return self._tv_categorys.keys() - @property - def anime_categorys(self) -> list: - """ - 获取动漫分类清单 - """ - if not self._anime_categorys: - return [] - return self._anime_categorys.keys() - def get_movie_category(self, tmdb_info) -> str: """ 判断电影的分类 @@ -106,10 +95,6 @@ def get_tv_category(self, tmdb_info) -> str: :param tmdb_info: 识别的TMDB中的信息 :return: 二级分类的名称 """ - genre_ids = tmdb_info.get("genre_ids") or [] - if self._anime_categorys and genre_ids \ - and set(genre_ids).intersection(set(settings.ANIME_GENREIDS)): - return self.get_category(self._anime_categorys, tmdb_info) return self.get_category(self._tv_categorys, tmdb_info) @staticmethod diff --git a/app/modules/themoviedb/tmdbapi.py b/app/modules/themoviedb/tmdbapi.py index 76230254b..01e630a58 100644 --- a/app/modules/themoviedb/tmdbapi.py +++ b/app/modules/themoviedb/tmdbapi.py @@ -530,7 +530,7 @@ def get_info(self, tmdbid: int) -> dict: """ 给定TMDB号,查询一条媒体信息 - :param mtype: 类型:电影、电视剧、动漫,为空时都查(此时用不上年份) + :param mtype: 类型:电影、电视剧,为空时都查(此时用不上年份) :param tmdbid: TMDB的ID,有tmdbid时优先使用tmdbid,否则使用年份和标题 """ diff --git a/config/category.yaml b/config/category.yaml index 51104c00d..7d24fae15 100644 --- a/config/category.yaml +++ b/config/category.yaml @@ -23,9 +23,16 @@ movie: # 配置电视剧的分类策略 tv: # 分类名同时也是目录名 - 动漫: + 国漫: + # 匹配 genre_ids 内容类型,16是动漫 + genre_ids: '16' + # 匹配 origin_country 国家,CN是中国大陆,TW是中国台湾,HK是中国香港 + origin_country: 'CN,TW,HK' + 日番: # 匹配 genre_ids 内容类型,16是动漫 genre_ids: '16' + # 匹配 origin_country 国家,JP是日本 + origin_country: 'JP' 纪录片: # 匹配 genre_ids 内容类型,99是纪录片 genre_ids: '99' @@ -47,16 +54,6 @@ tv: # 未匹配以上分类,则命名为未分类 未分类: -# 配置动漫的分类策略 -anime: - 国漫: - # 匹配 origin_country 国家,CN是中国大陆,TW是中国台湾,HK是中国香港 - origin_country: 'CN,TW,HK' - 日番: - # 匹配 origin_country 国家,JP是日本 - origin_country: 'JP' - 未分类: - ## genre_ids 内容类型 字典,注意部分中英文是不一样的 # 28 Action # 12 Adventure