add scrape api
This commit is contained in:
parent
edf8b03d3b
commit
f91763ef7c
@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
@ -6,7 +7,7 @@ from app import schemas
|
|||||||
from app.chain.media import MediaChain
|
from app.chain.media import MediaChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import Context
|
from app.core.context import Context
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo, MetaInfoPath
|
||||||
from app.core.security import verify_token, verify_uri_token
|
from app.core.security import verify_token, verify_uri_token
|
||||||
from app.schemas import MediaType
|
from app.schemas import MediaType
|
||||||
|
|
||||||
@ -76,6 +77,28 @@ def search_by_title(title: str,
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/scrape", summary="刮削媒体信息", response_model=schemas.Response)
|
||||||
|
def scrape(path: str,
|
||||||
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
刮削媒体信息
|
||||||
|
"""
|
||||||
|
if not path:
|
||||||
|
return schemas.Response(success=False, message="刮削路径无效")
|
||||||
|
scrape_path = Path(path)
|
||||||
|
if not scrape_path.exists():
|
||||||
|
return schemas.Response(success=False, message="刮削路径不存在")
|
||||||
|
# 识别
|
||||||
|
chain = MediaChain()
|
||||||
|
meta = MetaInfoPath(scrape_path)
|
||||||
|
mediainfo = chain.recognize_media(meta)
|
||||||
|
if not media_info:
|
||||||
|
return schemas.Response(success=False, message="刮削失败,无法识别媒体信息")
|
||||||
|
# 刮削
|
||||||
|
chain.scrape_metadata(path=scrape_path, mediainfo=mediainfo, transfer_type=settings.TRANSFER_TYPE)
|
||||||
|
return schemas.Response(success=True, message="刮削完成")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
||||||
def media_info(mediaid: str, type_name: str,
|
def media_info(mediaid: str, type_name: str,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user