Add series/season/episode ingestion pipeline
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
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
Movie and person ingestion existed, but the series/season/episode API
endpoints had no way to actually populate them from TMDb -- the
biggest remaining gap in Core 0.1's television scope.
- normalize_series/normalize_season in the metadata normalizer,
including two TMDb quirks that would otherwise silently produce
empty data: /tv nests keywords and alternative_titles under
"results" (not "keywords"/"titles" like /movie), and series-level
creators come from a separate created_by array, not the credits
cast/crew lists.
- ingest_series upserts the Series row plus season *stubs* (number,
title, air date, poster -- everything TMDb inlines on /tv/{id});
ingest_season fetches and upserts one season's full episode list,
and requires the series to already exist (TMDb has no single
endpoint for a whole series' episodes, so this has to be a separate
per-season call).
- Wired through the same job-lifecycle path as movie/person ingestion
(runner.py, arq tasks, admin endpoints), with the shared boilerplate
between them factored into runner._run_ingestion and
admin.py:_enqueue rather than copy-pasted a third and fourth time.
- Unit tests for both normalizers (runnable without a DB) and
integration tests for the full ingest_series -> ingest_season flow,
including the series-must-exist-first error and idempotency on
re-ingestion.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
669034896a
commit
3f6332559a
@@ -19,6 +19,60 @@ async def get_series_by_id(session: AsyncSession, series_id: uuid.UUID) -> Serie
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_season_by_number(
|
||||
session: AsyncSession, series_id: uuid.UUID, season_number: int
|
||||
) -> Season | None:
|
||||
stmt = select(Season).where(
|
||||
Season.series_id == series_id, Season.season_number == season_number
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_or_create_season(
|
||||
session: AsyncSession, series_id: uuid.UUID, season_number: int
|
||||
) -> Season:
|
||||
season = await get_season_by_number(session, series_id, season_number)
|
||||
if season is not None:
|
||||
return season
|
||||
season = Season(series_id=series_id, season_number=season_number)
|
||||
session.add(season)
|
||||
await session.flush()
|
||||
return season
|
||||
|
||||
|
||||
async def get_episode_by_number(
|
||||
session: AsyncSession, season_id: uuid.UUID, episode_number: int
|
||||
) -> Episode | None:
|
||||
stmt = select(Episode).where(
|
||||
Episode.season_id == season_id, Episode.episode_number == episode_number
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_or_create_episode(
|
||||
session: AsyncSession,
|
||||
*,
|
||||
series_id: uuid.UUID,
|
||||
season_id: uuid.UUID,
|
||||
season_number: int,
|
||||
episode_number: int,
|
||||
) -> Episode:
|
||||
episode = await get_episode_by_number(session, season_id, episode_number)
|
||||
if episode is not None:
|
||||
return episode
|
||||
episode = Episode(
|
||||
series_id=series_id,
|
||||
season_id=season_id,
|
||||
season_number=season_number,
|
||||
episode_number=episode_number,
|
||||
)
|
||||
session.add(episode)
|
||||
await session.flush()
|
||||
return episode
|
||||
|
||||
|
||||
async def get_seasons_for_series(session: AsyncSession, series_id: uuid.UUID) -> list[Season]:
|
||||
stmt = (
|
||||
select(Season)
|
||||
|
||||
Reference in New Issue
Block a user