archive-backend/schemas/playlist_schema.py
2026-11-07 11:40:36 +00:00

37 lines
883 B
Python

from datetime import date as DateType
from urllib.parse import quote
from pydantic import BaseModel, field_validator
def encode_path(path: str) -> str:
if not path:
return ""
return "/".join(quote(part, safe="") for part in path.split("/"))
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