50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from fastapi.responses import FileResponse
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database import get_db
|
|
from app.models import Clip
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/clips/{clip_id}")
|
|
async def get_clip(clip_id: UUID, db: AsyncSession = Depends(get_db)):
|
|
clip = await db.get(Clip, clip_id)
|
|
if not clip:
|
|
raise HTTPException(404, "Clip not found")
|
|
clip.duration = clip.end_time - clip.start_time
|
|
return clip
|
|
|
|
|
|
@router.get("/clips/{clip_id}/preview")
|
|
async def preview_clip(clip_id: UUID, db: AsyncSession = Depends(get_db)):
|
|
clip = await db.get(Clip, clip_id)
|
|
if not clip:
|
|
raise HTTPException(404, "Clip not found")
|
|
if not clip.raw_clip_path:
|
|
raise HTTPException(404, "Clip not yet extracted")
|
|
|
|
return FileResponse(
|
|
clip.raw_clip_path,
|
|
media_type="video/mp4",
|
|
content_disposition_type="inline",
|
|
)
|
|
|
|
|
|
@router.get("/clips/{clip_id}/download")
|
|
async def download_clip(clip_id: UUID, db: AsyncSession = Depends(get_db)):
|
|
clip = await db.get(Clip, clip_id)
|
|
if not clip:
|
|
raise HTTPException(404, "Clip not found")
|
|
if not clip.raw_clip_path:
|
|
raise HTTPException(404, "Clip not yet extracted")
|
|
|
|
return FileResponse(
|
|
clip.raw_clip_path,
|
|
media_type="video/mp4",
|
|
filename=f"{clip.title}.mp4",
|
|
)
|