fix rardar

This commit is contained in:
jxxghp
2023-06-13 20:20:02 +08:00
parent a743403faa
commit ac9dbb5239
5 changed files with 56 additions and 38 deletions

View File

@ -15,12 +15,12 @@ from app.utils.types import MediaType
router = APIRouter()
def start_subscribe_chain(title: str,
def start_subscribe_chain(title: str, year: str,
mtype: MediaType, tmdbid: int, season: int, username: str):
"""
启动订阅链式任务
"""
SubscribeChain().process(title=title,
SubscribeChain().process(title=title, year=year,
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
@ -113,6 +113,7 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
mtype=media_type,
tmdbid=tmdbId,
title=subject,
year="",
season=0,
username=user_name)
else:
@ -126,6 +127,7 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
mtype=media_type,
tmdbid=tmdbId,
title=subject,
year="",
season=season,
username=user_name)

View File

@ -4,10 +4,12 @@ from fastapi import APIRouter, HTTPException, Depends
from requests import Session
from app import schemas
from app.chain.subscribe import SubscribeChain
from app.core.config import settings
from app.db import get_db
from app.db.models.subscribe import Subscribe
from app.schemas import RadarrMovie
from app.utils.types import MediaType
from version import APP_VERSION
arr_router = APIRouter()
@ -214,6 +216,37 @@ async def arr_movies(apikey: str, db: Session = Depends(get_db)) -> Any:
return result
@arr_router.get("/movie/lookup", response_model=List[schemas.RadarrMovie])
async def arr_movie_lookup(apikey: str, term: str, db: Session = Depends(get_db)) -> Any:
"""
查询Rardar电影 term: `tmdb:${id}`
"""
if not apikey or apikey != settings.API_TOKEN:
raise HTTPException(
status_code=403,
detail="认证失败!",
)
tmdbid = term.replace("tmdb:", "")
subscribe = Subscribe.get_by_tmdbid(db, int(tmdbid))
if subscribe:
return [RadarrMovie(
id=subscribe.id,
title=subscribe.name,
isAvailable=True,
monitored=True,
tmdbId=subscribe.tmdbid,
profileId=1,
qualityProfileId=1,
added=True,
hasFile=False,
)]
else:
raise HTTPException(
status_code=404,
detail="未找到该电影!"
)
@arr_router.get("/movie/{mid}", response_model=schemas.RadarrMovie)
async def arr_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> Any:
"""
@ -244,39 +277,8 @@ async def arr_movie(apikey: str, mid: int, db: Session = Depends(get_db)) -> Any
)
@arr_router.get("/movie/lookup", response_model=List[schemas.RadarrMovie])
async def arr_movie_lookup(apikey: str, term: str, db: Session = Depends(get_db)) -> Any:
"""
查询Rardar电影 term: `tmdb:${id}`
"""
if not apikey or apikey != settings.API_TOKEN:
raise HTTPException(
status_code=403,
detail="认证失败!",
)
tmdbid = term.replace("tmdb:", "")
subscribe = Subscribe.get_by_tmdbid(db, int(tmdbid))
if subscribe:
return RadarrMovie(
id=subscribe.id,
title=subscribe.name,
isAvailable=True,
monitored=True,
tmdbId=subscribe.tmdbid,
profileId=1,
qualityProfileId=1,
added=True,
hasFile=False,
)
else:
raise HTTPException(
status_code=404,
detail="未找到该电影!"
)
@arr_router.put("/movie", response_model=schemas.Response)
async def arr_add_movie(apikey: str, title: str, tmdbId: int, year: int) -> Any:
async def arr_add_movie(apikey: str, title: str, tmdbId: int, year: str) -> Any:
"""
新增Rardar电影订阅
"""
@ -285,6 +287,13 @@ async def arr_add_movie(apikey: str, title: str, tmdbId: int, year: int) -> Any:
status_code=403,
detail="认证失败!",
)
if SubscribeChain().process(title=title, year=year, mtype=MediaType.MOVIE, tmdbid=tmdbId):
return {"success": True, "msg": "添加订阅成功!"}
else:
raise HTTPException(
status_code=500,
detail="添加订阅失败!"
)
@arr_router.delete("/movie/{mid}", response_model=schemas.Response)