CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Production-grade media metadata backend per docs/aurora-core-spec.md: Aurora-owned UUIDv7 identity system, normalized movie/TV/people/credits schema, provider abstraction with a TMDb adapter, an idempotent async ingestion pipeline (normalize -> match -> upsert -> provenance), a Postgres FTS/trigram search layer, a stateless FastAPI v1 API with Redis caching/rate-limiting, arq workers, dev/prod Docker Compose topologies, unit + integration + load tests, CI, and architecture/ database/API/ERD documentation. Co-Authored-By: Claude Sonnet 5 <[email protected]>
106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
"""Shared helpers for turning ORM rows into response schemas."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.core.ids import aurora_id
|
|
from app.models.artwork import Artwork
|
|
from app.models.credit import Credit
|
|
from app.models.enums import ArtworkType
|
|
from app.models.video import Video
|
|
from app.schemas.common import (
|
|
ArtworkOut,
|
|
CastCreditOut,
|
|
CrewCreditOut,
|
|
ImagesOut,
|
|
PersonBriefOut,
|
|
VideoOut,
|
|
)
|
|
|
|
|
|
def artwork_url(artwork: Artwork) -> str:
|
|
return artwork.local_path or artwork.original_url
|
|
|
|
|
|
def to_artwork_out(artwork: Artwork) -> ArtworkOut:
|
|
return ArtworkOut(
|
|
id=aurora_id("artwork", str(artwork.id)),
|
|
type=artwork.artwork_type.value,
|
|
language=artwork.language_code,
|
|
width=artwork.width,
|
|
height=artwork.height,
|
|
aspect_ratio=artwork.aspect_ratio,
|
|
url=artwork_url(artwork),
|
|
provider=artwork.provider.slug if artwork.provider else None,
|
|
is_primary=artwork.is_primary,
|
|
vote_average=artwork.vote_average,
|
|
)
|
|
|
|
|
|
def to_images_out(artwork_list: list[Artwork]) -> ImagesOut:
|
|
images = ImagesOut()
|
|
for artwork in artwork_list:
|
|
out = to_artwork_out(artwork)
|
|
if artwork.artwork_type == ArtworkType.POSTER:
|
|
images.posters.append(out)
|
|
elif artwork.artwork_type == ArtworkType.BACKDROP:
|
|
images.backdrops.append(out)
|
|
elif artwork.artwork_type == ArtworkType.LOGO:
|
|
images.logos.append(out)
|
|
return images
|
|
|
|
|
|
def primary_artwork_path(artwork_list: list[Artwork], artwork_type: ArtworkType) -> str | None:
|
|
for artwork in artwork_list:
|
|
if artwork.artwork_type == artwork_type:
|
|
return artwork_url(artwork)
|
|
return None
|
|
|
|
|
|
def to_video_out(video: Video) -> VideoOut:
|
|
return VideoOut(
|
|
id=aurora_id("video", str(video.id)),
|
|
type=video.video_type.value,
|
|
site=video.site,
|
|
url=video.url,
|
|
language=video.language_code,
|
|
country=video.country_code,
|
|
is_official=video.is_official,
|
|
published_at=video.published_at,
|
|
provider=video.provider.slug if video.provider else None,
|
|
)
|
|
|
|
|
|
def split_credits(
|
|
credits_: list[Credit], profile_paths: dict | None = None
|
|
) -> tuple[list[CastCreditOut], list[CrewCreditOut]]:
|
|
profile_paths = profile_paths or {}
|
|
cast: list[CastCreditOut] = []
|
|
crew: list[CrewCreditOut] = []
|
|
for credit in credits_:
|
|
person_brief = PersonBriefOut(
|
|
id=aurora_id("person", str(credit.person_id)),
|
|
name=credit.person.name,
|
|
profile_path=profile_paths.get(credit.person_id),
|
|
)
|
|
if credit.department == "Acting":
|
|
cast.append(
|
|
CastCreditOut(
|
|
id=aurora_id("credit", str(credit.id)),
|
|
person=person_brief,
|
|
character=credit.character,
|
|
billing_order=credit.billing_order,
|
|
episode_count=credit.episode_count,
|
|
)
|
|
)
|
|
else:
|
|
crew.append(
|
|
CrewCreditOut(
|
|
id=aurora_id("credit", str(credit.id)),
|
|
person=person_brief,
|
|
department=credit.department,
|
|
job=credit.job,
|
|
episode_count=credit.episode_count,
|
|
)
|
|
)
|
|
return cast, crew
|