"""Videos/trailers as normalized entities (section 11). Aurora never downloads copyrighted video media — only stores the provider's reference/URL and metadata about it. """ from __future__ import annotations import uuid from datetime import date from sqlalchemy import Boolean, Date, ForeignKey, Index, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin from app.models.enums import VideoType from app.models.provider import Provider class Video(Base, UUIDPrimaryKeyMixin, TimestampMixin): __tablename__ = "videos" __table_args__ = ( Index("ix_videos_entity", "entity_type", "entity_id"), UniqueConstraint("provider_id", "provider_video_id", name="uq_video_provider_source"), ) # Polymorphic target: "movie", "series", "season", "episode". entity_type: Mapped[str] = mapped_column(String(30), nullable=False) entity_id: Mapped[uuid.UUID] = mapped_column(nullable=False) video_type: Mapped[VideoType] = mapped_column(nullable=False) provider_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("providers.id", ondelete="CASCADE"), nullable=False ) provider_video_id: Mapped[str] = mapped_column(String(200), nullable=False) site: Mapped[str | None] = mapped_column(String(100), nullable=True) # "YouTube", "Vimeo" url: Mapped[str] = mapped_column(String(1000), nullable=False) language_code: Mapped[str | None] = mapped_column( ForeignKey("languages.code"), nullable=True ) country_code: Mapped[str | None] = mapped_column(ForeignKey("countries.code"), nullable=True) is_official: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) published_at: Mapped[date | None] = mapped_column(Date, nullable=True) provider: Mapped[Provider] = relationship() __all__ = ["Video"]