update
This commit is contained in:
@@ -1,54 +1,18 @@
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from api.schemas import CleanupRequest, VideoCreate, VideoResponse
|
||||
from database.database import getDb
|
||||
from database.database import DbSession
|
||||
from download.download_service import downloadAsync
|
||||
from model.video import Video
|
||||
from notify.notify_clients import notifyClients
|
||||
from stream.stream_service import streamAndSave
|
||||
|
||||
router = APIRouter(prefix="/videos", tags=["videos"])
|
||||
|
||||
|
||||
@router.post("", status_code=204)
|
||||
async def create(videoData: VideoCreate, db: Session = Depends(getDb)):
|
||||
title = videoData.title
|
||||
youtuber = videoData.youtuber
|
||||
thumbnailUrl = videoData.thumbnailUrl
|
||||
youtubeUrl = videoData.youtubeUrl
|
||||
profileId = videoData.profileId
|
||||
|
||||
Video.deleteIfExists(db, youtubeUrl, profileId)
|
||||
Video.create(db, title, youtuber, thumbnailUrl, youtubeUrl, profileId)
|
||||
await notifyClients(profileId)
|
||||
|
||||
|
||||
@router.get("", response_model=list[VideoResponse])
|
||||
def getAll(profileId: Optional[int] = Query(None), db: Session = Depends(getDb)):
|
||||
return Video.getAll(db, profileId=profileId)
|
||||
|
||||
|
||||
@router.get("/downloaded", response_model=list[VideoResponse])
|
||||
def getDownloaded(profileId: Optional[int] = Query(None), db: Session = Depends(getDb)):
|
||||
return Video.getDownloaded(db, profileId=profileId)
|
||||
|
||||
|
||||
@router.post("/cleanup")
|
||||
def cleanup(request: CleanupRequest, db: Session = Depends(getDb)):
|
||||
profileId = request.profileId
|
||||
excludeIds = request.excludeIds
|
||||
|
||||
count = Video.deleteNotDownloaded(db, profileId, excludeIds)
|
||||
return {"deleted": count}
|
||||
router = APIRouter(prefix="/videos")
|
||||
|
||||
|
||||
@router.post("/{videoId}/download")
|
||||
def download(videoId: int, db: Session = Depends(getDb)):
|
||||
def download(videoId: int, db: DbSession):
|
||||
video = Video.getById(db, videoId)
|
||||
if not video:
|
||||
raise HTTPException(404, "Video nicht gefunden")
|
||||
@@ -60,7 +24,7 @@ def download(videoId: int, db: Session = Depends(getDb)):
|
||||
|
||||
|
||||
@router.get("/{videoId}/stream")
|
||||
def stream(videoId: int, db: Session = Depends(getDb)):
|
||||
def stream(videoId: int, db: DbSession):
|
||||
video = Video.getById(db, videoId)
|
||||
if not video:
|
||||
raise HTTPException(404, "Video nicht gefunden")
|
||||
@@ -75,7 +39,7 @@ def stream(videoId: int, db: Session = Depends(getDb)):
|
||||
|
||||
|
||||
@router.get("/{videoId}/file")
|
||||
def getFile(videoId: int, db: Session = Depends(getDb)):
|
||||
def getFile(videoId: int, db: DbSession):
|
||||
path, video = Video.getValidPath(db, videoId)
|
||||
if not path:
|
||||
raise HTTPException(404, "Video noch nicht heruntergeladen")
|
||||
@@ -83,7 +47,7 @@ def getFile(videoId: int, db: Session = Depends(getDb)):
|
||||
|
||||
|
||||
@router.delete("/{videoId}/file")
|
||||
def deleteFile(videoId: int, db: Session = Depends(getDb)):
|
||||
def deleteFile(videoId: int, db: DbSession):
|
||||
if not Video.deleteServerFile(db, videoId):
|
||||
raise HTTPException(404, "Video nicht gefunden")
|
||||
return {"status": "deleted"}
|
||||
|
||||
Reference in New Issue
Block a user