fix douban api
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Any, Union
|
from typing import List, Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
@ -64,20 +64,22 @@ def recognize_file2(path: str,
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/search", summary="搜索媒体/人物信息", response_model=List[dict])
|
@router.get("/search", summary="搜索媒体/人物信息", response_model=List[dict])
|
||||||
def search_by_title(title: str,
|
def search(title: str,
|
||||||
type: str = "media",
|
type: str = "media",
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
count: int = 8,
|
count: int = 8,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
模糊搜索媒体/人物信息列表 media:媒体信息,person:人物信息
|
模糊搜索媒体/人物信息列表 media:媒体信息,person:人物信息
|
||||||
"""
|
"""
|
||||||
_, medias = MediaChain().search(title=title, stype=type)
|
if type == "media":
|
||||||
if medias:
|
_, medias = MediaChain().search(title=title)
|
||||||
if type == "media":
|
if medias:
|
||||||
return [media.to_dict() for media in medias[(page - 1) * count: page * count]]
|
return [media.to_dict() for media in medias[(page - 1) * count: page * count]]
|
||||||
else:
|
else:
|
||||||
return medias[(page - 1) * count: page * count]
|
persons = MediaChain().search_persons(name=title)
|
||||||
|
if persons:
|
||||||
|
return persons[(page - 1) * count: page * count]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import copy
|
|||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import Optional, List, Tuple, Union
|
from typing import Optional, List, Tuple
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.core.context import Context, MediaInfo
|
from app.core.context import Context, MediaInfo
|
||||||
@ -10,7 +10,6 @@ from app.core.event import eventmanager, Event
|
|||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo, MetaInfoPath
|
from app.core.metainfo import MetaInfo, MetaInfoPath
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import MediaPerson
|
|
||||||
from app.schemas.types import EventType, MediaType
|
from app.schemas.types import EventType, MediaType
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
@ -157,48 +156,36 @@ class MediaChain(ChainBase, metaclass=Singleton):
|
|||||||
# 返回上下文
|
# 返回上下文
|
||||||
return Context(meta_info=file_meta, media_info=mediainfo)
|
return Context(meta_info=file_meta, media_info=mediainfo)
|
||||||
|
|
||||||
def search(self, title: str,
|
def search(self, title: str) -> Tuple[Optional[MetaBase], List[MediaInfo]]:
|
||||||
stype: str = "media") -> Tuple[Optional[MetaBase], List[Union[MediaInfo, MediaPerson]]]:
|
|
||||||
"""
|
"""
|
||||||
搜索媒体/人物信息
|
搜索媒体/人物信息
|
||||||
:param title: 搜索内容
|
:param title: 搜索内容
|
||||||
:param stype: 搜索类型 media:媒体信息,person:人物信息
|
|
||||||
:return: 识别元数据,媒体信息列表
|
:return: 识别元数据,媒体信息列表
|
||||||
"""
|
"""
|
||||||
if stype == "media":
|
# 提取要素
|
||||||
# 提取要素
|
mtype, key_word, season_num, episode_num, year, content = StringUtils.get_keyword(title)
|
||||||
mtype, key_word, season_num, episode_num, year, content = StringUtils.get_keyword(title)
|
# 识别
|
||||||
# 识别
|
meta = MetaInfo(content)
|
||||||
meta = MetaInfo(content)
|
if not meta.name:
|
||||||
if not meta.name:
|
meta.cn_name = content
|
||||||
meta.cn_name = content
|
# 合并信息
|
||||||
# 合并信息
|
if mtype:
|
||||||
if mtype:
|
meta.type = mtype
|
||||||
meta.type = mtype
|
if season_num:
|
||||||
if season_num:
|
meta.begin_season = season_num
|
||||||
meta.begin_season = season_num
|
if episode_num:
|
||||||
if episode_num:
|
meta.begin_episode = episode_num
|
||||||
meta.begin_episode = episode_num
|
if year:
|
||||||
if year:
|
meta.year = year
|
||||||
meta.year = year
|
# 开始搜索
|
||||||
# 开始搜索
|
logger.info(f"开始搜索媒体信息:{meta.name}")
|
||||||
logger.info(f"开始搜索媒体信息:{meta.name}")
|
medias: Optional[List[MediaInfo]] = self.search_medias(meta=meta)
|
||||||
medias: Optional[List[MediaInfo]] = self.search_medias(meta=meta)
|
if not medias:
|
||||||
if not medias:
|
logger.warn(f"{meta.name} 没有找到对应的媒体信息!")
|
||||||
logger.warn(f"{meta.name} 没有找到对应的媒体信息!")
|
return meta, []
|
||||||
return meta, []
|
logger.info(f"{content} 搜索到 {len(medias)} 条相关媒体信息")
|
||||||
logger.info(f"{content} 搜索到 {len(medias)} 条相关媒体信息")
|
# 识别的元数据,媒体信息列表
|
||||||
# 识别的元数据,媒体信息列表
|
return meta, medias
|
||||||
return meta, medias
|
|
||||||
else:
|
|
||||||
# 搜索人物信息
|
|
||||||
logger.info(f"开始搜索人物信息:{title}")
|
|
||||||
persons = self.search_persons(name=title)
|
|
||||||
if not persons:
|
|
||||||
logger.warn(f"{title} 没有找到对应的人物信息!")
|
|
||||||
return None, []
|
|
||||||
logger.info(f"{title} 搜索到 {len(persons)} 条相关人物信息")
|
|
||||||
return None, persons
|
|
||||||
|
|
||||||
def get_tmdbinfo_by_doubanid(self, doubanid: str, mtype: MediaType = None) -> Optional[dict]:
|
def get_tmdbinfo_by_doubanid(self, doubanid: str, mtype: MediaType = None) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
|
@ -574,7 +574,7 @@ class DoubanModule(_ModuleBase):
|
|||||||
'url': item.get('target', {}).get('url'),
|
'url': item.get('target', {}).get('url'),
|
||||||
'images': item.get('target', {}).get('cover', {}),
|
'images': item.get('target', {}).get('cover', {}),
|
||||||
'avatar': item.get('target', {}).get('cover_img', {}).get('url'),
|
'avatar': item.get('target', {}).get('cover_img', {}).get('url'),
|
||||||
}) for item in result.get('items')]
|
}) for item in result.get('items') if name in item.get('target', {}).get('title')]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@retry(Exception, 5, 3, 3, logger=logger)
|
@retry(Exception, 5, 3, 3, logger=logger)
|
||||||
|
@ -181,7 +181,7 @@ class DoubanApi(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
req_url = self._base_url + url
|
req_url = self._base_url + url
|
||||||
|
|
||||||
params = {'apiKey': self._api_key}
|
params: dict = {'apiKey': self._api_key}
|
||||||
if kwargs:
|
if kwargs:
|
||||||
params.update(kwargs)
|
params.update(kwargs)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user