This commit is contained in:
jxxghp 2024-06-02 21:09:15 +08:00
parent 45945bd025
commit c05223846f
4 changed files with 26 additions and 8 deletions

View File

@ -46,7 +46,9 @@ def download(
torrent_info=torrentinfo torrent_info=torrentinfo
) )
did = DownloadChain().download_single(context=context, username=current_user.name) did = DownloadChain().download_single(context=context, username=current_user.name)
return schemas.Response(success=True if did else False, data={ if not did:
return schemas.Response(success=False, message="任务添加失败")
return schemas.Response(success=True, data={
"download_id": did "download_id": did
}) })
@ -74,7 +76,9 @@ def add(
torrent_info=torrentinfo torrent_info=torrentinfo
) )
did = DownloadChain().download_single(context=context, username=current_user.name) did = DownloadChain().download_single(context=context, username=current_user.name)
return schemas.Response(success=True if did else False, data={ if not did:
return schemas.Response(success=False, message="任务添加失败")
return schemas.Response(success=True, data={
"download_id": did "download_id": did
}) })

View File

@ -85,7 +85,7 @@ def search_by_id(mediaid: str,
return schemas.Response(success=True, data=[torrent.to_dict() for torrent in torrents]) return schemas.Response(success=True, data=[torrent.to_dict() for torrent in torrents])
@router.get("/title", summary="模糊搜索资源", response_model=List[schemas.TorrentInfo]) @router.get("/title", summary="模糊搜索资源", response_model=schemas.Response)
async def search_by_title(keyword: str = None, async def search_by_title(keyword: str = None,
page: int = 0, page: int = 0,
site: int = None, site: int = None,
@ -94,4 +94,6 @@ async def search_by_title(keyword: str = None,
根据名称模糊搜索站点资源支持分页关键词为空是返回首页资源 根据名称模糊搜索站点资源支持分页关键词为空是返回首页资源
""" """
torrents = SearchChain().search_by_title(title=keyword, page=page, site=site) torrents = SearchChain().search_by_title(title=keyword, page=page, site=site)
return [torrent.to_dict() for torrent in torrents] if not torrents:
return schemas.Response(success=False, message="未搜索到任何资源")
return schemas.Response(success=True, data=[torrent.to_dict() for torrent in torrents])

View File

@ -53,12 +53,12 @@ class SearchChain(ChainBase):
} }
} }
results = self.process(mediainfo=mediainfo, area=area, no_exists=no_exists) results = self.process(mediainfo=mediainfo, area=area, no_exists=no_exists)
# 保存结果 # 保存结果
bytes_results = pickle.dumps(results) bytes_results = pickle.dumps(results)
self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results) self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results)
return results return results
def search_by_title(self, title: str, page: int = 0, site: int = None) -> List[TorrentInfo]: def search_by_title(self, title: str, page: int = 0, site: int = None) -> List[Context]:
""" """
根据标题搜索资源不识别不过滤直接返回站点内容 根据标题搜索资源不识别不过滤直接返回站点内容
:param title: 标题为空时返回所有站点首页内容 :param title: 标题为空时返回所有站点首页内容
@ -70,7 +70,17 @@ class SearchChain(ChainBase):
else: else:
logger.info(f'开始浏览资源,站点:{site} ...') logger.info(f'开始浏览资源,站点:{site} ...')
# 搜索 # 搜索
return self.__search_all_sites(keywords=[title], sites=[site] if site else None, page=page) or [] torrents = self.__search_all_sites(keywords=[title], sites=[site] if site else None, page=page) or []
if not torrents:
logger.warn(f'{title} 未搜索到资源')
return []
# 组装上下文
contexts = [Context(meta_info=MetaInfo(title=torrent.title, subtitle=torrent.description),
torrent_info=torrent) for torrent in torrents]
# 保存结果
bytes_results = pickle.dumps(contexts)
self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results)
return contexts
def last_search_results(self) -> List[Context]: def last_search_results(self) -> List[Context]:
""" """

View File

@ -674,7 +674,9 @@ class TorrentSpider:
try: try:
args = filter_item.get("args") args = filter_item.get("args")
if method_name == "re_search" and isinstance(args, list): if method_name == "re_search" and isinstance(args, list):
text = re.search(r"%s" % args[0], text).group(args[-1]) rematch = re.search(r"%s" % args[0], text)
if rematch:
text = rematch.group(args[-1])
elif method_name == "split" and isinstance(args, list): elif method_name == "split" and isinstance(args, list):
text = text.split(r"%s" % args[0])[args[-1]] text = text.split(r"%s" % args[0])[args[-1]]
elif method_name == "replace" and isinstance(args, list): elif method_name == "replace" and isinstance(args, list):