add 搜索结果保存与查询
This commit is contained in:
parent
f77164f90a
commit
6f3209f95d
@ -12,6 +12,15 @@ from app.schemas.types import MediaType
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/last", summary="查询搜索结果", response_model=List[schemas.Context])
|
||||||
|
async def search_latest(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
查询搜索结果
|
||||||
|
"""
|
||||||
|
torrents = SearchChain().last_search_results()
|
||||||
|
return [torrent.to_dict() for torrent in torrents]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/media/{mediaid}", summary="精确搜索资源", response_model=List[schemas.Context])
|
@router.get("/media/{mediaid}", summary="精确搜索资源", response_model=List[schemas.Context])
|
||||||
async def search_by_tmdbid(mediaid: str,
|
async def search_by_tmdbid(mediaid: str,
|
||||||
mtype: str = None,
|
mtype: str = None,
|
||||||
|
@ -46,10 +46,10 @@ class DoubanChain(ChainBase):
|
|||||||
mediainfo: MediaInfo = self.recognize_media(meta=meta)
|
mediainfo: MediaInfo = self.recognize_media(meta=meta)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{meta.name} 未识别到TMDB媒体信息')
|
logger.warn(f'{meta.name} 未识别到TMDB媒体信息')
|
||||||
return Context(meta=meta, mediainfo=MediaInfo(douban_info=doubaninfo))
|
return Context(meta_info=meta, media_info=MediaInfo(douban_info=doubaninfo))
|
||||||
logger.info(f'{doubanid} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}{meta.season}')
|
logger.info(f'{doubanid} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}{meta.season}')
|
||||||
mediainfo.set_douban_info(doubaninfo)
|
mediainfo.set_douban_info(doubaninfo)
|
||||||
return Context(meta=meta, mediainfo=mediainfo)
|
return Context(meta_info=meta, media_info=mediainfo)
|
||||||
|
|
||||||
def movie_top250(self, page: int = 1, count: int = 30) -> List[dict]:
|
def movie_top250(self, page: int = 1, count: int = 30) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
|
@ -28,12 +28,12 @@ class MediaChain(ChainBase):
|
|||||||
mediainfo: MediaInfo = self.recognize_media(meta=metainfo)
|
mediainfo: MediaInfo = self.recognize_media(meta=metainfo)
|
||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.warn(f'{title} 未识别到媒体信息')
|
logger.warn(f'{title} 未识别到媒体信息')
|
||||||
return Context(meta=metainfo)
|
return Context(meta_info=metainfo)
|
||||||
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_images(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
# 返回上下文
|
# 返回上下文
|
||||||
return Context(meta=metainfo, mediainfo=mediainfo, title=title, subtitle=subtitle)
|
return Context(meta_info=metainfo, media_info=mediainfo)
|
||||||
|
|
||||||
def search(self, title: str) -> Tuple[MetaBase, List[MediaInfo]]:
|
def search(self, title: str) -> Tuple[MetaBase, List[MediaInfo]]:
|
||||||
"""
|
"""
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import pickle
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
@ -8,11 +9,12 @@ from app.core.config import settings
|
|||||||
from app.core.context import Context
|
from app.core.context import Context
|
||||||
from app.core.context import MediaInfo, TorrentInfo
|
from app.core.context import MediaInfo, TorrentInfo
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.progress import ProgressHelper
|
from app.helper.progress import ProgressHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import NotExistMediaInfo
|
from app.schemas import NotExistMediaInfo
|
||||||
from app.schemas.types import MediaType, ProgressKey
|
from app.schemas.types import MediaType, ProgressKey, SystemConfigKey
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ class SearchChain(ChainBase):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.siteshelper = SitesHelper()
|
self.siteshelper = SitesHelper()
|
||||||
self.progress = ProgressHelper()
|
self.progress = ProgressHelper()
|
||||||
|
self.systemconfig = SystemConfigOper()
|
||||||
|
|
||||||
def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]:
|
def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]:
|
||||||
"""
|
"""
|
||||||
@ -36,7 +39,10 @@ class SearchChain(ChainBase):
|
|||||||
if not mediainfo:
|
if not mediainfo:
|
||||||
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
logger.error(f'{tmdbid} 媒体信息识别失败!')
|
||||||
return None
|
return None
|
||||||
return self.process(mediainfo=mediainfo)
|
results = self.process(mediainfo=mediainfo)
|
||||||
|
# 保存眲结果
|
||||||
|
self.systemconfig.set(SystemConfigKey.SearchResults, pickle.dumps(results))
|
||||||
|
return results
|
||||||
|
|
||||||
def search_by_title(self, title: str) -> List[TorrentInfo]:
|
def search_by_title(self, title: str) -> List[TorrentInfo]:
|
||||||
"""
|
"""
|
||||||
@ -47,6 +53,15 @@ class SearchChain(ChainBase):
|
|||||||
# 搜索
|
# 搜索
|
||||||
return self.__search_all_sites(keyword=title)
|
return self.__search_all_sites(keyword=title)
|
||||||
|
|
||||||
|
def last_search_results(self) -> List[Context]:
|
||||||
|
"""
|
||||||
|
获取上次搜索结果
|
||||||
|
"""
|
||||||
|
results = self.systemconfig.get(SystemConfigKey.SearchResults)
|
||||||
|
if not results:
|
||||||
|
return []
|
||||||
|
return pickle.loads(results)
|
||||||
|
|
||||||
def browse(self, domain: str, keyword: str = None) -> List[TorrentInfo]:
|
def browse(self, domain: str, keyword: str = None) -> List[TorrentInfo]:
|
||||||
"""
|
"""
|
||||||
浏览站点首页内容
|
浏览站点首页内容
|
||||||
@ -168,9 +183,9 @@ class SearchChain(ChainBase):
|
|||||||
_match_torrents = torrents
|
_match_torrents = torrents
|
||||||
logger.info(f"匹配完成,共匹配到 {len(_match_torrents)} 个资源")
|
logger.info(f"匹配完成,共匹配到 {len(_match_torrents)} 个资源")
|
||||||
# 组装上下文返回
|
# 组装上下文返回
|
||||||
return [Context(meta=MetaInfo(title=torrent.title, subtitle=torrent.description),
|
return [Context(meta_info=MetaInfo(title=torrent.title, subtitle=torrent.description),
|
||||||
mediainfo=mediainfo,
|
media_info=mediainfo,
|
||||||
torrentinfo=torrent) for torrent in _match_torrents]
|
torrent_info=torrent) for torrent in _match_torrents]
|
||||||
|
|
||||||
def __search_all_sites(self, mediainfo: Optional[MediaInfo] = None,
|
def __search_all_sites(self, mediainfo: Optional[MediaInfo] = None,
|
||||||
keyword: str = None) -> Optional[List[TorrentInfo]]:
|
keyword: str = None) -> Optional[List[TorrentInfo]]:
|
||||||
|
@ -304,7 +304,7 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'未识别到媒体信息,标题:{torrent.title}')
|
logger.warn(f'未识别到媒体信息,标题:{torrent.title}')
|
||||||
continue
|
continue
|
||||||
# 上下文
|
# 上下文
|
||||||
context = Context(meta=meta, mediainfo=mediainfo, torrentinfo=torrent)
|
context = Context(meta_info=meta, media_info=mediainfo, torrent_info=torrent)
|
||||||
self._torrents_cache[domain].append(context)
|
self._torrents_cache[domain].append(context)
|
||||||
# 从缓存中匹配订阅
|
# 从缓存中匹配订阅
|
||||||
self.match()
|
self.match()
|
||||||
|
@ -478,25 +478,10 @@ class Context:
|
|||||||
|
|
||||||
# 识别信息
|
# 识别信息
|
||||||
meta_info: MetaBase = None
|
meta_info: MetaBase = None
|
||||||
# 种子信息
|
|
||||||
torrent_info: TorrentInfo = None
|
|
||||||
# 媒体信息
|
# 媒体信息
|
||||||
media_info: MediaInfo = None
|
media_info: MediaInfo = None
|
||||||
|
# 种子信息
|
||||||
def __init__(self,
|
torrent_info: TorrentInfo = None
|
||||||
meta: MetaBase = None,
|
|
||||||
mediainfo: MediaInfo = None,
|
|
||||||
torrentinfo: TorrentInfo = None,
|
|
||||||
**kwargs):
|
|
||||||
if meta:
|
|
||||||
self.meta_info = meta
|
|
||||||
if mediainfo:
|
|
||||||
self.media_info = mediainfo
|
|
||||||
if torrentinfo:
|
|
||||||
self.torrent_info = torrentinfo
|
|
||||||
if kwargs:
|
|
||||||
for k, v in kwargs.items():
|
|
||||||
setattr(self, k, v)
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""
|
"""
|
||||||
|
@ -34,6 +34,8 @@ class EventType(Enum):
|
|||||||
class SystemConfigKey(Enum):
|
class SystemConfigKey(Enum):
|
||||||
# 用户已安装的插件
|
# 用户已安装的插件
|
||||||
UserInstalledPlugins = "UserInstalledPlugins"
|
UserInstalledPlugins = "UserInstalledPlugins"
|
||||||
|
# 搜索结果
|
||||||
|
SearchResults = "SearchResults"
|
||||||
|
|
||||||
|
|
||||||
# 站点框架
|
# 站点框架
|
||||||
|
Loading…
x
Reference in New Issue
Block a user