mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
feat: 新增优先使用插件识别的功能
This commit is contained in:
@@ -5,6 +5,7 @@ from fastapi import APIRouter, Depends, Body
|
|||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.download import DownloadChain
|
from app.chain.download import DownloadChain
|
||||||
from app.chain.media import MediaChain
|
from app.chain.media import MediaChain
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo, Context, TorrentInfo
|
from app.core.context import MediaInfo, Context, TorrentInfo
|
||||||
from app.core.event import eventmanager
|
from app.core.event import eventmanager
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
@@ -77,13 +78,24 @@ def add(
|
|||||||
# 元数据
|
# 元数据
|
||||||
metainfo = MetaInfo(title=torrent_in.title, subtitle=torrent_in.description)
|
metainfo = MetaInfo(title=torrent_in.title, subtitle=torrent_in.description)
|
||||||
# 媒体信息
|
# 媒体信息
|
||||||
mediainfo = MediaChain().recognize_media(meta=metainfo, tmdbid=tmdbid, doubanid=doubanid)
|
mediainfo: MediaInfo = None
|
||||||
if not mediainfo:
|
if settings.RECOGNIZE_PLUGIN_FIRST and eventmanager.check(ChainEventType.NameRecognize):
|
||||||
# 尝试使用辅助识别,如果有注册响应事件的话
|
# 插件优先模式:优先使用辅助识别
|
||||||
if eventmanager.check(ChainEventType.NameRecognize):
|
mediainfo = MediaChain().recognize_help(title=torrent_in.title, org_meta=metainfo)
|
||||||
mediainfo = MediaChain().recognize_help(title=torrent_in.title, org_meta=metainfo)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
return schemas.Response(success=False, message="无法识别媒体信息")
|
# 尝试使用原生识别
|
||||||
|
mediainfo = MediaChain().recognize_media(meta=metainfo, tmdbid=tmdbid, doubanid=doubanid)
|
||||||
|
if not mediainfo:
|
||||||
|
return schemas.Response(success=False, message="无法识别媒体信息")
|
||||||
|
else:
|
||||||
|
# 标准模式:优先使用原生识别
|
||||||
|
mediainfo = MediaChain().recognize_media(meta=metainfo, tmdbid=tmdbid, doubanid=doubanid)
|
||||||
|
if not mediainfo:
|
||||||
|
# 尝试使用辅助识别,如果有注册响应事件的话
|
||||||
|
if eventmanager.check(ChainEventType.NameRecognize):
|
||||||
|
mediainfo = MediaChain().recognize_help(title=torrent_in.title, org_meta=metainfo)
|
||||||
|
if not mediainfo:
|
||||||
|
return schemas.Response(success=False, message="无法识别媒体信息")
|
||||||
# 种子信息
|
# 种子信息
|
||||||
torrentinfo = TorrentInfo()
|
torrentinfo = TorrentInfo()
|
||||||
torrentinfo.from_dict(torrent_in.model_dump())
|
torrentinfo.from_dict(torrent_in.model_dump())
|
||||||
|
|||||||
@@ -90,16 +90,29 @@ class MediaChain(ChainBase):
|
|||||||
根据主副标题识别媒体信息
|
根据主副标题识别媒体信息
|
||||||
"""
|
"""
|
||||||
title = metainfo.title
|
title = metainfo.title
|
||||||
# 识别媒体信息
|
mediainfo: MediaInfo = None
|
||||||
mediainfo: MediaInfo = self.recognize_media(meta=metainfo, episode_group=episode_group)
|
if settings.RECOGNIZE_PLUGIN_FIRST and eventmanager.check(ChainEventType.NameRecognize):
|
||||||
if not mediainfo:
|
# 插件优先模式:优先使用辅助识别
|
||||||
# 尝试使用辅助识别,如果有注册响应事件的话
|
logger.info(f"插件优先模式已开启。请求辅助识别,标题:{title} ...")
|
||||||
if eventmanager.check(ChainEventType.NameRecognize):
|
mediainfo = self.recognize_help(title=title, org_meta=metainfo)
|
||||||
logger.info(f'请求辅助识别,标题:{title} ...')
|
|
||||||
mediainfo = self.recognize_help(title=title, org_meta=metainfo)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{title} 未识别到媒体信息')
|
# 尝试使用原生识别
|
||||||
return None
|
logger.info(f'辅助识别未识别到 {title} 的媒体信息,尝试使用原生识别')
|
||||||
|
mediainfo = self.recognize_media(meta=metainfo, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
# 标准模式:优先使用原生识别
|
||||||
|
mediainfo = self.recognize_media(meta=metainfo, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
# 尝试使用辅助识别,如果有注册响应事件的话
|
||||||
|
if eventmanager.check(ChainEventType.NameRecognize):
|
||||||
|
logger.info(f'请求辅助识别,标题:{title} ...')
|
||||||
|
mediainfo = self.recognize_help(title=title, org_meta=metainfo)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
|
return None
|
||||||
# 识别成功
|
# 识别成功
|
||||||
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
@@ -163,16 +176,29 @@ class MediaChain(ChainBase):
|
|||||||
file_path = Path(path)
|
file_path = Path(path)
|
||||||
# 元数据
|
# 元数据
|
||||||
file_meta = MetaInfoPath(file_path)
|
file_meta = MetaInfoPath(file_path)
|
||||||
# 识别媒体信息
|
mediainfo: MediaInfo = None
|
||||||
mediainfo = self.recognize_media(meta=file_meta, episode_group=episode_group)
|
if settings.RECOGNIZE_PLUGIN_FIRST and eventmanager.check(ChainEventType.NameRecognize):
|
||||||
if not mediainfo:
|
# 插件优先模式:优先使用辅助识别
|
||||||
# 尝试使用辅助识别,如果有注册响应事件的话
|
logger.info(f"插件优先模式已开启。请求辅助识别,标题:{file_path.name} ...")
|
||||||
if eventmanager.check(ChainEventType.NameRecognize):
|
mediainfo = self.recognize_help(title=path, org_meta=file_meta)
|
||||||
logger.info(f'请求辅助识别,标题:{file_path.name} ...')
|
|
||||||
mediainfo = self.recognize_help(title=path, org_meta=file_meta)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{path} 未识别到媒体信息')
|
# 尝试使用原生识别
|
||||||
return Context(meta_info=file_meta)
|
logger.info(f'辅助识别未识别到 {path} 的媒体信息,尝试使用原生识别')
|
||||||
|
mediainfo = self.recognize_media(meta=file_meta, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{path} 未识别到媒体信息')
|
||||||
|
return Context(meta_info=file_meta)
|
||||||
|
else:
|
||||||
|
# 标准模式:优先使用原生识别
|
||||||
|
mediainfo = self.recognize_media(meta=file_meta, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
# 尝试使用辅助识别,如果有注册响应事件的话
|
||||||
|
if eventmanager.check(ChainEventType.NameRecognize):
|
||||||
|
logger.info(f'请求辅助识别,标题:{file_path.name} ...')
|
||||||
|
mediainfo = self.recognize_help(title=path, org_meta=file_meta)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{path} 未识别到媒体信息')
|
||||||
|
return Context(meta_info=file_meta)
|
||||||
logger.info(f'{path} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{path} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_images(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
@@ -826,16 +852,29 @@ class MediaChain(ChainBase):
|
|||||||
根据主副标题识别媒体信息(异步版本)
|
根据主副标题识别媒体信息(异步版本)
|
||||||
"""
|
"""
|
||||||
title = metainfo.title
|
title = metainfo.title
|
||||||
# 识别媒体信息
|
mediainfo: MediaInfo = None
|
||||||
mediainfo: MediaInfo = await self.async_recognize_media(meta=metainfo, episode_group=episode_group)
|
if settings.RECOGNIZE_PLUGIN_FIRST and eventmanager.check(ChainEventType.NameRecognize):
|
||||||
if not mediainfo:
|
# 插件优先模式:优先使用辅助识别
|
||||||
# 尝试使用辅助识别,如果有注册响应事件的话
|
logger.info(f"插件优先模式已开启。请求辅助识别,标题:{title} ...")
|
||||||
if eventmanager.check(ChainEventType.NameRecognize):
|
mediainfo = await self.async_recognize_help(title=title, org_meta=metainfo)
|
||||||
logger.info(f'请求辅助识别,标题:{title} ...')
|
|
||||||
mediainfo = await self.async_recognize_help(title=title, org_meta=metainfo)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{title} 未识别到媒体信息')
|
# 尝试使用原生识别
|
||||||
return None
|
logger.info(f'辅助识别未识别到 {title} 的媒体信息,尝试使用原生识别')
|
||||||
|
mediainfo = await self.async_recognize_media(meta=metainfo, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
# 标准模式:优先使用原生识别
|
||||||
|
mediainfo = await self.async_recognize_media(meta=metainfo, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
# 尝试使用辅助识别,如果有注册响应事件的话
|
||||||
|
if eventmanager.check(ChainEventType.NameRecognize):
|
||||||
|
logger.info(f'请求辅助识别,标题:{title} ...')
|
||||||
|
mediainfo = await self.async_recognize_help(title=title, org_meta=metainfo)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
|
return None
|
||||||
# 识别成功
|
# 识别成功
|
||||||
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
@@ -899,16 +938,29 @@ class MediaChain(ChainBase):
|
|||||||
file_path = Path(path)
|
file_path = Path(path)
|
||||||
# 元数据
|
# 元数据
|
||||||
file_meta = MetaInfoPath(file_path)
|
file_meta = MetaInfoPath(file_path)
|
||||||
# 识别媒体信息
|
mediainfo: MediaInfo = None
|
||||||
mediainfo = await self.async_recognize_media(meta=file_meta, episode_group=episode_group)
|
if settings.RECOGNIZE_PLUGIN_FIRST and eventmanager.check(ChainEventType.NameRecognize):
|
||||||
if not mediainfo:
|
# 插件优先模式:优先使用辅助识别
|
||||||
# 尝试使用辅助识别,如果有注册响应事件的话
|
logger.info(f"插件优先模式已开启。请求辅助识别,标题:{file_path.name} ...")
|
||||||
if eventmanager.check(ChainEventType.NameRecognize):
|
mediainfo = await self.async_recognize_help(title=path, org_meta=file_meta)
|
||||||
logger.info(f'请求辅助识别,标题:{file_path.name} ...')
|
|
||||||
mediainfo = await self.async_recognize_help(title=path, org_meta=file_meta)
|
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{path} 未识别到媒体信息')
|
# 尝试使用原生识别
|
||||||
return Context(meta_info=file_meta)
|
logger.info(f'辅助识别未识别到 {path} 的媒体信息,尝试使用原生识别')
|
||||||
|
mediainfo = await self.async_recognize_media(meta=file_meta, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{path} 未识别到媒体信息')
|
||||||
|
return Context(meta_info=file_meta)
|
||||||
|
else:
|
||||||
|
# 标准模式:优先使用原生识别
|
||||||
|
mediainfo = await self.async_recognize_media(meta=file_meta, episode_group=episode_group)
|
||||||
|
if not mediainfo:
|
||||||
|
# 尝试使用辅助识别,如果有注册响应事件的话
|
||||||
|
if eventmanager.check(ChainEventType.NameRecognize):
|
||||||
|
logger.info(f'请求辅助识别,标题:{file_path.name} ...')
|
||||||
|
mediainfo = await self.async_recognize_help(title=path, org_meta=file_meta)
|
||||||
|
if not mediainfo:
|
||||||
|
logger.warn(f'{path} 未识别到媒体信息')
|
||||||
|
return Context(meta_info=file_meta)
|
||||||
logger.info(f'{path} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{path} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
await self.async_obtain_images(mediainfo=mediainfo)
|
await self.async_obtain_images(mediainfo=mediainfo)
|
||||||
|
|||||||
@@ -322,6 +322,8 @@ class ConfigModel(BaseModel):
|
|||||||
DEFAULT_SUB: Optional[str] = "zh-cn"
|
DEFAULT_SUB: Optional[str] = "zh-cn"
|
||||||
# 新增已入库媒体是否跟随TMDB信息变化
|
# 新增已入库媒体是否跟随TMDB信息变化
|
||||||
SCRAP_FOLLOW_TMDB: bool = True
|
SCRAP_FOLLOW_TMDB: bool = True
|
||||||
|
# 优先使用辅助识别
|
||||||
|
RECOGNIZE_PLUGIN_FIRST: bool = False
|
||||||
|
|
||||||
# ==================== 服务地址配置 ====================
|
# ==================== 服务地址配置 ====================
|
||||||
# 服务器地址,对应 https://github.com/jxxghp/MoviePilot-Server 项目
|
# 服务器地址,对应 https://github.com/jxxghp/MoviePilot-Server 项目
|
||||||
|
|||||||
Reference in New Issue
Block a user