Skip to content

Commit

Permalink
fix 动漫分类
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed May 24, 2024
1 parent 355dad9 commit 0428002
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 49 deletions.
2 changes: 1 addition & 1 deletion app/chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
15 changes: 6 additions & 9 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,7 @@ def __init__(self):
self.mediachain = MediaChain()
self.tmdbchain = TmdbChain()
self.systemconfig = SystemConfigOper()
self.directoryhelper = DirectoryHelper()

def process(self) -> bool:
"""
Expand Down Expand Up @@ -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: 文件路径
Expand Down Expand Up @@ -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):
# 父目录非根目录,才删除父目录
Expand Down
10 changes: 2 additions & 8 deletions app/helper/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions app/modules/themoviedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
15 changes: 0 additions & 15 deletions app/modules/themoviedb/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
判断电影的分类
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/modules/themoviedb/tmdbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def get_info(self,
tmdbid: int) -> dict:
"""
给定TMDB号,查询一条媒体信息
:param mtype: 类型:电影、电视剧、动漫,为空时都查(此时用不上年份)
:param mtype: 类型:电影、电视剧,为空时都查(此时用不上年份)
:param tmdbid: TMDB的ID,有tmdbid时优先使用tmdbid,否则使用年份和标题
"""

Expand Down
19 changes: 8 additions & 11 deletions config/category.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down

1 comment on commit 0428002

@faithleysath
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这么重大的变更,app.env没做向后兼容啊,更新后我动漫刮削直接失效了,还得重新配置。

Please sign in to comment.