Expose certifications and per-country release dates
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

TMDb's release_dates/content_ratings blocks were already fetched via
append_to_response but discarded at normalization -- every downstream
layer (ingestion write, repository read, schema, service) was unbuilt.
Adds the full pipeline: NormalizedReleaseDate + get_or_create_certification,
a shared polymorphic sync/read (movie and series both use it), and
MovieDetailOut/SeriesDetailOut certification + release_dates fields.

Series content_ratings has no date of its own, so each rating is anchored
to the show's first_air_date with release_type="tv".

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
NixReaper
2026-09-06 04:07:18 -05:00
co-authored by Claude Sonnet 5
parent 340cadd99d
commit e1a36ce227
15 changed files with 510 additions and 5 deletions
+96 -1
View File
@@ -96,6 +96,95 @@ def company_logo_artwork(logo_path: str | None) -> NormalizedArtwork | None:
)
# TMDb's per-country rating body isn't returned alongside a release_dates
# certification or a content_ratings rating -- only the country and the
# rating string itself are. This maps the handful of markets Aurora can
# name with confidence; everywhere else falls back to the country code
# itself (see NormalizedReleaseDate.certification) rather than fabricating
# a body name TMDb never told us.
_CERTIFICATION_SYSTEMS = {
"US": "MPA",
"GB": "BBFC",
"DE": "FSK",
"FR": "CNC",
"JP": "Eirin",
"AU": "ACB",
"CA": "CHVRS",
"KR": "KMRB",
"BR": "ANCINE",
"ES": "ICAA",
"IT": "MiC",
"NZ": "OFLC",
"IE": "IFCO",
"IN": "CBFC",
}
# TMDb's release_dates[].type: 1=Premiere, 2=Theatrical (limited),
# 3=Theatrical, 4=Digital, 5=Physical, 6=TV -- collapsed onto the five
# release_type values ReleaseDate.release_type documents.
_RELEASE_TYPE_MAP = {1: "premiere", 2: "theatrical", 3: "theatrical", 4: "digital", 5: "physical", 6: "tv"}
@dataclass
class NormalizedReleaseDate:
country_code: str
release_date: date
release_type: str | None
certification: tuple[str, str] | None = None # (system, rating)
note: str | None = None
def _movie_release_dates(raw: dict) -> list[NormalizedReleaseDate]:
out: list[NormalizedReleaseDate] = []
for country_block in (raw.get("release_dates") or {}).get("results", []):
country_code = country_block.get("iso_3166_1")
if not country_code:
continue
for entry in country_block.get("release_dates", []):
release_date = _parse_date((entry.get("release_date") or "")[:10] or None)
if release_date is None:
continue
rating = entry.get("certification")
certification = (
(_CERTIFICATION_SYSTEMS.get(country_code, country_code), rating) if rating else None
)
out.append(
NormalizedReleaseDate(
country_code=country_code,
release_date=release_date,
release_type=_RELEASE_TYPE_MAP.get(entry.get("type")),
certification=certification,
note=entry.get("note") or None,
)
)
return out
def _series_release_dates(raw: dict, first_air_date: date | None) -> list[NormalizedReleaseDate]:
# Unlike /movie's release_dates, TMDb's /tv content_ratings has no date
# at all -- just a country and a rating. ReleaseDate.release_date is
# required, so each rating is anchored to the show's own first_air_date
# (release_type="tv") rather than left dateless; a show with no
# first_air_date yet has nothing to anchor to and is skipped.
if first_air_date is None:
return []
out: list[NormalizedReleaseDate] = []
for entry in (raw.get("content_ratings") or {}).get("results", []):
country_code = entry.get("iso_3166_1")
rating = entry.get("rating")
if not country_code or not rating:
continue
out.append(
NormalizedReleaseDate(
country_code=country_code,
release_date=first_air_date,
release_type="tv",
certification=(_CERTIFICATION_SYSTEMS.get(country_code, country_code), rating),
)
)
return out
@dataclass
class NormalizedVideo:
video_type: str
@@ -136,6 +225,7 @@ class NormalizedMovie:
external_ids: dict[str, str] = field(default_factory=dict)
collection: tuple[str, str] | None = None # (external_id, name)
recommendation_external_ids: list[str] = field(default_factory=list)
release_dates: list[NormalizedReleaseDate] = field(default_factory=list)
@dataclass
@@ -338,6 +428,7 @@ def normalize_movie(raw: dict) -> NormalizedMovie:
external_ids=external_ids,
collection=(str(collection["id"]), collection["name"]) if collection else None,
recommendation_external_ids=[str(m["id"]) for m in recommendations],
release_dates=_movie_release_dates(raw),
)
@@ -486,6 +577,7 @@ class NormalizedSeries:
videos: list[NormalizedVideo] = field(default_factory=list)
external_ids: dict[str, str] = field(default_factory=dict)
seasons: list[NormalizedSeasonStub] = field(default_factory=list)
release_dates: list[NormalizedReleaseDate] = field(default_factory=list)
def normalize_series(raw: dict) -> NormalizedSeries:
@@ -637,6 +729,8 @@ def normalize_series(raw: dict) -> NormalizedSeries:
if s.get("season_number") is not None
]
first_air_date = _parse_date(raw.get("first_air_date"))
return NormalizedSeries(
external_id=str(raw["id"]),
title=raw.get("name") or raw.get("original_name") or "",
@@ -645,7 +739,7 @@ def normalize_series(raw: dict) -> NormalizedSeries:
tagline=raw.get("tagline") or None,
status=_SERIES_STATUS_MAP.get(raw.get("status", "Returning Series"), "returning_series"),
original_language=raw.get("original_language"),
first_air_date=_parse_date(raw.get("first_air_date")),
first_air_date=first_air_date,
last_air_date=_parse_date(raw.get("last_air_date")),
number_of_seasons=raw.get("number_of_seasons"),
number_of_episodes=raw.get("number_of_episodes"),
@@ -664,6 +758,7 @@ def normalize_series(raw: dict) -> NormalizedSeries:
videos=normalized_videos,
external_ids=external_ids,
seasons=seasons,
release_dates=_series_release_dates(raw, first_air_date),
)