fix api
This commit is contained in:
@ -317,3 +317,11 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
sort_by=sort_by, with_genres=with_genres,
|
||||
with_original_language=with_original_language,
|
||||
page=page)
|
||||
|
||||
def movie_top250(self, page: int = 1, count: int = 30) -> List[dict]:
|
||||
"""
|
||||
获取豆瓣电影TOP250
|
||||
:param page: 页码
|
||||
:param count: 每页数量
|
||||
"""
|
||||
return self.__run_module("movie_top250", page=page, count=count)
|
||||
|
@ -1,15 +1,18 @@
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
from typing import Optional, List
|
||||
from typing import Union
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.chain.download import DownloadChain
|
||||
from app.chain.search import SearchChain
|
||||
from app.chain.subscribe import SubscribeChain
|
||||
from app.core.config import settings
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.core.context import Context
|
||||
from app.core.context import MediaInfo
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.helper.rss import RssHelper
|
||||
from app.log import logger
|
||||
from app.schemas import MediaType
|
||||
|
||||
|
||||
class DoubanChain(ChainBase):
|
||||
@ -28,6 +31,48 @@ class DoubanChain(ChainBase):
|
||||
self.searchchain = SearchChain()
|
||||
self.subscribechain = SubscribeChain()
|
||||
|
||||
def recognize_by_doubanid(self, doubanid: str) -> Optional[Context]:
|
||||
"""
|
||||
根据豆瓣ID识别媒体信息
|
||||
"""
|
||||
logger.info(f'开始识别媒体信息,豆瓣ID:{doubanid} ...')
|
||||
# 查询豆瓣信息
|
||||
doubaninfo = self.douban_info(doubanid=doubanid)
|
||||
if not doubaninfo:
|
||||
logger.warn(f'未查询到豆瓣信息,豆瓣ID:{doubanid}')
|
||||
return None
|
||||
meta = MetaInfo(title=doubaninfo.get("original_title") or doubaninfo.get("title"))
|
||||
# 识别媒体信息
|
||||
mediainfo: MediaInfo = self.recognize_media(meta=meta)
|
||||
if not mediainfo:
|
||||
logger.warn(f'{meta.name} 未识别到TMDB媒体信息')
|
||||
return Context(meta=meta, mediainfo=MediaInfo(douban_info=doubaninfo))
|
||||
logger.info(f'{doubanid} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}{meta.season}')
|
||||
mediainfo.set_douban_info(doubaninfo)
|
||||
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]):
|
||||
"""
|
||||
同步豆瓣想看数据,发送消息
|
||||
|
@ -5,7 +5,6 @@ from app.core.context import Context, MediaInfo
|
||||
from app.core.meta import MetaBase
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.log import logger
|
||||
from app.schemas import MediaType
|
||||
from app.utils.string import StringUtils
|
||||
|
||||
|
||||
@ -36,26 +35,6 @@ class MediaChain(ChainBase):
|
||||
# 返回上下文
|
||||
return Context(meta=metainfo, mediainfo=mediainfo, title=title, subtitle=subtitle)
|
||||
|
||||
def recognize_by_doubanid(self, doubanid: str) -> Optional[Context]:
|
||||
"""
|
||||
根据豆瓣ID识别媒体信息
|
||||
"""
|
||||
logger.info(f'开始识别媒体信息,豆瓣ID:{doubanid} ...')
|
||||
# 查询豆瓣信息
|
||||
doubaninfo = self.douban_info(doubanid=doubanid)
|
||||
if not doubaninfo:
|
||||
logger.warn(f'未查询到豆瓣信息,豆瓣ID:{doubanid}')
|
||||
return None
|
||||
meta = MetaInfo(title=doubaninfo.get("original_title") or doubaninfo.get("title"))
|
||||
# 识别媒体信息
|
||||
mediainfo: MediaInfo = self.recognize_media(meta=meta)
|
||||
if not mediainfo:
|
||||
logger.warn(f'{meta.name} 未识别到TMDB媒体信息')
|
||||
return Context(meta=meta, mediainfo=MediaInfo(douban_info=doubaninfo))
|
||||
logger.info(f'{doubanid} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}{meta.season}')
|
||||
mediainfo.set_douban_info(doubaninfo)
|
||||
return Context(meta=meta, mediainfo=mediainfo)
|
||||
|
||||
def search(self, title: str) -> Tuple[MetaBase, List[MediaInfo]]:
|
||||
"""
|
||||
搜索媒体信息
|
||||
@ -87,57 +66,3 @@ class MediaChain(ChainBase):
|
||||
logger.info(f"{content} 搜索到 {len(medias)} 条相关媒体信息")
|
||||
# 识别的元数据,媒体信息列表
|
||||
return meta, medias
|
||||
|
||||
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 tmdb_movies(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}')
|
||||
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]
|
||||
|
41
app/chain/tmdb.py
Normal file
41
app/chain/tmdb.py
Normal file
@ -0,0 +1,41 @@
|
||||
from typing import List
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.core.context import MediaInfo
|
||||
from app.log import logger
|
||||
from app.schemas import MediaType
|
||||
|
||||
|
||||
class TmdbChain(ChainBase):
|
||||
|
||||
def tmdb_movies(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}')
|
||||
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]
|
Reference in New Issue
Block a user