This commit is contained in:
jxxghp
2024-04-26 19:41:17 +08:00
parent f20b1bcfe9
commit 9daff87f2f
4 changed files with 15 additions and 37 deletions

View File

@ -38,6 +38,7 @@ class DoubanApi(metaclass=Singleton):
"tv_search": "/search/movie",
"book_search": "/search/book",
"group_search": "/search/group",
"person_search": "/search/celebrity",
# 各类主题合集
# start: int = 0&count: int = 20
@ -137,9 +138,6 @@ class DoubanApi(metaclass=Singleton):
# doulist
"doulist": "/doulist/",
"doulist_items": "/doulist/%s/items",
# personlist
"person_search": "/person/search",
}
_user_agents = [
@ -193,13 +191,13 @@ class DoubanApi(metaclass=Singleton):
'_ts': ts,
'_sig': self.__sign(url=req_url, ts=ts)
})
resp = RequestUtils(
with RequestUtils(
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 {}
).get_res(url=req_url, params=params) as resp:
if resp is not None and resp.status_code == 400 and "rate_limit" in resp.text:
return resp.json()
return resp.json() if resp else {}
@lru_cache(maxsize=settings.CACHE_CONF.get('douban'))
def __post(self, url: str, **kwargs) -> dict:
@ -230,6 +228,13 @@ class DoubanApi(metaclass=Singleton):
return resp.json()
return resp.json() if resp else {}
def imdbid(self, imdbid: str,
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
"""
IMDBID搜索
"""
return self.__post(self._urls["imdbid"] % imdbid, _ts=ts)
def search(self, keyword: str, start: int = 0, count: int = 20,
ts=datetime.strftime(datetime.now(), '%Y%m%d')) -> dict:
"""
@ -238,13 +243,6 @@ class DoubanApi(metaclass=Singleton):
return self.__invoke(self._urls["search"], q=keyword,
start=start, count=count, _ts=ts)
def imdbid(self, imdbid: str,
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
"""
IMDBID搜索
"""
return self.__post(self._urls["imdbid"] % imdbid, _ts=ts)
def movie_search(self, keyword: str, start: int = 0, count: int = 20,
ts=datetime.strftime(datetime.now(), '%Y%m%d')):
"""