feat:人物搜索API
This commit is contained in:
@ -13,6 +13,7 @@ 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
|
||||
@ -563,6 +564,19 @@ 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:
|
||||
|
@ -137,6 +137,9 @@ class DoubanApi(metaclass=Singleton):
|
||||
# doulist
|
||||
"doulist": "/doulist/",
|
||||
"doulist_items": "/doulist/%s/items",
|
||||
|
||||
# personlist
|
||||
"person_search": "/person/search",
|
||||
}
|
||||
|
||||
_user_agents = [
|
||||
@ -274,6 +277,14 @@ 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')):
|
||||
"""
|
||||
|
@ -13,6 +13,7 @@ from app.modules.themoviedb.category import CategoryHelper
|
||||
from app.modules.themoviedb.scraper import TmdbScraper
|
||||
from app.modules.themoviedb.tmdb_cache import TmdbCache
|
||||
from app.modules.themoviedb.tmdbapi import TmdbApi
|
||||
from app.schemas import TmdbPerson
|
||||
from app.schemas.types import MediaType, MediaImageType
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.system import SystemUtils
|
||||
@ -261,6 +262,19 @@ class TheMovieDbModule(_ModuleBase):
|
||||
return medias
|
||||
return []
|
||||
|
||||
def search_persons(self, name: str) -> Optional[List[TmdbPerson]]:
|
||||
"""
|
||||
搜索人物信息
|
||||
"""
|
||||
if settings.RECOGNIZE_SOURCE != "themoviedb":
|
||||
return None
|
||||
if not name:
|
||||
return []
|
||||
results = self.tmdb.search_persons(name)
|
||||
if results:
|
||||
return [TmdbPerson(**person) for person in results]
|
||||
return []
|
||||
|
||||
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,
|
||||
metainfo: MetaBase = None, force_nfo: bool = False, force_img: bool = False) -> None:
|
||||
"""
|
||||
|
@ -95,6 +95,20 @@ class TmdbApi:
|
||||
ret_infos.append(tv)
|
||||
return ret_infos
|
||||
|
||||
def search_persons(self, name: str) -> List[dict]:
|
||||
"""
|
||||
查询模糊匹配的所有人物TMDB信息
|
||||
"""
|
||||
if not name:
|
||||
return []
|
||||
ret_infos = []
|
||||
persons = self.person.search(query=name) or []
|
||||
for person in persons:
|
||||
if name in person.get("name"):
|
||||
person['media_type'] = MediaType.PERSON
|
||||
ret_infos.append(person)
|
||||
return ret_infos
|
||||
|
||||
@staticmethod
|
||||
def __compare_names(file_name: str, tmdb_names: list) -> bool:
|
||||
"""
|
||||
|
@ -136,3 +136,16 @@ class Person(TMDb):
|
||||
params="page=%s" % page,
|
||||
key="results"
|
||||
)
|
||||
|
||||
def search(self, query, page=1):
|
||||
"""
|
||||
Search for people.
|
||||
:param query: str
|
||||
:param page: int
|
||||
:return:
|
||||
"""
|
||||
return self._request_obj(
|
||||
self._urls["search_people"],
|
||||
params="query=%s&page=%s" % (query, page),
|
||||
key="results"
|
||||
)
|
||||
|
Reference in New Issue
Block a user