fix apis
This commit is contained in:
parent
8b4a44c8d4
commit
6d4b1eed77
@ -9,6 +9,7 @@ from app.core.context import MediaInfo
|
|||||||
from app.db.models.user import User
|
from app.db.models.user import User
|
||||||
from app.db.userauth import get_current_active_superuser
|
from app.db.userauth import get_current_active_superuser
|
||||||
from app.db.userauth import get_current_active_user
|
from app.db.userauth import get_current_active_user
|
||||||
|
from app.schemas import MediaType
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -63,8 +64,11 @@ async def douban_movies(sort: str = "R",
|
|||||||
"""
|
"""
|
||||||
浏览豆瓣电影信息
|
浏览豆瓣电影信息
|
||||||
"""
|
"""
|
||||||
movies = DoubanChain().douban_movies(sort=sort, tags=tags, start=start, count=count)
|
movies = DoubanChain().douban_discover(mtype=MediaType.MOVIE,
|
||||||
return [movie.to_dict() for movie in movies]
|
sort=sort, tags=tags, start=start, count=count)
|
||||||
|
if not movies:
|
||||||
|
return []
|
||||||
|
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/doubantvs", response_model=List[schemas.MediaInfo])
|
@router.get("/doubantvs", response_model=List[schemas.MediaInfo])
|
||||||
@ -76,8 +80,11 @@ async def douban_tvs(sort: str = "R",
|
|||||||
"""
|
"""
|
||||||
浏览豆瓣剧集信息
|
浏览豆瓣剧集信息
|
||||||
"""
|
"""
|
||||||
tvs = DoubanChain().douban_tvs(sort=sort, tags=tags, start=start, count=count)
|
tvs = DoubanChain().douban_discover(mtype=MediaType.TV,
|
||||||
return [tv.to_dict() for tv in tvs]
|
sort=sort, tags=tags, start=start, count=count)
|
||||||
|
if not tvs:
|
||||||
|
return []
|
||||||
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/top250", response_model=List[schemas.MediaInfo])
|
@router.get("/top250", response_model=List[schemas.MediaInfo])
|
||||||
@ -88,4 +95,4 @@ async def movie_top250(page: int = 1,
|
|||||||
浏览豆瓣剧集信息
|
浏览豆瓣剧集信息
|
||||||
"""
|
"""
|
||||||
movies = DoubanChain().movie_top250(page=page, count=count)
|
movies = DoubanChain().movie_top250(page=page, count=count)
|
||||||
return [movie.to_dict() for movie in movies]
|
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
||||||
|
@ -3,8 +3,8 @@ from typing import List, Any
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain.media import MediaChain
|
|
||||||
from app.chain.tmdb import TmdbChain
|
from app.chain.tmdb import TmdbChain
|
||||||
|
from app.core.context import MediaInfo
|
||||||
from app.db.models.user import User
|
from app.db.models.user import User
|
||||||
from app.db.userauth import get_current_active_user
|
from app.db.userauth import get_current_active_user
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
@ -18,11 +18,11 @@ async def tmdb_info(tmdbid: int, type_name: str) -> Any:
|
|||||||
根据TMDBID查询themoviedb媒体信息
|
根据TMDBID查询themoviedb媒体信息
|
||||||
"""
|
"""
|
||||||
mtype = MediaType.MOVIE if type_name == MediaType.MOVIE.value else MediaType.TV
|
mtype = MediaType.MOVIE if type_name == MediaType.MOVIE.value else MediaType.TV
|
||||||
media = MediaChain().recognize_media(tmdbid=tmdbid, mtype=mtype)
|
tmdbinfo = TmdbChain().tmdb_info(tmdbid=tmdbid, mtype=mtype)
|
||||||
if media:
|
if not tmdbinfo:
|
||||||
return media.to_dict()
|
|
||||||
else:
|
|
||||||
return schemas.MediaInfo()
|
return schemas.MediaInfo()
|
||||||
|
else:
|
||||||
|
return MediaInfo(tmdb_info=tmdbinfo).to_dict()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/tmdbmovies", response_model=List[schemas.MediaInfo])
|
@router.get("/tmdbmovies", response_model=List[schemas.MediaInfo])
|
||||||
@ -34,11 +34,14 @@ async def tmdb_movies(sort_by: str = "popularity.desc",
|
|||||||
"""
|
"""
|
||||||
浏览TMDB电影信息
|
浏览TMDB电影信息
|
||||||
"""
|
"""
|
||||||
movies = TmdbChain().tmdb_movies(sort_by=sort_by,
|
movies = TmdbChain().tmdb_discover(mtype=MediaType.MOVIE,
|
||||||
|
sort_by=sort_by,
|
||||||
with_genres=with_genres,
|
with_genres=with_genres,
|
||||||
with_original_language=with_original_language,
|
with_original_language=with_original_language,
|
||||||
page=page)
|
page=page)
|
||||||
return [movie.to_dict() for movie in movies]
|
if not movies:
|
||||||
|
return []
|
||||||
|
return [MediaInfo(tmdb_info=movie).to_dict() for movie in movies]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/tmdbtvs", response_model=List[schemas.MediaInfo])
|
@router.get("/tmdbtvs", response_model=List[schemas.MediaInfo])
|
||||||
@ -50,8 +53,11 @@ async def tmdb_tvs(sort_by: str = "popularity.desc",
|
|||||||
"""
|
"""
|
||||||
浏览TMDB剧集信息
|
浏览TMDB剧集信息
|
||||||
"""
|
"""
|
||||||
tvs = TmdbChain().tmdb_tvs(sort_by=sort_by,
|
tvs = TmdbChain().tmdb_discover(mtype=MediaType.TV,
|
||||||
|
sort_by=sort_by,
|
||||||
with_genres=with_genres,
|
with_genres=with_genres,
|
||||||
with_original_language=with_original_language,
|
with_original_language=with_original_language,
|
||||||
page=page)
|
page=page)
|
||||||
return [tv.to_dict() for tv in tvs]
|
if not tvs:
|
||||||
|
return []
|
||||||
|
return [MediaInfo(tmdb_info=tv).to_dict() for tv in tvs]
|
||||||
|
@ -108,6 +108,15 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return self.__run_module("tvdb_info", tvdbid=tvdbid)
|
return self.__run_module("tvdb_info", tvdbid=tvdbid)
|
||||||
|
|
||||||
|
def tmdb_info(self, tmdbid: int, mtype: MediaType) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
获取TMDB信息
|
||||||
|
:param tmdbid: int
|
||||||
|
:param mtype: 媒体类型
|
||||||
|
:return: TVDB信息
|
||||||
|
"""
|
||||||
|
return self.__run_module("tmdb_info", tmdbid=tmdbid, mtype=mtype)
|
||||||
|
|
||||||
def message_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
def message_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
解析消息内容,返回字典,注意以下约定值:
|
解析消息内容,返回字典,注意以下约定值:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, List
|
from typing import Optional
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
@ -12,7 +12,6 @@ from app.core.context import MediaInfo
|
|||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.helper.rss import RssHelper
|
from app.helper.rss import RssHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import MediaType
|
|
||||||
|
|
||||||
|
|
||||||
class DoubanChain(ChainBase):
|
class DoubanChain(ChainBase):
|
||||||
@ -51,28 +50,6 @@ class DoubanChain(ChainBase):
|
|||||||
mediainfo.set_douban_info(doubaninfo)
|
mediainfo.set_douban_info(doubaninfo)
|
||||||
return Context(meta=meta, mediainfo=mediainfo)
|
return Context(meta=meta, mediainfo=mediainfo)
|
||||||
|
|
||||||
def douban_movies(self, sort: str, tags: str, start: int = 0, count: int = 30) -> List[MediaInfo]:
|
|
||||||
"""
|
|
||||||
浏览豆瓣电影列表
|
|
||||||
"""
|
|
||||||
logger.info(f'开始获取豆瓣电影列表,排序:{sort},标签:{tags}')
|
|
||||||
movies = self.douban_discover(mtype=MediaType.MOVIE, sort=sort, tags=tags, start=start, count=count)
|
|
||||||
if not movies:
|
|
||||||
logger.warn(f'豆瓣电影列表为空,排序:{sort},标签:{tags}')
|
|
||||||
return []
|
|
||||||
return [MediaInfo(douban_info=movie) for movie in movies]
|
|
||||||
|
|
||||||
def douban_tvs(self, sort: str, tags: str, start: int = 0, count: int = 30) -> List[MediaInfo]:
|
|
||||||
"""
|
|
||||||
浏览豆瓣剧集列表
|
|
||||||
"""
|
|
||||||
logger.info(f'开始获取豆瓣剧集列表,排序:{sort},标签:{tags}')
|
|
||||||
tvs = self.douban_discover(mtype=MediaType.TV, sort=sort, tags=tags, start=start, count=count)
|
|
||||||
if not tvs:
|
|
||||||
logger.warn(f'豆瓣剧集列表为空,排序:{sort},标签:{tags}')
|
|
||||||
return []
|
|
||||||
return [MediaInfo(douban_info=tv) for tv in tvs]
|
|
||||||
|
|
||||||
def remote_sync(self, userid: Union[int, str]):
|
def remote_sync(self, userid: Union[int, str]):
|
||||||
"""
|
"""
|
||||||
同步豆瓣想看数据,发送消息
|
同步豆瓣想看数据,发送消息
|
||||||
|
@ -1,41 +1,8 @@
|
|||||||
from typing import List
|
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.core.context import MediaInfo
|
|
||||||
from app.log import logger
|
|
||||||
from app.schemas import MediaType
|
|
||||||
|
|
||||||
|
|
||||||
class TmdbChain(ChainBase):
|
class TmdbChain(ChainBase):
|
||||||
|
|
||||||
def tmdb_movies(self, sort_by: str, with_genres: str, with_original_language: str,
|
|
||||||
page: int = 1) -> List[MediaInfo]:
|
|
||||||
"""
|
"""
|
||||||
浏览TMDB电影信息
|
TheMovieDB处理链
|
||||||
"""
|
"""
|
||||||
logger.info(f'开始获取TMDB电影列表,排序:{sort_by},类型:{with_genres},语言:{with_original_language}')
|
pass
|
||||||
movies = self.tmdb_discover(mtype=MediaType.MOVIE,
|
|
||||||
sort_by=sort_by,
|
|
||||||
with_genres=with_genres,
|
|
||||||
with_original_language=with_original_language,
|
|
||||||
page=page)
|
|
||||||
if not movies:
|
|
||||||
logger.warn(f'TMDB电影列表为空,排序:{sort_by},类型:{with_genres},语言:{with_original_language}')
|
|
||||||
return []
|
|
||||||
return [MediaInfo(tmdb_info=movie) for movie in movies]
|
|
||||||
|
|
||||||
def tmdb_tvs(self, sort_by: str, with_genres: str, with_original_language: str,
|
|
||||||
page: int = 1) -> List[MediaInfo]:
|
|
||||||
"""
|
|
||||||
浏览TMDB剧集信息
|
|
||||||
"""
|
|
||||||
logger.info(f'开始获取TMDB剧集列表,排序:{sort_by},类型:{with_genres},语言:{with_original_language}')
|
|
||||||
tvs = self.tmdb_discover(mtype=MediaType.TV,
|
|
||||||
sort_by=sort_by,
|
|
||||||
with_genres=with_genres,
|
|
||||||
with_original_language=with_original_language,
|
|
||||||
page=page)
|
|
||||||
if not tvs:
|
|
||||||
logger.warn(f'TMDB剧集列表为空,排序:{sort_by},类型:{with_genres},语言:{with_original_language}')
|
|
||||||
return []
|
|
||||||
return [MediaInfo(tmdb_info=tv) for tv in tvs]
|
|
||||||
|
@ -138,6 +138,15 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def tmdb_info(self, tmdbid: int, mtype: MediaType) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
获取TMDB信息
|
||||||
|
:param tmdbid: int
|
||||||
|
:param mtype: 媒体类型
|
||||||
|
:return: TVDB信息
|
||||||
|
"""
|
||||||
|
return self.tmdb.get_info(mtype=mtype, tmdbid=tmdbid)
|
||||||
|
|
||||||
def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]:
|
def search_medias(self, meta: MetaBase) -> Optional[List[MediaInfo]]:
|
||||||
"""
|
"""
|
||||||
搜索媒体信息
|
搜索媒体信息
|
||||||
|
Loading…
x
Reference in New Issue
Block a user