This commit is contained in:
jxxghp 2023-06-14 12:45:59 +08:00
parent f7e395c834
commit e1f19b2ce0
7 changed files with 62 additions and 9 deletions

View File

@ -4,6 +4,7 @@ from fastapi import APIRouter, HTTPException, Depends, Request
from requests import Session
from app import schemas
from app.chain.identify import IdentifyChain
from app.chain.subscribe import SubscribeChain
from app.core.config import settings
from app.db import get_db
@ -468,21 +469,27 @@ async def arr_series_lookup(apikey: str, term: str, db: Session = Depends(get_db
status_code=403,
detail="认证失败!",
)
# 季列表
seasons = []
if not term.startswith("tvdb:"):
title = term
subscribe = Subscribe.get_by_title(db, title)
else:
tmdbid = term.replace("tvdb:", "")
subscribe = Subscribe.get_by_tmdbid(db, int(tmdbid))
if not subscribe:
# 查询TMDB季信息
tmdbinfo = IdentifyChain().tvdb_info(tvdbid=int(tmdbid))
if tmdbinfo:
season_num = tmdbinfo.get('season')
if season_num:
seasons = list(range(1, season_num + 1))
if subscribe:
return [SonarrSeries(
id=subscribe.id,
title=subscribe.name,
seasonCount=1,
seasons=[{
"seasonNumber": subscribe.season,
"monitored": True,
}],
seasons=[subscribe.season],
year=subscribe.year,
isAvailable=True,
monitored=True,
@ -493,7 +500,7 @@ async def arr_series_lookup(apikey: str, term: str, db: Session = Depends(get_db
hasFile=False,
)]
else:
return [SonarrSeries()]
return [SonarrSeries(seasons=seasons)]
@arr_router.get("/series/{tid}")
@ -534,7 +541,7 @@ async def arr_serie(apikey: str, tid: int, db: Session = Depends(get_db)) -> Any
@arr_router.post("/series")
async def arr_add_series(request: Request, apikey: str) -> Any:
async def arr_add_series(request: Request, apikey: str, tv: schemas.SonarrSeries) -> Any:
"""
新增Sonarr剧集订阅
"""
@ -544,7 +551,6 @@ async def arr_add_series(request: Request, apikey: str) -> Any:
detail="认证失败!",
)
logger.info(await request.body())
'''
sid = 0
for season in tv.seasons:
sid = SubscribeChain().process(title=tv.title,
@ -562,7 +568,6 @@ async def arr_add_series(request: Request, apikey: str) -> Any:
status_code=500,
detail="添加订阅失败!"
)
'''
@arr_router.delete("/series/{tid}")

View File

@ -80,6 +80,9 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
def douban_info(self, doubanid: str) -> Optional[dict]:
return self.run_module("douban_info", doubanid=doubanid)
def tvdb_info(self, tvdbid: int) -> Optional[dict]:
return self.run_module("tvdb_info", tvdbid=tvdbid)
def message_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
return self.run_module("message_parser", body=body, form=form, args=args)

View File

@ -41,6 +41,8 @@ class Settings(BaseSettings):
TMDB_API_DOMAIN: str = "api.themoviedb.org"
# TMDB API Key
TMDB_API_KEY: str = "db55323b8d3e4154498498a75642b381"
# TVDB API Key
TVDB_API_KEY: str = "6b481081-10aa-440c-99f2-21d17717ee02"
# Fanart API Key
FANART_API_KEY: str = "d2d31f9ecabea050fc7d68aa3146015f"
# 支持的后缀格式

View File

@ -68,6 +68,14 @@ class _ModuleBase(metaclass=ABCMeta):
"""
pass
def tvdb_info(self, tvdbid: int) -> Optional[dict]:
"""
获取TVDB信息
:param tvdbid: int
:return: 识别的媒体信息包括剧集信息
"""
pass
def message_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
"""
解析消息内容返回字典注意以下约定值

View File

@ -37,6 +37,7 @@ class DoubanModule(_ModuleBase):
"""
if not doubanid:
return None
logger.info(f"开始获取豆瓣信息:{doubanid} ...")
douban_info = self.doubanapi.movie_detail(doubanid)
if douban_info:
celebrities = self.doubanapi.movie_celebrities(doubanid)

View File

@ -0,0 +1,33 @@
from typing import Optional, Tuple, Union
import tvdb_api
from app.core.config import settings
from app.log import logger
from app.modules import _ModuleBase
class TheTvDbModule(_ModuleBase):
tvdb: tvdb_api.Tvdb = None
def init_module(self) -> None:
self.tvdb = tvdb_api.Tvdb(apikey=settings.TVDB_API_KEY)
def stop(self):
pass
def init_setting(self) -> Tuple[str, Union[str, bool]]:
pass
def tvdb_info(self, tvdbid: int) -> Optional[dict]:
"""
获取TVDB信息
:param tvdbid: int
:return: 识别的媒体信息包括剧集信息
"""
try:
logger.info(f"开始获取TVDB信息: {tvdbid} ...")
return self.tvdb[tvdbid].data
except Exception as err:
logger.error(f"获取TVDB信息失败: {err}")

View File

@ -42,3 +42,4 @@ chardet~=4.0.0
starlette~=0.27.0
PyVirtualDisplay~=3.0
Cython~=0.29.35
tvdb_api~=3.1