archive-backend/schemas/playlist_schema.py
2026-11-07 19:35:15 +00:00

32 lines
749 B
Python

from datetime import date as DateType
from pydantic import BaseModel, field_validator
from services.path import encode_path
class VideoItem(BaseModel):
id: int
title: str
path: str
preview_path: str | None = None
date: DateType | None = None
channel_id: int
@field_validator("path", "preview_path", mode="before")
@classmethod
def encode_urls(cls, v):
return encode_path(v)
@field_validator("path", mode="after")
@classmethod
def add_yt(cls, v: str) -> str:
if not v: return v
clean_v = v.lstrip('/')
if clean_v.startswith('yt/'): return f"/{clean_v}"
return f"yt/{clean_v}"
class PlaylistOut(BaseModel):
videos: list[VideoItem]
video_count: int