diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index fff975a0..4cd28956 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -85,15 +85,18 @@ def delete_transfer_history(history_in: schemas.TransferHistory, @router.post("/transfer", summary="历史记录重新转移", response_model=schemas.Response) def redo_transfer_history(history_in: schemas.TransferHistory, - mtype: str, - new_tmdbid: int, + mtype: str = None, + new_tmdbid: int = None, db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ - 历史记录重新转移 + 历史记录重新转移,不输入 mtype 和 new_tmdbid 时,自动使用文件名重新识别 """ - state, errmsg = TransferChain(db).re_transfer(logid=history_in.id, - mtype=MediaType(mtype), tmdbid=new_tmdbid) + if mtype and new_tmdbid: + state, errmsg = TransferChain(db).re_transfer(logid=history_in.id, + mtype=MediaType(mtype), tmdbid=new_tmdbid) + else: + state, errmsg = TransferChain(db).re_transfer(logid=history_in.id) if state: return schemas.Response(success=True) else: diff --git a/app/chain/media.py b/app/chain/media.py index 243b7071..e797525f 100644 --- a/app/chain/media.py +++ b/app/chain/media.py @@ -4,7 +4,7 @@ from typing import Optional, List, Tuple from app.chain import ChainBase from app.core.context import Context, MediaInfo from app.core.meta import MetaBase -from app.core.metainfo import MetaInfo +from app.core.metainfo import MetaInfo, MetaInfoPath from app.log import logger from app.utils.string import StringUtils @@ -38,12 +38,8 @@ class MediaChain(ChainBase): """ logger.info(f'开始识别媒体信息,文件:{path} ...') file_path = Path(path) - # 上级目录元数据 - dir_meta = MetaInfo(title=file_path.parent.name) - # 文件元数据,不包含后缀 - file_meta = MetaInfo(title=file_path.stem) - # 合并元数据 - file_meta.merge(dir_meta) + # 元数据 + file_meta = MetaInfoPath(file_path) # 识别媒体信息 mediainfo = self.recognize_media(meta=file_meta) if not mediainfo: diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 5741ea8a..124e966b 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -12,7 +12,7 @@ from app.chain.media import MediaChain from app.core.config import settings from app.core.context import MediaInfo from app.core.meta import MetaBase -from app.core.metainfo import MetaInfo +from app.core.metainfo import MetaInfoPath from app.db.downloadhistory_oper import DownloadHistoryOper from app.db.models.downloadhistory import DownloadHistory from app.db.models.transferhistory import TransferHistory @@ -202,12 +202,8 @@ class TransferChain(ChainBase): key=ProgressKey.FileTransfer) if not meta: - # 上级目录元数据 - dir_meta = MetaInfo(title=file_path.parent.name) - # 文件元数据,不包含后缀 - file_meta = MetaInfo(title=file_path.stem) - # 合并元数据 - file_meta.merge(dir_meta) + # 文件元数据 + file_meta = MetaInfoPath(file_path) else: file_meta = meta @@ -474,7 +470,8 @@ class TransferChain(ChainBase): text=errmsg, userid=userid)) return - def re_transfer(self, logid: int, mtype: MediaType, tmdbid: int) -> Tuple[bool, str]: + def re_transfer(self, logid: int, + mtype: MediaType = None, tmdbid: int = None) -> Tuple[bool, str]: """ 根据历史记录,重新识别转移,只处理对应的src目录 :param logid: 历史记录ID @@ -492,11 +489,15 @@ class TransferChain(ChainBase): return False, f"源目录不存在:{src_path}" dest_path = Path(history.dest) if history.dest else None # 查询媒体信息 - mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid) + if mtype and tmdbid: + mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid) + else: + meta = MetaInfoPath(src_path) + mediainfo = self.recognize_media(meta=meta) if not mediainfo: return False, f"未识别到媒体信息,类型:{mtype.value},tmdbid:{tmdbid}" # 重新执行转移 - logger.info(f"{mtype.value} {tmdbid} 识别为:{mediainfo.title_year}") + logger.info(f"{src_path.name} 识别为:{mediainfo.title_year}") # 更新媒体图片 self.obtain_images(mediainfo=mediainfo) diff --git a/app/core/metainfo.py b/app/core/metainfo.py index 6a583b92..2ae668f5 100644 --- a/app/core/metainfo.py +++ b/app/core/metainfo.py @@ -9,7 +9,7 @@ from app.core.meta.words import WordsMatcher def MetaInfo(title: str, subtitle: str = None) -> MetaBase: """ - 媒体整理入口,根据名称和副标题,判断是哪种类型的识别,返回对应对象 + 根据标题和副标题识别元数据 :param title: 标题、种子名、文件名 :param subtitle: 副标题、描述 :return: MetaAnime、MetaVideo @@ -33,6 +33,20 @@ def MetaInfo(title: str, subtitle: str = None) -> MetaBase: return meta +def MetaInfoPath(path: Path) -> MetaBase: + """ + 根据路径识别元数据 + :param path: 路径 + """ + # 上级目录元数据 + dir_meta = MetaInfo(title=path.parent.name) + # 文件元数据,不包含后缀 + file_meta = MetaInfo(title=path.stem) + # 合并元数据 + file_meta.merge(dir_meta) + return file_meta + + def is_anime(name: str) -> bool: """ 判断是否为动漫 diff --git a/app/plugins/brushflow/__init__.py b/app/plugins/brushflow/__init__.py index 7fbd174f..63a380c4 100644 --- a/app/plugins/brushflow/__init__.py +++ b/app/plugins/brushflow/__init__.py @@ -43,7 +43,7 @@ class BrushFlow(_PluginBase): # 加载顺序 plugin_order = 21 # 可使用的用户级别 - auth_level = 3 + auth_level = 2 # 私有属性 siteshelper = None diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index ce6e4a89..0264b8fb 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -15,7 +15,7 @@ from watchdog.observers.polling import PollingObserver from app.chain.transfer import TransferChain from app.core.config import settings from app.core.context import MediaInfo -from app.core.metainfo import MetaInfo +from app.core.metainfo import MetaInfoPath from app.db.downloadhistory_oper import DownloadHistoryOper from app.db.transferhistory_oper import TransferHistoryOper from app.log import logger @@ -237,13 +237,8 @@ class DirMonitor(_PluginBase): logger.info(f"{event_path} 已整理过") return - # 上级目录元数据 - meta = MetaInfo(title=file_path.parent.name) - # 文件元数据,不包含后缀 - file_meta = MetaInfo(title=file_path.stem) - # 合并元数据 - file_meta.merge(meta) - + # 元数据 + file_meta = MetaInfoPath(file_path) if not file_meta.name: logger.error(f"{file_path.name} 无法识别有效信息") return @@ -343,7 +338,7 @@ class DirMonitor(_PluginBase): } """ # 发送消息汇总 - media_list = self._medias.get(mediainfo.title_year + " " + meta.season) or {} + media_list = self._medias.get(mediainfo.title_year + " " + file_meta.season) or {} if media_list: media_files = media_list.get("files") or [] if media_files: @@ -384,7 +379,7 @@ class DirMonitor(_PluginBase): ], "time": datetime.now() } - self._medias[mediainfo.title_year + " " + meta.season] = media_list + self._medias[mediainfo.title_year + " " + file_meta.season] = media_list # 汇总刷新媒体库 if settings.REFRESH_MEDIASERVER: