fix schemas
This commit is contained in:
parent
39165a92f0
commit
9ccb2b482e
@ -38,7 +38,12 @@ async def login_access_token(
|
|||||||
raise HTTPException(status_code=401, detail="用户名或密码不正确")
|
raise HTTPException(status_code=401, detail="用户名或密码不正确")
|
||||||
else:
|
else:
|
||||||
logger.info(f"辅助认证成功,用户信息: {token}")
|
logger.info(f"辅助认证成功,用户信息: {token}")
|
||||||
user = schemas.User(id=-1, name=form_data.username, is_active=True, is_superuser=False)
|
# 加入用户信息表
|
||||||
|
user = User.get_by_name(db=db, name=form_data.username)
|
||||||
|
if not user:
|
||||||
|
logger.info(f"用户不存在,创建用户: {form_data.username}")
|
||||||
|
user = User(name=form_data.username, is_active=True, is_superuser=False)
|
||||||
|
user.create(db)
|
||||||
elif not user.is_active:
|
elif not user.is_active:
|
||||||
raise HTTPException(status_code=403, detail="用户未启用")
|
raise HTTPException(status_code=403, detail="用户未启用")
|
||||||
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||||
|
@ -1,33 +1,47 @@
|
|||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
from app import schemas
|
from app import schemas
|
||||||
|
from app.chain.douban import DoubanChain
|
||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
|
from app.core.context import Context
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/tmdbid", summary="精确搜索资源", response_model=List[schemas.Context])
|
@router.get("/media/{mediaid}", summary="精确搜索资源", response_model=List[schemas.Context])
|
||||||
async def search_by_tmdbid(tmdbid: int,
|
async def search_by_tmdbid(mediaid: str,
|
||||||
mtype: str = None,
|
mtype: str = None,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据TMDBID精确搜索站点资源
|
根据TMDBID/豆瓣ID精确搜索站点资源 tmdb:/douban:/
|
||||||
"""
|
"""
|
||||||
if mtype:
|
if mediaid.startswith("tmdb:"):
|
||||||
mtype = MediaType.TV if mtype == MediaType.TV.value else MediaType.MOVIE
|
tmdbid = int(mediaid.replace("tmdb:", ""))
|
||||||
torrents = SearchChain().search_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
|
if mtype:
|
||||||
|
mtype = MediaType(mtype)
|
||||||
|
torrents = SearchChain().search_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
|
||||||
|
elif mediaid.startswith("douban:"):
|
||||||
|
doubanid = mediaid.replace("douban:", "")
|
||||||
|
# 识别豆瓣信息
|
||||||
|
context = DoubanChain().recognize_by_doubanid(doubanid)
|
||||||
|
if not context or not context.media_info or not context.media_info.tmdb_id:
|
||||||
|
raise HTTPException(status_code=404, detail="无法识别TMDB媒体信息!")
|
||||||
|
torrents = SearchChain().search_by_tmdbid(tmdbid=context.media_info.tmdb_id,
|
||||||
|
mtype=context.media_info.type)
|
||||||
|
else:
|
||||||
|
return []
|
||||||
return [torrent.to_dict() for torrent in torrents]
|
return [torrent.to_dict() for torrent in torrents]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/title", summary="模糊搜索资源", response_model=List[schemas.TorrentInfo])
|
@router.get("/title/{keyword}", summary="模糊搜索资源", response_model=List[schemas.Context])
|
||||||
async def search_by_title(title: str,
|
async def search_by_title(keyword: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据名称模糊搜索站点资源
|
根据名称模糊搜索站点资源
|
||||||
"""
|
"""
|
||||||
torrents = SearchChain().search_by_title(title=title)
|
torrents = SearchChain().search_by_title(title=keyword)
|
||||||
return [torrent.to_dict() for torrent in torrents]
|
return [Context(torrent_info=torrent).to_dict() for torrent in torrents]
|
||||||
|
@ -26,7 +26,7 @@ class SearchChain(ChainBase):
|
|||||||
self.siteshelper = SitesHelper()
|
self.siteshelper = SitesHelper()
|
||||||
self.progress = ProgressHelper()
|
self.progress = ProgressHelper()
|
||||||
|
|
||||||
def search_by_tmdbid(self, tmdbid: int, mtype: str = None) -> Optional[List[Context]]:
|
def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]:
|
||||||
"""
|
"""
|
||||||
根据TMDB ID搜索资源,精确匹配,但不不过滤本地存在的资源
|
根据TMDB ID搜索资源,精确匹配,但不不过滤本地存在的资源
|
||||||
:param tmdbid: TMDB ID
|
:param tmdbid: TMDB ID
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
from typing import Union, Optional, List
|
from typing import Union, Optional, List
|
||||||
|
|
||||||
import cn2an
|
import cn2an
|
||||||
@ -7,6 +8,7 @@ from app.utils.string import StringUtils
|
|||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class MetaBase(object):
|
class MetaBase(object):
|
||||||
"""
|
"""
|
||||||
媒体信息基类
|
媒体信息基类
|
||||||
|
@ -83,42 +83,42 @@ class MediaInfo(BaseModel):
|
|||||||
# 海报图片
|
# 海报图片
|
||||||
poster_path: Optional[str] = None
|
poster_path: Optional[str] = None
|
||||||
# 评分
|
# 评分
|
||||||
vote_average: int = 0
|
vote_average: Optional[int] = 0
|
||||||
# 描述
|
# 描述
|
||||||
overview: Optional[str] = None
|
overview: Optional[str] = None
|
||||||
# 二级分类
|
# 二级分类
|
||||||
category: str = ""
|
category: Optional[str] = ""
|
||||||
# 季季集清单
|
# 季季集清单
|
||||||
seasons: Dict[int, list] = {}
|
seasons: Dict[int, list] = {}
|
||||||
# 季详情
|
# 季详情
|
||||||
season_info: List[dict] = []
|
season_info: List[dict] = []
|
||||||
# 别名和译名
|
# 别名和译名
|
||||||
names: list = []
|
names: Optional[list] = []
|
||||||
# 演员
|
# 演员
|
||||||
actors: list = []
|
actors: Optional[list] = []
|
||||||
# 导演
|
# 导演
|
||||||
directors: list = []
|
directors: Optional[list] = []
|
||||||
# 其它TMDB属性
|
# 其它TMDB属性
|
||||||
adult: bool = False
|
adult: Optional[bool] = False
|
||||||
created_by: list = []
|
created_by: Optional[list] = []
|
||||||
episode_run_time: list = []
|
episode_run_time: Optional[list] = []
|
||||||
genres: list = []
|
genres: Optional[list] = []
|
||||||
first_air_date: Optional[str] = None
|
first_air_date: Optional[str] = None
|
||||||
homepage: Optional[str] = None
|
homepage: Optional[str] = None
|
||||||
languages: list = []
|
languages: Optional[list] = []
|
||||||
last_air_date: Optional[str] = None
|
last_air_date: Optional[str] = None
|
||||||
networks: list = []
|
networks: Optional[list] = []
|
||||||
number_of_episodes: int = 0
|
number_of_episodes: Optional[int] = 0
|
||||||
number_of_seasons: int = 0
|
number_of_seasons: Optional[int] = 0
|
||||||
origin_country: list = []
|
origin_country: Optional[list] = []
|
||||||
original_name: Optional[str] = None
|
original_name: Optional[str] = None
|
||||||
production_companies: list = []
|
production_companies: Optional[list] = []
|
||||||
production_countries: list = []
|
production_countries: Optional[list] = []
|
||||||
spoken_languages: list = []
|
spoken_languages: Optional[list] = []
|
||||||
status: Optional[str] = None
|
status: Optional[str] = None
|
||||||
tagline: Optional[str] = None
|
tagline: Optional[str] = None
|
||||||
vote_count: int = 0
|
vote_count: Optional[int] = 0
|
||||||
popularity: int = 0
|
popularity: Optional[int] = 0
|
||||||
runtime: Optional[int] = None
|
runtime: Optional[int] = None
|
||||||
next_episode_to_air: Optional[str] = None
|
next_episode_to_air: Optional[str] = None
|
||||||
|
|
||||||
@ -136,27 +136,27 @@ class TorrentInfo(BaseModel):
|
|||||||
# 站点UA
|
# 站点UA
|
||||||
site_ua: Optional[str] = None
|
site_ua: Optional[str] = None
|
||||||
# 站点是否使用代理
|
# 站点是否使用代理
|
||||||
site_proxy: bool = False
|
site_proxy: Optional[bool] = False
|
||||||
# 站点优先级
|
# 站点优先级
|
||||||
site_order: int = 0
|
site_order: Optional[int] = 0
|
||||||
# 种子名称
|
# 种子名称
|
||||||
title: Optional[str] = None
|
title: Optional[str] = None
|
||||||
# 种子副标题
|
# 种子副标题
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
# IMDB ID
|
# IMDB ID
|
||||||
imdbid: str = None
|
imdbid: Optional[str] = None
|
||||||
# 种子链接
|
# 种子链接
|
||||||
enclosure: Optional[str] = None
|
enclosure: Optional[str] = None
|
||||||
# 详情页面
|
# 详情页面
|
||||||
page_url: Optional[str] = None
|
page_url: Optional[str] = None
|
||||||
# 种子大小
|
# 种子大小
|
||||||
size: float = 0
|
size: Optional[float] = 0
|
||||||
# 做种者
|
# 做种者
|
||||||
seeders: int = 0
|
seeders: Optional[int] = 0
|
||||||
# 下载者
|
# 下载者
|
||||||
peers: int = 0
|
peers: Optional[int] = 0
|
||||||
# 完成者
|
# 完成者
|
||||||
grabs: int = 0
|
grabs: Optional[int] = 0
|
||||||
# 发布时间
|
# 发布时间
|
||||||
pubdate: Optional[str] = None
|
pubdate: Optional[str] = None
|
||||||
# 已过时间
|
# 已过时间
|
||||||
@ -166,11 +166,11 @@ class TorrentInfo(BaseModel):
|
|||||||
# 下载因子
|
# 下载因子
|
||||||
downloadvolumefactor: Optional[float] = None
|
downloadvolumefactor: Optional[float] = None
|
||||||
# HR
|
# HR
|
||||||
hit_and_run: bool = False
|
hit_and_run: Optional[bool] = False
|
||||||
# 种子标签
|
# 种子标签
|
||||||
labels: Optional[list] = []
|
labels: Optional[list] = []
|
||||||
# 种子优先级
|
# 种子优先级
|
||||||
pri_order: int = 0
|
pri_order: Optional[int] = 0
|
||||||
|
|
||||||
|
|
||||||
class Context(BaseModel):
|
class Context(BaseModel):
|
||||||
@ -178,11 +178,11 @@ class Context(BaseModel):
|
|||||||
上下文
|
上下文
|
||||||
"""
|
"""
|
||||||
# 元数据
|
# 元数据
|
||||||
meta_info: Optional[MetaInfo]
|
meta_info: Optional[MetaInfo] = None
|
||||||
# 媒体信息
|
# 媒体信息
|
||||||
media_info: Optional[MediaInfo]
|
media_info: Optional[MediaInfo] = None
|
||||||
# 种子信息
|
# 种子信息
|
||||||
torrent_info: Optional[TorrentInfo]
|
torrent_info: Optional[TorrentInfo] = None
|
||||||
|
|
||||||
|
|
||||||
class TransferTorrent(BaseModel):
|
class TransferTorrent(BaseModel):
|
||||||
@ -221,11 +221,11 @@ class TransferInfo(BaseModel):
|
|||||||
# 转移后路径
|
# 转移后路径
|
||||||
target_path: Optional[Path] = None
|
target_path: Optional[Path] = None
|
||||||
# 处理文件数
|
# 处理文件数
|
||||||
file_count: int = 0
|
file_count: Optional[int] = 0
|
||||||
# 总文件大小
|
# 总文件大小
|
||||||
total_size: float = 0
|
total_size: Optional[float] = 0
|
||||||
# 失败清单
|
# 失败清单
|
||||||
fail_list: list = []
|
fail_list: Optional[list] = []
|
||||||
# 错误信息
|
# 错误信息
|
||||||
message: Optional[str] = None
|
message: Optional[str] = None
|
||||||
|
|
||||||
@ -235,9 +235,9 @@ class ExistMediaInfo(BaseModel):
|
|||||||
媒体服务器存在媒体信息
|
媒体服务器存在媒体信息
|
||||||
"""
|
"""
|
||||||
# 类型 电影、电视剧
|
# 类型 电影、电视剧
|
||||||
type: MediaType
|
type: Optional[MediaType]
|
||||||
# 季
|
# 季
|
||||||
seasons: Dict[int, list] = {}
|
seasons: Optional[Dict[int, list]] = {}
|
||||||
|
|
||||||
|
|
||||||
class NotExistMediaInfo(BaseModel):
|
class NotExistMediaInfo(BaseModel):
|
||||||
@ -259,7 +259,7 @@ class RefreshMediaItem(BaseModel):
|
|||||||
媒体库刷新信息
|
媒体库刷新信息
|
||||||
"""
|
"""
|
||||||
# 标题
|
# 标题
|
||||||
title: str
|
title: Optional[str] = None
|
||||||
# 年份
|
# 年份
|
||||||
year: Optional[str] = None
|
year: Optional[str] = None
|
||||||
# 类型
|
# 类型
|
||||||
|
Loading…
x
Reference in New Issue
Block a user