fix api
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.endpoints import login, user, site, message, webhook, subscribe, media, douban
|
||||
from app.api.endpoints import login, user, site, message, webhook, subscribe, media, douban, search
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(login.router, tags=["login"])
|
||||
@ -10,4 +10,5 @@ api_router.include_router(message.router, prefix="/message", tags=["message"])
|
||||
api_router.include_router(webhook.router, prefix="/webhook", tags=["webhook"])
|
||||
api_router.include_router(subscribe.router, prefix="/subscribe", tags=["subscribe"])
|
||||
api_router.include_router(media.router, prefix="/media", tags=["media"])
|
||||
api_router.include_router(search.router, prefix="/search", tags=["search"])
|
||||
api_router.include_router(douban.router, prefix="/douban", tags=["douban"])
|
||||
|
@ -1,7 +1,9 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, BackgroundTasks
|
||||
|
||||
from app import schemas
|
||||
from app.chain.douban_sync import DoubanSyncChain
|
||||
from app.chain.douban import DoubanChain
|
||||
from app.db.models.user import User
|
||||
from app.db.userauth import get_current_active_superuser
|
||||
|
||||
@ -12,15 +14,15 @@ def start_douban_chain():
|
||||
"""
|
||||
启动链式任务
|
||||
"""
|
||||
DoubanSyncChain().process()
|
||||
DoubanChain().sync()
|
||||
|
||||
|
||||
@router.get("/sync", response_model=schemas.Response)
|
||||
async def sync_douban(
|
||||
background_tasks: BackgroundTasks,
|
||||
_: User = Depends(get_current_active_superuser)):
|
||||
_: User = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
查询所有订阅
|
||||
同步豆瓣想看
|
||||
"""
|
||||
background_tasks.add_task(start_douban_chain)
|
||||
return {"success": True}
|
||||
|
@ -1,20 +1,59 @@
|
||||
from typing import List, Any
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from app import schemas
|
||||
from app.chain.identify import IdentifyChain
|
||||
from app.chain.media import MediaChain
|
||||
from app.core.context import MediaInfo
|
||||
from app.db.models.user import User
|
||||
from app.db.userauth import get_current_active_user
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/recognize", response_model=schemas.Context)
|
||||
@router.get("/recognize", response_model=schemas.Context)
|
||||
async def recognize(title: str,
|
||||
subtitle: str = None,
|
||||
_: User = Depends(get_current_active_user)):
|
||||
_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
识别媒体信息
|
||||
"""
|
||||
# 识别媒体信息
|
||||
context = IdentifyChain().process(title=title, subtitle=subtitle)
|
||||
context = MediaChain().recognize_by_title(title=title, subtitle=subtitle)
|
||||
return context.to_dict()
|
||||
|
||||
|
||||
@router.get("/tmdb", response_model=schemas.MediaInfo)
|
||||
async def tmdb_info(tmdbid: int, type_name: str) -> Any:
|
||||
"""
|
||||
根据TMDBID查询媒体信息
|
||||
"""
|
||||
mtype = MediaType.MOVIE if type_name == MediaType.MOVIE.value else MediaType.TV
|
||||
media = MediaChain().recognize_media(tmdbid=tmdbid, mtype=mtype)
|
||||
if media:
|
||||
return media.to_dict()
|
||||
else:
|
||||
return schemas.MediaInfo()
|
||||
|
||||
|
||||
@router.get("/douban", response_model=schemas.MediaInfo)
|
||||
async def douban_info(doubanid: str) -> Any:
|
||||
"""
|
||||
根据豆瓣ID查询豆瓣媒体信息
|
||||
"""
|
||||
doubaninfo = MediaChain().douban_info(doubanid=doubanid)
|
||||
if doubaninfo:
|
||||
return MediaInfo(douban_info=doubaninfo).to_dict()
|
||||
else:
|
||||
return schemas.MediaInfo()
|
||||
|
||||
|
||||
@router.get("/search", response_model=List[schemas.MediaInfo])
|
||||
async def search_by_title(title: str,
|
||||
_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
搜索媒体信息
|
||||
"""
|
||||
_, medias = MediaChain().search(title=title)
|
||||
return [media.to_dict() for media in medias]
|
||||
|
@ -5,7 +5,7 @@ from fastapi import Request
|
||||
from starlette.responses import PlainTextResponse
|
||||
|
||||
from app import schemas
|
||||
from app.chain.user_message import UserMessageChain
|
||||
from app.chain.message import MessageChain
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
from app.modules.wechat.WXBizMsgCrypt3 import WXBizMsgCrypt
|
||||
@ -17,7 +17,7 @@ def start_message_chain(body: Any, form: Any, args: Any):
|
||||
"""
|
||||
启动链式任务
|
||||
"""
|
||||
UserMessageChain().process(body=body, form=form, args=args)
|
||||
MessageChain().process(body=body, form=form, args=args)
|
||||
|
||||
|
||||
@router.post("/", response_model=schemas.Response)
|
||||
@ -33,7 +33,8 @@ async def user_message(background_tasks: BackgroundTasks, request: Request):
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def wechat_verify(echostr: str, msg_signature: str, timestamp: Union[str, int], nonce: str):
|
||||
async def wechat_verify(echostr: str, msg_signature: str,
|
||||
timestamp: Union[str, int], nonce: str) -> Any:
|
||||
"""
|
||||
用户消息响应
|
||||
"""
|
||||
|
24
app/api/endpoints/search.py
Normal file
24
app/api/endpoints/search.py
Normal file
@ -0,0 +1,24 @@
|
||||
from typing import List, Any
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from app import schemas
|
||||
from app.chain.search import SearchChain
|
||||
from app.db.models.user import User
|
||||
from app.db.userauth import get_current_active_user
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/tmdbid", response_model=List[schemas.Context])
|
||||
async def search_by_tmdbid(tmdbid: int,
|
||||
mtype: str = None,
|
||||
_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
根据TMDBID搜索资源
|
||||
"""
|
||||
if mtype:
|
||||
mtype = MediaType.TV if mtype == MediaType.TV.value else MediaType.MOVIE
|
||||
torrents = SearchChain().search_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
|
||||
return [torrent.to_dict() for torrent in torrents]
|
@ -43,7 +43,7 @@ async def update_site(
|
||||
|
||||
|
||||
@router.get("/cookiecloud", response_model=schemas.Response)
|
||||
async def cookie_cloud_sync(_: User = Depends(get_current_active_user)) -> dict:
|
||||
async def cookie_cloud_sync(_: User = Depends(get_current_active_user)) -> Any:
|
||||
"""
|
||||
运行CookieCloud同步站点信息
|
||||
"""
|
||||
|
@ -20,14 +20,14 @@ def start_subscribe_chain(title: str, year: str,
|
||||
"""
|
||||
启动订阅链式任务
|
||||
"""
|
||||
SubscribeChain().process(title=title, year=year,
|
||||
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
|
||||
SubscribeChain().add(title=title, year=year,
|
||||
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
|
||||
|
||||
|
||||
@router.get("/", response_model=List[schemas.Subscribe])
|
||||
async def read_subscribes(
|
||||
db: Session = Depends(get_db),
|
||||
_: User = Depends(get_current_active_superuser)):
|
||||
_: User = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
查询所有订阅
|
||||
"""
|
||||
@ -43,7 +43,7 @@ async def create_subscribe(
|
||||
"""
|
||||
新增订阅
|
||||
"""
|
||||
result = SubscribeChain().process(**subscribe_in.dict())
|
||||
result = SubscribeChain().add(**subscribe_in.dict())
|
||||
return {"success": result}
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ async def delete_subscribe(
|
||||
|
||||
@router.post("/seerr", response_model=schemas.Response)
|
||||
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
||||
authorization: str = Header(None)):
|
||||
authorization: str = Header(None)) -> Any:
|
||||
"""
|
||||
Jellyseerr/Overseerr订阅
|
||||
"""
|
||||
@ -136,7 +136,7 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
|
||||
|
||||
@router.get("/refresh", response_model=schemas.Response)
|
||||
async def refresh_subscribes(
|
||||
_: User = Depends(get_current_active_superuser)):
|
||||
_: User = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
刷新所有订阅
|
||||
"""
|
||||
@ -146,7 +146,7 @@ async def refresh_subscribes(
|
||||
|
||||
@router.get("/search", response_model=schemas.Response)
|
||||
async def search_subscribes(
|
||||
_: User = Depends(get_current_active_superuser)):
|
||||
_: User = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
搜索所有订阅
|
||||
"""
|
||||
|
@ -3,7 +3,7 @@ from typing import Any
|
||||
from fastapi import APIRouter, BackgroundTasks, Request
|
||||
|
||||
from app import schemas
|
||||
from app.chain.webhook_message import WebhookMessageChain
|
||||
from app.chain.webhook import WebhookChain
|
||||
from app.core.config import settings
|
||||
|
||||
router = APIRouter()
|
||||
@ -13,11 +13,12 @@ def start_webhook_chain(body: Any, form: Any, args: Any):
|
||||
"""
|
||||
启动链式任务
|
||||
"""
|
||||
WebhookMessageChain().process(body=body, form=form, args=args)
|
||||
WebhookChain().message(body=body, form=form, args=args)
|
||||
|
||||
|
||||
@router.post("/", response_model=schemas.Response)
|
||||
async def webhook_message(background_tasks: BackgroundTasks, token: str, request: Request):
|
||||
async def webhook_message(background_tasks: BackgroundTasks,
|
||||
token: str, request: Request) -> Any:
|
||||
"""
|
||||
Webhook响应
|
||||
"""
|
||||
|
@ -4,7 +4,7 @@ from fastapi import APIRouter, HTTPException, Depends
|
||||
from requests import Session
|
||||
|
||||
from app import schemas
|
||||
from app.chain.identify import IdentifyChain
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.subscribe import SubscribeChain
|
||||
from app.core.config import settings
|
||||
from app.core.metainfo import MetaInfo
|
||||
@ -232,11 +232,11 @@ async def arr_movie_lookup(apikey: str, term: str, db: Session = Depends(get_db)
|
||||
)
|
||||
tmdbid = term.replace("tmdb:", "")
|
||||
# 查询媒体信息
|
||||
mediainfo = IdentifyChain().recognize_media(mtype=MediaType.MOVIE, tmdbid=int(tmdbid))
|
||||
mediainfo = MediaChain().recognize_media(mtype=MediaType.MOVIE, tmdbid=int(tmdbid))
|
||||
if not mediainfo:
|
||||
return [RadarrMovie()]
|
||||
# 查询是否已存在
|
||||
exists = IdentifyChain().media_exists(mediainfo=mediainfo)
|
||||
exists = MediaChain().media_exists(mediainfo=mediainfo)
|
||||
if not exists:
|
||||
# 文件不存在
|
||||
hasfile = False
|
||||
@ -311,11 +311,11 @@ async def arr_add_movie(apikey: str, movie: RadarrMovie) -> Any:
|
||||
status_code=403,
|
||||
detail="认证失败!",
|
||||
)
|
||||
sid = SubscribeChain().process(title=movie.title,
|
||||
year=movie.year,
|
||||
mtype=MediaType.MOVIE,
|
||||
tmdbid=movie.tmdbId,
|
||||
userid="Seerr")
|
||||
sid = SubscribeChain().add(title=movie.title,
|
||||
year=movie.year,
|
||||
mtype=MediaType.MOVIE,
|
||||
tmdbid=movie.tmdbId,
|
||||
userid="Seerr")
|
||||
if sid:
|
||||
return {
|
||||
"id": sid
|
||||
@ -501,29 +501,29 @@ async def arr_series_lookup(apikey: str, term: str, db: Session = Depends(get_db
|
||||
)
|
||||
# 查询TMDB媒体信息
|
||||
if not term.startswith("tvdb:"):
|
||||
mediainfo = IdentifyChain().recognize_media(meta=MetaInfo(term),
|
||||
mtype=MediaType.MOVIE)
|
||||
mediainfo = MediaChain().recognize_media(meta=MetaInfo(term),
|
||||
mtype=MediaType.MOVIE)
|
||||
if not mediainfo:
|
||||
return [SonarrSeries()]
|
||||
tvdbid = mediainfo.tvdb_id
|
||||
tmdbid = mediainfo.tmdb_id
|
||||
else:
|
||||
tvdbid = int(term.replace("tvdb:", ""))
|
||||
mediainfo = IdentifyChain().recognize_media(mtype=MediaType.MOVIE,
|
||||
tmdbid=tvdbid)
|
||||
mediainfo = MediaChain().recognize_media(mtype=MediaType.MOVIE,
|
||||
tmdbid=tvdbid)
|
||||
if not mediainfo:
|
||||
return [SonarrSeries()]
|
||||
tmdbid = mediainfo.tmdb_id
|
||||
# 查询TVDB季信息
|
||||
seas: List[int] = []
|
||||
if tvdbid:
|
||||
tvdbinfo = IdentifyChain().tvdb_info(tvdbid=tvdbid)
|
||||
tvdbinfo = MediaChain().tvdb_info(tvdbid=tvdbid)
|
||||
if tvdbinfo:
|
||||
sea_num = tvdbinfo.get('season')
|
||||
if sea_num:
|
||||
seas = list(range(1, int(sea_num) + 1))
|
||||
# 查询是否存在
|
||||
exists = IdentifyChain().media_exists(mediainfo)
|
||||
exists = MediaChain().media_exists(mediainfo)
|
||||
if exists:
|
||||
hasfile = True
|
||||
else:
|
||||
@ -629,12 +629,12 @@ async def arr_add_series(apikey: str, tv: schemas.SonarrSeries) -> Any:
|
||||
for season in tv.seasons:
|
||||
if not season.get("monitored"):
|
||||
continue
|
||||
sid = SubscribeChain().process(title=tv.title,
|
||||
year=tv.year,
|
||||
season=season.get("seasonNumber"),
|
||||
tmdbid=tv.tmdbId,
|
||||
mtype=MediaType.TV,
|
||||
userid="Seerr")
|
||||
sid = SubscribeChain().add(title=tv.title,
|
||||
year=tv.year,
|
||||
season=season.get("seasonNumber"),
|
||||
tmdbid=tv.tmdbId,
|
||||
mtype=MediaType.TV,
|
||||
userid="Seerr")
|
||||
|
||||
if sid:
|
||||
return {
|
||||
|
Reference in New Issue
Block a user