diff --git a/app/chain/search.py b/app/chain/search.py index 66e7724b..b3bcd3d9 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -2,7 +2,7 @@ from typing import Optional, List from app.chain import _ChainBase from app.chain.common import CommonChain -from app.core import Context, MetaInfo, MediaInfo, TorrentInfo +from app.core import Context, MetaInfo, MediaInfo, TorrentInfo, settings from app.core.meta import MetaBase from app.helper.sites import SitesHelper from app.log import logger @@ -26,13 +26,22 @@ class SearchChain(_ChainBase): :param mediainfo: 媒体信息 :param keyword: 搜索关键词 """ - # 执行搜索 logger.info(f'开始搜索资源,关键词:{keyword or mediainfo.title} ...') + # 未开启的站点不搜索 + indexer_sites = [] + for indexer in self.siteshelper.get_indexers(): + if settings.INDEXER_SITES \ + and any([s in indexer.get("domain") for s in settings.INDEXER_SITES.split(',')]): + indexer_sites.append(indexer) + if not indexer_sites: + logger.warn('未开启任何有效站点,无法搜索资源') + return [] + # 执行搜索 torrents: List[TorrentInfo] = self.run_module( 'search_torrents', mediainfo=mediainfo, keyword=keyword, - sites=self.siteshelper.get_indexers() + sites=indexer_sites ) if not torrents: logger.warn(f'{keyword or mediainfo.title} 未搜索到资源') diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 2d661e56..572ee20a 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -3,7 +3,7 @@ from typing import Dict, List, Optional from app.chain import _ChainBase from app.chain.common import CommonChain from app.chain.search import SearchChain -from app.core import MetaInfo, TorrentInfo, Context, MediaInfo +from app.core import MetaInfo, TorrentInfo, Context, MediaInfo, settings from app.db.subscribes import Subscribes from app.helper.sites import SitesHelper from app.log import logger @@ -122,6 +122,10 @@ class SubscribeChain(_ChainBase): indexers = self.siteshelper.get_indexers() # 遍历站点缓存资源 for indexer in indexers: + # 未开启的站点不搜索 + if settings.INDEXER_SITES \ + and not any([s in indexer.get("domain") for s in settings.INDEXER_SITES.split(',')]): + continue logger.info(f'开始刷新站点资源,站点:{indexer.get("name")} ...') domain = StringUtils.get_url_domain(indexer.get("domain")) torrents: List[TorrentInfo] = self.run_module("refresh_torrents", sites=[indexer]) diff --git a/app/modules/indexer/__init__.py b/app/modules/indexer/__init__.py index 314db3ed..6035beb8 100644 --- a/app/modules/indexer/__init__.py +++ b/app/modules/indexer/__init__.py @@ -53,7 +53,7 @@ class IndexerModule(_ModuleBase): results += result # 计算耗时 end_time = datetime.now() - logger.info(f"所有站点搜索完成,有效资源数:{len(results)},总耗时 {(end_time - start_time).seconds} 秒") + logger.info(f"站点搜索完成,有效资源数:{len(results)},总耗时 {(end_time - start_time).seconds} 秒") # 返回 return results @@ -74,10 +74,6 @@ class IndexerModule(_ModuleBase): else: search_word = None - # 未开启的站点不搜索 - if settings.INDEXER_SITES and not any([s in site.get("domain") for s in settings.INDEXER_SITES.split(',')]): - return [] - if search_word \ and site.get('language') == "en" \ and StringUtils.is_chinese(search_word):