37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends, Query
|
|
from fastapi.templating import Jinja2Templates
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from ..core.authx import auth
|
|
from ..core.config import TEMPLATES_DIR
|
|
from ..core.db import get_db
|
|
from ..models.video_model import Video
|
|
from ..schemas.playlist_schema import PlaylistOut
|
|
|
|
router = APIRouter()
|
|
templates = Jinja2Templates(directory=TEMPLATES_DIR)
|
|
|
|
|
|
@router.get("/playlist", response_model=PlaylistOut, dependencies=[Depends(auth.access_token_required)])
|
|
async def playlist(session: AsyncSession = Depends(get_db), id: int = Query(...)): # noqa: B008
|
|
query = select(Video).where(Video.playlist_id == id)
|
|
result = await session.execute(query)
|
|
|
|
videos = result.scalars().all()
|
|
|
|
return {
|
|
"videos": [
|
|
{
|
|
"id": v.id,
|
|
"title": getattr(v, "title", None),
|
|
"path": v.path,
|
|
"preview_path": v.preview_path,
|
|
"date": v.date,
|
|
"channel_id": v.channel_id,
|
|
}
|
|
for v in videos
|
|
],
|
|
"video_count": len(videos),
|
|
}
|