add apis
This commit is contained in:
@ -142,3 +142,15 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
|
||||
def register_commands(self, commands: dict) -> None:
|
||||
return self.__run_module("register_commands", commands=commands)
|
||||
|
||||
def douban_discover(self, mtype: MediaType, sort: str, tags: str,
|
||||
start: int = 0, count: int = 30) -> Optional[List[dict]]:
|
||||
return self.__run_module("douban_discover", mtype=mtype, sort=sort, tags=tags,
|
||||
start=start, count=count)
|
||||
|
||||
def tmdb_discover(self, mtype: MediaType, sort_by: str, with_genres: str,
|
||||
with_original_language: str, page: int = 1) -> Optional[List[dict]]:
|
||||
return self.__run_module("tmdb_discover", mtype=mtype,
|
||||
sort_by=sort_by, with_genres=with_genres,
|
||||
with_original_language=with_original_language,
|
||||
page=page)
|
||||
|
@ -16,7 +16,7 @@ from app.utils.http import RequestUtils
|
||||
|
||||
class CookieCloudChain(ChainBase):
|
||||
"""
|
||||
同步站点Cookie
|
||||
CookieCloud处理链
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -14,7 +14,7 @@ from app.log import logger
|
||||
|
||||
class DoubanChain(ChainBase):
|
||||
"""
|
||||
同步豆瓣想看数据
|
||||
豆瓣处理链
|
||||
"""
|
||||
|
||||
_interests_url: str = "https://www.douban.com/feed/people/%s/interests"
|
||||
|
@ -14,6 +14,9 @@ from app.utils.string import StringUtils
|
||||
|
||||
|
||||
class DownloadChain(ChainBase):
|
||||
"""
|
||||
下载处理链
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@ -84,8 +87,8 @@ class DownloadChain(ChainBase):
|
||||
_folder_name = ""
|
||||
if not torrent_file:
|
||||
# 下载种子文件
|
||||
_torrent_file, _folder_name, _ = self.download_torrent(_torrent, userid=userid)
|
||||
if not _torrent_file:
|
||||
torrent_file, _folder_name, _ = self.download_torrent(_torrent, userid=userid)
|
||||
if not torrent_file:
|
||||
return
|
||||
# 添加下载
|
||||
result: Optional[tuple] = self.download(torrent_path=torrent_file,
|
||||
|
@ -5,17 +5,18 @@ 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
|
||||
|
||||
|
||||
class MediaChain(ChainBase):
|
||||
"""
|
||||
识别处理链
|
||||
媒体信息处理链
|
||||
"""
|
||||
|
||||
def recognize_by_title(self, title: str, subtitle: str = None) -> Optional[Context]:
|
||||
"""
|
||||
识别媒体信息
|
||||
根据主副标题识别媒体信息
|
||||
"""
|
||||
logger.info(f'开始识别媒体信息,标题:{title},副标题:{subtitle} ...')
|
||||
# 识别前预处理
|
||||
@ -35,6 +36,26 @@ 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]]:
|
||||
"""
|
||||
搜索媒体信息
|
||||
@ -66,3 +87,57 @@ 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]
|
||||
|
@ -22,7 +22,7 @@ class SearchChain(ChainBase):
|
||||
|
||||
def search_by_tmdbid(self, tmdbid: int, mtype: str = None) -> Optional[List[Context]]:
|
||||
"""
|
||||
根据TMDB ID搜索资源,不过滤本地存在的内容
|
||||
根据TMDB ID搜索资源,精确匹配,但不不过滤本地存在的资源
|
||||
:param tmdbid: TMDB ID
|
||||
:param mtype: 媒体,电影 or 电视剧
|
||||
"""
|
||||
@ -32,11 +32,30 @@ class SearchChain(ChainBase):
|
||||
return None
|
||||
return self.process(mediainfo=mediainfo)
|
||||
|
||||
def search_by_title(self, title: str, site_ids: List[int] = None) -> List[TorrentInfo]:
|
||||
"""
|
||||
根据标题搜索资源,不识别不过滤,直接返回站点内容
|
||||
"""
|
||||
logger.info(f'开始搜索资源,关键词:{title} ...')
|
||||
# 未开启的站点不搜索
|
||||
indexer_sites = []
|
||||
for indexer in self.siteshelper.get_indexers():
|
||||
if not settings.INDEXER_SITES \
|
||||
or any([s in indexer.get("domain") for s in settings.INDEXER_SITES.split(',')]):
|
||||
if site_ids and indexer.get("id") not in site_ids:
|
||||
continue
|
||||
indexer_sites.append(indexer)
|
||||
if not indexer_sites:
|
||||
logger.warn('未开启任何有效站点,无法搜索资源')
|
||||
return []
|
||||
# 搜索
|
||||
return self.search_torrents(mediainfo=None, sites=indexer_sites, keyword=title)
|
||||
|
||||
def process(self, mediainfo: MediaInfo,
|
||||
keyword: str = None,
|
||||
no_exists: Dict[int, Dict[int, NotExistMediaInfo]] = None) -> Optional[List[Context]]:
|
||||
"""
|
||||
根据媒体信息,搜索种子资源
|
||||
根据媒体信息搜索种子资源,精确匹配,应用过滤规则,同时根据no_exists过滤本地已存在的资源
|
||||
:param mediainfo: 媒体信息
|
||||
:param keyword: 搜索关键词
|
||||
:param no_exists: 缺失的媒体信息
|
||||
|
@ -10,7 +10,7 @@ from app.log import logger
|
||||
|
||||
class SiteChain(ChainBase):
|
||||
"""
|
||||
站点远程管理处理链
|
||||
站点管理处理链
|
||||
"""
|
||||
|
||||
_siteoper: SiteOper = None
|
||||
|
@ -17,7 +17,7 @@ from app.schemas.types import MediaType
|
||||
|
||||
class SubscribeChain(ChainBase):
|
||||
"""
|
||||
订阅处理链
|
||||
订阅管理处理链
|
||||
"""
|
||||
|
||||
# 站点最新种子缓存 {站点域名: 种子上下文}
|
||||
|
@ -8,7 +8,7 @@ from app.schemas.types import EventType
|
||||
|
||||
class WebhookChain(ChainBase):
|
||||
"""
|
||||
响应Webhook事件
|
||||
Webhook处理链
|
||||
"""
|
||||
|
||||
def message(self, body: Any, form: Any, args: Any) -> None:
|
||||
|
Reference in New Issue
Block a user