|
|
@@ -18,11 +18,15 @@ logger = logging.getLogger(__name__)
|
|
|
|
|
|
_LOG_LABEL = "工具调用:douyin_search -> 抖音关键词搜索(爬虫接口)"
|
|
|
|
|
|
+_MIN_REQUEST_INTERVAL_SECONDS = 10.1
|
|
|
+_rate_limit_lock = asyncio.Lock()
|
|
|
+_last_request_monotonic: float = 0.0
|
|
|
+
|
|
|
|
|
|
# API 基础配置
|
|
|
DOUYIN_SEARCH_API = "http://crawapi.piaoquantv.com/crawler/dou_yin/keyword"
|
|
|
DEFAULT_TIMEOUT = 60.0
|
|
|
-DOUYIN_ACCOUNT_ID = "771431186"
|
|
|
+DOUYIN_ACCOUNT_ID = "771431222"
|
|
|
|
|
|
|
|
|
@tool(description="通过关键词搜索抖音视频内容")
|
|
|
@@ -83,6 +87,14 @@ async def douyin_search(
|
|
|
}
|
|
|
|
|
|
try:
|
|
|
+ global _last_request_monotonic
|
|
|
+ async with _rate_limit_lock:
|
|
|
+ now_mono = time.monotonic()
|
|
|
+ wait_seconds = _MIN_REQUEST_INTERVAL_SECONDS - (now_mono - _last_request_monotonic)
|
|
|
+ if wait_seconds > 0:
|
|
|
+ await asyncio.sleep(wait_seconds)
|
|
|
+ _last_request_monotonic = time.monotonic()
|
|
|
+
|
|
|
payload = {
|
|
|
"keyword": keyword,
|
|
|
"content_type": content_type,
|