fix:演职员刮削优化

1.豆瓣查询增加速率限制后重试
2.全中文演职员跳过处理
This commit is contained in:
olly
2023-10-08 14:00:55 +08:00
parent 9236b361e2
commit 7ea0c5ee4c
3 changed files with 79 additions and 87 deletions

View File

@ -1,3 +1,4 @@
from datetime import datetime
from pathlib import Path
from typing import List, Optional, Tuple, Union
@ -10,6 +11,7 @@ from app.modules import _ModuleBase
from app.modules.douban.apiv2 import DoubanApi
from app.modules.douban.scraper import DoubanScraper
from app.schemas.types import MediaType
from app.utils.common import retry
from app.utils.system import SystemUtils
@ -393,6 +395,7 @@ class DoubanModule(_ModuleBase):
return ret_medias
@retry(Exception, 5, 3, 3, logger=logger)
def match_doubaninfo(self, name: str, mtype: str = None,
year: str = None, season: int = None) -> dict:
"""
@ -402,9 +405,15 @@ class DoubanModule(_ModuleBase):
:param year: 年份
:param season: 季号
"""
result = self.doubanapi.search(f"{name} {year or ''}".strip())
result = self.doubanapi.search(f"{name} {year or ''}".strip(),
ts=datetime.strftime(datetime.now(), '%Y%m%d%H%M%S'))
if not result:
logger.warn(f"未找到 {name} 的豆瓣信息")
return {}
# 触发rate limit
if "search_access_rate_limit" in result.values():
logger.warn(f"触发豆瓣API速率限制 错误信息 {result} ...")
raise Exception("触发豆瓣API速率限制")
for item_obj in result.get("items"):
type_name = item_obj.get("type_name")
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:

View File

@ -173,7 +173,7 @@ class DoubanApi(metaclass=Singleton):
ts = params.pop(
'_ts',
int(datetime.strftime(datetime.now(), '%Y%m%d'))
datetime.strftime(datetime.now(), '%Y%m%d')
)
params.update({
'os_rom': 'android',
@ -185,6 +185,8 @@ class DoubanApi(metaclass=Singleton):
ua=choice(self._user_agents),
session=self._session
).get_res(url=req_url, params=params)
if resp.status_code == 400 and "rate_limit" in resp.text:
return resp.json()
return resp.json() if resp else {}
def search(self, keyword, start=0, count=20,