fix api
This commit is contained in:
parent
4ab54b7672
commit
df05c46a5b
@ -67,15 +67,16 @@ def tmdb_recommend(tmdbid: int,
|
|||||||
@router.get("/credits/{tmdbid}/{type_name}", summary="演员阵容", response_model=List[schemas.TmdbPerson])
|
@router.get("/credits/{tmdbid}/{type_name}", summary="演员阵容", response_model=List[schemas.TmdbPerson])
|
||||||
def tmdb_credits(tmdbid: int,
|
def tmdb_credits(tmdbid: int,
|
||||||
type_name: str,
|
type_name: str,
|
||||||
|
page: int = 1,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询演员阵容,type_name: 电影/电视剧
|
根据TMDBID查询演员阵容,type_name: 电影/电视剧
|
||||||
"""
|
"""
|
||||||
mediatype = MediaType(type_name)
|
mediatype = MediaType(type_name)
|
||||||
if mediatype == MediaType.MOVIE:
|
if mediatype == MediaType.MOVIE:
|
||||||
tmdbinfos = TmdbChain().movie_credits(tmdbid=tmdbid)
|
tmdbinfos = TmdbChain().movie_credits(tmdbid=tmdbid, page=page)
|
||||||
elif mediatype == MediaType.TV:
|
elif mediatype == MediaType.TV:
|
||||||
tmdbinfos = TmdbChain().tv_credits(tmdbid=tmdbid)
|
tmdbinfos = TmdbChain().tv_credits(tmdbid=tmdbid, page=page)
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
if not tmdbinfos:
|
if not tmdbinfos:
|
||||||
|
@ -76,19 +76,21 @@ class TmdbChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("tv_recommend", tmdbid=tmdbid)
|
return self.run_module("tv_recommend", tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_credits(self, tmdbid: int) -> List[dict]:
|
def movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电影演职人员
|
根据TMDBID查询电影演职人员
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.run_module("movie_credits", tmdbid=tmdbid)
|
return self.run_module("movie_credits", tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def tv_credits(self, tmdbid: int) -> List[dict]:
|
def tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电视剧演职人员
|
根据TMDBID查询电视剧演职人员
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.run_module("tv_credits", tmdbid=tmdbid)
|
return self.run_module("tv_credits", tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def person_detail(self, person_id: int) -> dict:
|
def person_detail(self, person_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
|
@ -359,19 +359,21 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
"""
|
"""
|
||||||
return self.tmdb.get_tv_recommend(tmdbid=tmdbid)
|
return self.tmdb.get_tv_recommend(tmdbid=tmdbid)
|
||||||
|
|
||||||
def movie_credits(self, tmdbid: int) -> List[dict]:
|
def movie_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电影演职员表
|
根据TMDBID查询电影演职员表
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_movie_credits(tmdbid=tmdbid)
|
return self.tmdb.get_movie_credits(tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def tv_credits(self, tmdbid: int) -> List[dict]:
|
def tv_credits(self, tmdbid: int, page: int = 1) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
根据TMDBID查询电视剧演职员表
|
根据TMDBID查询电视剧演职员表
|
||||||
:param tmdbid: TMDBID
|
:param tmdbid: TMDBID
|
||||||
|
:param page: 页码
|
||||||
"""
|
"""
|
||||||
return self.tmdb.get_tv_credits(tmdbid=tmdbid)
|
return self.tmdb.get_tv_credits(tmdbid=tmdbid, page=page)
|
||||||
|
|
||||||
def person_detail(self, person_id: int) -> dict:
|
def person_detail(self, person_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
|
@ -1094,30 +1094,36 @@ class TmdbHelper:
|
|||||||
print(str(e))
|
print(str(e))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_movie_credits(self, tmdbid: int) -> List[dict]:
|
def get_movie_credits(self, tmdbid: int, page: int = 1, count: int = 24) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取电影的演职员列表
|
获取电影的演职员列表
|
||||||
"""
|
"""
|
||||||
if not self.movie:
|
if not self.movie:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
logger.info(f"正在获取电影演职员:{tmdbid}...")
|
logger.info(f"正在获取电影演职人员:{tmdbid}...")
|
||||||
info = self.movie.credits(movie_id=tmdbid) or {}
|
info = self.movie.credits(movie_id=tmdbid) or {}
|
||||||
return info.get('cast') or []
|
cast = info.get('cast') or []
|
||||||
|
if cast:
|
||||||
|
return [c.to_dict() for c in cast][(page - 1) * count: page * count]
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_tv_credits(self, tmdbid: int) -> List[dict]:
|
def get_tv_credits(self, tmdbid: int, page: int = 1, count: int = 24) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取电视剧的演职员列表
|
获取电视剧的演职员列表
|
||||||
"""
|
"""
|
||||||
if not self.tv:
|
if not self.tv:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
logger.info(f"正在获取电视剧演职员:{tmdbid}...")
|
logger.info(f"正在获取电视剧演职人员:{tmdbid}...")
|
||||||
info = self.tv.credits(tv_id=tmdbid) or {}
|
info = self.tv.credits(tv_id=tmdbid) or {}
|
||||||
return info.get('cast') or []
|
cast = info.get('cast') or []
|
||||||
|
if cast:
|
||||||
|
return [c.to_dict() for c in cast][(page - 1) * count: page * count]
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
return []
|
return []
|
||||||
|
@ -29,7 +29,7 @@ class TMDb(object):
|
|||||||
def __init__(self, obj_cached=True, session=None):
|
def __init__(self, obj_cached=True, session=None):
|
||||||
if self.__class__._session is None or session is not None:
|
if self.__class__._session is None or session is not None:
|
||||||
self.__class__._session = requests.Session() if session is None else session
|
self.__class__._session = requests.Session() if session is None else session
|
||||||
self._base = "https://api.themoviedb.org/3"
|
self.domain = "api.themoviedb.org"
|
||||||
self._remaining = 40
|
self._remaining = 40
|
||||||
self._reset = None
|
self._reset = None
|
||||||
self.obj_cached = obj_cached
|
self.obj_cached = obj_cached
|
||||||
@ -143,8 +143,8 @@ class TMDb(object):
|
|||||||
if self.api_key is None or self.api_key == "":
|
if self.api_key is None or self.api_key == "":
|
||||||
raise TMDbException("No API key found.")
|
raise TMDbException("No API key found.")
|
||||||
|
|
||||||
url = "%s%s?api_key=%s&%s&language=%s" % (
|
url = "https://%s/3%s?api_key=%s&%s&language=%s" % (
|
||||||
self._base,
|
self.domain,
|
||||||
action,
|
action,
|
||||||
self.api_key,
|
self.api_key,
|
||||||
params,
|
params,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user