This commit is contained in:
jxxghp 2024-04-26 20:29:04 +08:00
parent 9daff87f2f
commit c303ab0765
5 changed files with 11 additions and 31 deletions

View File

@ -1,5 +1,5 @@
from pathlib import Path
from typing import List, Any
from typing import List, Any, Union
from fastapi import APIRouter, Depends
@ -63,7 +63,7 @@ def recognize_file2(path: str,
return recognize_file(path)
@router.get("/search", summary="搜索媒体/人物信息", response_model=List[schemas.MediaInfo])
@router.get("/search", summary="搜索媒体/人物信息", response_model=List[dict])
def search_by_title(title: str,
type: str = "media",
page: int = 1,
@ -74,7 +74,10 @@ def search_by_title(title: str,
"""
_, medias = MediaChain().search(title=title, stype=type)
if medias:
if type == "media":
return [media.to_dict() for media in medias[(page - 1) * count: page * count]]
else:
return medias[(page - 1) * count: page * count]
return []

View File

@ -19,7 +19,7 @@ from app.db.message_oper import MessageOper
from app.helper.message import MessageHelper
from app.log import logger
from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent, CommingMessage, Notification, \
WebhookEventInfo, TmdbEpisode, TmdbPerson, DoubanPerson
WebhookEventInfo, TmdbEpisode, TmdbPerson
from app.schemas.types import TorrentStatus, MediaType, MediaImageType, EventType
from app.utils.object import ObjectUtils
@ -260,7 +260,7 @@ class ChainBase(metaclass=ABCMeta):
"""
return self.run_module("search_medias", meta=meta)
def search_persons(self, name: str) -> Optional[List[Union[TmdbPerson, DoubanPerson]]]:
def search_persons(self, name: str) -> Optional[List[TmdbPerson]]:
"""
搜索人物信息
:param name: 人物名称

View File

@ -10,7 +10,7 @@ from app.core.event import eventmanager, Event
from app.core.meta import MetaBase
from app.core.metainfo import MetaInfo, MetaInfoPath
from app.log import logger
from app.schemas import TmdbPerson, DoubanPerson
from app.schemas import TmdbPerson
from app.schemas.types import EventType, MediaType
from app.utils.singleton import Singleton
from app.utils.string import StringUtils
@ -158,7 +158,7 @@ class MediaChain(ChainBase, metaclass=Singleton):
return Context(meta_info=file_meta, media_info=mediainfo)
def search(self, title: str,
stype: str = "media") -> Tuple[Optional[MetaBase], List[Union[MediaInfo, TmdbPerson, DoubanPerson]]]:
stype: str = "media") -> Tuple[Optional[MetaBase], List[Union[MediaInfo, TmdbPerson]]]:
"""
搜索媒体/人物信息
:param title: 搜索内容
@ -193,7 +193,7 @@ class MediaChain(ChainBase, metaclass=Singleton):
else:
# 搜索人物信息
logger.info(f"开始搜索人物信息:{title}")
persons: Optional[List[Union[TmdbPerson, DoubanPerson]]] = self.search_persons(name=title)
persons = self.search_persons(name=title)
if not persons:
logger.warn(f"{title} 没有找到对应的人物信息!")
return None, []

View File

@ -13,7 +13,6 @@ from app.modules import _ModuleBase
from app.modules.douban.apiv2 import DoubanApi
from app.modules.douban.douban_cache import DoubanCache
from app.modules.douban.scraper import DoubanScraper
from app.schemas import DoubanPerson
from app.schemas.types import MediaType
from app.utils.common import retry
from app.utils.http import RequestUtils
@ -564,19 +563,6 @@ class DoubanModule(_ModuleBase):
media.season = meta.begin_season
return ret_medias
def search_persons(self, name: str) -> Optional[List[DoubanPerson]]:
"""
搜索人物信息
"""
if settings.RECOGNIZE_SOURCE != "douban":
return None
if not name:
return []
result = self.doubanapi.person_search(name)
if not result:
return []
return [DoubanPerson(**item) for item in result.get("items")]
@retry(Exception, 5, 3, 3, logger=logger)
def match_doubaninfo(self, name: str, imdbid: str = None,
mtype: MediaType = None, year: str = None, season: int = None) -> dict:

View File

@ -38,7 +38,6 @@ class DoubanApi(metaclass=Singleton):
"tv_search": "/search/movie",
"book_search": "/search/book",
"group_search": "/search/group",
"person_search": "/search/celebrity",
# 各类主题合集
# start: int = 0&count: int = 20
@ -275,14 +274,6 @@ class DoubanApi(metaclass=Singleton):
return self.__invoke(self._urls["group_search"], q=keyword,
start=start, count=count, _ts=ts)
def person_search(self, keyword: str, start: int = 0, count: int = 20,
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
"""
人物搜索
"""
return self.__invoke(self._urls["person_search"], q=keyword,
start=start, count=count, _ts=ts)
def movie_showing(self, start: int = 0, count: int = 20,
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
"""