From 2f1e55fa1e7dc6ac59ce9a16416446e77b395b57 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 21 Jul 2025 12:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E7=BB=9F=E8=AE=A1=E5=92=8C=E5=BC=BA=E5=88=B6=E4=BC=91?= =?UTF-8?q?=E7=9C=A0=E6=9C=BA=E5=88=B6=E4=BB=A5=E4=BC=98=E5=8C=96=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/indexer/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/modules/indexer/__init__.py b/app/modules/indexer/__init__.py index 99293496..e9ea368e 100644 --- a/app/modules/indexer/__init__.py +++ b/app/modules/indexer/__init__.py @@ -1,3 +1,5 @@ +import random +import time from datetime import datetime from typing import List, Optional, Tuple, Union @@ -114,6 +116,7 @@ class IndexerModule(_ModuleBase): # 搜索多个关键字 error_flag = False + search_count = 0 for search_word in keywords: # 可能为关键字或ttxxxx if search_word \ @@ -129,6 +132,11 @@ class IndexerModule(_ModuleBase): logger.warn(msg) continue + if search_count > 0: + # 强制休眠 1-10 秒 + logger.info(f"站点 {site.get('name')} 已搜索 {search_count} 次,强制休眠 1-10 秒 ...") + time.sleep(random.randint(1, 10)) + # 去除搜索关键字中的特殊字符 if search_word: search_word = StringUtils.clear(search_word, replace_word=" ", allow_space=True) @@ -188,6 +196,8 @@ class IndexerModule(_ModuleBase): break except Exception as err: logger.error(f"{site.get('name')} 搜索出错:{str(err)}") + finally: + search_count += 1 # 索引花费的时间 seconds = (datetime.now() - start_time).seconds @@ -201,10 +211,10 @@ class IndexerModule(_ModuleBase): # 返回结果 if not result_array or len(result_array) == 0: - logger.warn(f"{site.get('name')} 未搜索到数据,耗时 {seconds} 秒") + logger.warn(f"{site.get('name')} 未搜索到数据,共搜索 {search_count} 次,耗时 {seconds} 秒") return [] else: - logger.info(f"{site.get('name')} 搜索完成,耗时 {seconds} 秒,返回数据:{len(result_array)}") + logger.info(f"{site.get('name')} 搜索完成,共搜索 {search_count} 次,耗时 {seconds} 秒,返回数据:{len(result_array)}") # TorrentInfo torrents = [TorrentInfo(site=site.get("id"), site_name=site.get("name"),