add media exists api
This commit is contained in:
parent
84acb70ec2
commit
a9dc77ce0c
@ -4,7 +4,10 @@ from fastapi import APIRouter, Depends
|
||||
|
||||
from app import schemas
|
||||
from app.chain.download import DownloadChain
|
||||
from app.core.context import MediaInfo
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.core.security import verify_token
|
||||
from app.schemas import NotExistMediaInfo, MediaType
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -18,6 +21,28 @@ async def read_downloading(
|
||||
return DownloadChain().downloading()
|
||||
|
||||
|
||||
@router.post("/notexists", summary="查询电视剧缺失的剧集", response_model=List[NotExistMediaInfo])
|
||||
async def exists(media_in: schemas.MediaInfo,
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询已存在的媒体信息
|
||||
"""
|
||||
# 媒体信息
|
||||
mediainfo = MediaInfo()
|
||||
mediainfo.from_dict(media_in.dict())
|
||||
# 元数据
|
||||
meta = MetaInfo(title=mediainfo.title)
|
||||
# 查询缺失信息
|
||||
exist_flag, no_exists = DownloadChain().get_no_exists_info(meta=meta, mediainfo=mediainfo)
|
||||
if mediainfo.type == MediaType.MOVIE:
|
||||
# 电影已存在时返回空列表,存在时返回空对像列表
|
||||
return [] if exist_flag else [NotExistMediaInfo()]
|
||||
elif no_exists and no_exists.get(mediainfo.tmdb_id):
|
||||
# 电视剧返回缺失的剧集
|
||||
return list(no_exists.get(mediainfo.tmdb_id).values())
|
||||
return []
|
||||
|
||||
|
||||
@router.put("/{hashString}/start", summary="开始任务", response_model=schemas.Response)
|
||||
async def start_downloading(
|
||||
hashString: str,
|
||||
|
@ -31,5 +31,5 @@ async def search_by_title(title: str,
|
||||
"""
|
||||
_, medias = MediaChain().search(title=title)
|
||||
if medias:
|
||||
return [media.to_dict() for media in medias[(page-1) * count: page * count]]
|
||||
return [media.to_dict() for media in medias[(page - 1) * count: page * count]]
|
||||
return []
|
||||
|
@ -479,6 +479,8 @@ class DownloadChain(ChainBase):
|
||||
if not exists_tvs:
|
||||
# 所有剧集均缺失
|
||||
for season, episodes in mediainfo.seasons.items():
|
||||
if not episodes:
|
||||
continue
|
||||
# 全季不存在
|
||||
if meta.begin_season \
|
||||
and season not in meta.season_list:
|
||||
@ -494,12 +496,12 @@ class DownloadChain(ChainBase):
|
||||
exist_seasons = exists_tvs.seasons
|
||||
if exist_seasons.get(season):
|
||||
# 取差集
|
||||
episodes = list(set(episodes).difference(set(exist_seasons[season])))
|
||||
if not episodes:
|
||||
lack_episodes = list(set(episodes).difference(set(exist_seasons[season])))
|
||||
if not lack_episodes:
|
||||
# 全部集存在
|
||||
continue
|
||||
# 添加不存在的季集信息
|
||||
__append_no_exists(_season=season, _episodes=episodes,
|
||||
__append_no_exists(_season=season, _episodes=lack_episodes,
|
||||
_total=len(episodes), _start=min(episodes))
|
||||
else:
|
||||
# 全季不存在
|
||||
@ -507,7 +509,7 @@ class DownloadChain(ChainBase):
|
||||
_total=len(episodes), _start=min(episodes))
|
||||
# 存在不完整的剧集
|
||||
if no_exists:
|
||||
logger.info(f"媒体库中已存在部分剧集,缺失:{no_exists}")
|
||||
logger.debug(f"媒体库中已存在部分剧集,缺失:{no_exists}")
|
||||
return False, no_exists
|
||||
# 全部存在
|
||||
return True, no_exists
|
||||
|
@ -21,8 +21,8 @@ class Settings(BaseSettings):
|
||||
HOST: str = "0.0.0.0"
|
||||
# API监听端口
|
||||
PORT: int = 3001
|
||||
# 是否自动重载
|
||||
RELOAD: bool = False
|
||||
# 是否调试模式
|
||||
DEBUG: bool = False
|
||||
# 配置文件目录
|
||||
CONFIG_DIR: str = None
|
||||
# 超级管理员
|
||||
|
@ -173,6 +173,19 @@ class MediaInfo:
|
||||
def __setattr__(self, name: str, value: Any):
|
||||
self.__dict__[name] = value
|
||||
|
||||
def from_dict(self, data: dict):
|
||||
"""
|
||||
从字典中初始化
|
||||
"""
|
||||
for key, value in data.items():
|
||||
if key == "type":
|
||||
if value == MediaType.MOVIE.value:
|
||||
setattr(self, key, MediaType.MOVIE)
|
||||
elif value == MediaType.TV.value:
|
||||
setattr(self, key, MediaType.TV)
|
||||
continue
|
||||
setattr(self, key, value)
|
||||
|
||||
def set_image(self, name: str, image: str):
|
||||
"""
|
||||
设置图片地址
|
||||
|
@ -26,7 +26,7 @@ App.add_middleware(
|
||||
)
|
||||
|
||||
# uvicorn服务
|
||||
Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT, reload=settings.RELOAD))
|
||||
Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT, reload=settings.DEBUG))
|
||||
|
||||
|
||||
def init_routers():
|
||||
|
@ -37,6 +37,9 @@ class Scheduler(metaclass=Singleton):
|
||||
})
|
||||
|
||||
def __init__(self):
|
||||
# 调试模式不启动定时服务
|
||||
if settings.DEBUG:
|
||||
return
|
||||
# CookieCloud定时同步
|
||||
if settings.COOKIECLOUD_INTERVAL:
|
||||
self._scheduler.add_job(CookieCloudChain().process,
|
||||
|
@ -245,13 +245,13 @@ class NotExistMediaInfo(BaseModel):
|
||||
媒体服务器不存在媒体信息
|
||||
"""
|
||||
# 季
|
||||
season: int
|
||||
season: Optional[int] = None
|
||||
# 剧集列表
|
||||
episodes: list = []
|
||||
episodes: Optional[list] = []
|
||||
# 总集数
|
||||
total_episodes: int = 0
|
||||
total_episodes: Optional[int] = 0
|
||||
# 开始集
|
||||
start_episode: int = 0
|
||||
start_episode: Optional[int] = 0
|
||||
|
||||
|
||||
class RefreshMediaItem(BaseModel):
|
||||
|
Loading…
x
Reference in New Issue
Block a user