Skip to content

feat(collections): sync MDBList lists of episodes and seasons - #5937

Open
Rhainland wants to merge 44 commits into
Silo-Server:mainfrom
Rhainland:feat/mdblist-episode-lists
Open

Rhainland wants to merge 44 commits into
Silo-Server:mainfrom
Rhainland:feat/mdblist-episode-lists

Conversation

@Rhainland

@Rhainland Rhainland commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #3670
Validation tasks: reaches #193 S3, S5, S6; #194 A1, A5; #195 W1, W5 (title members behave as before)

Other clients: Apple Silo-Server/silo-apple#1366; Android Silo-Server/silo-android#1144; Roku Silo-Server/silo-roku#133; Web in this pull request

A server collection synced from an MDBList list of episodes, such as a list of Christmas episodes, stays empty. MDBList's public feed (/json), which the sync reads, lists nothing for episodes and seasons, so the sync matches no titles and the admin gets no reason. Kometa builds such collections, so users expect it to work.

This change reads those lists through MDBList's API with the server's MDBList key and lets a server collection hold episodes and seasons next to movies and series, on every surface that shows a collection. Without a server key, the admin is told that the list needs one, both while pasting the link and after a sync.

Approach

  • Storage. library_collection_items gets episode_id and season_id columns with their own cascading foreign keys, and a generated member_id that keys the table. Existing rows are titles and need no backfill. A unique index on (collection_id, media_item_id) stays beside the new key so servers of the previous release can keep writing titles during a rolling upgrade. A delete trigger refuses a direct delete of an episode or season member unless the transaction opts in, so a previous-release sync, which would replace a collection by deleting every row without a title, fails and leaves those members alone. This release's member deletes opt in.
  • Sync. When the public feed comes back empty and the server has a key, the sync reads the list's items through the MDBList API, which returns episodes and seasons with their TMDB IDs. Each one is matched within the series the library already has for its show's TMDB ID: by TMDB ID first, then by provider numbers. Episodes not in the library are skipped.
  • Reading. The collection page and catalog, counts, collages, home rows, Shuffle, backup restore and the Jellyfin BoxSet (children and Play all) return episode and season members. A member is visible when the viewer can see its series and its file is in a library they may open. From a library's Movies category a collection lists movies only.
  • Missing key. GET /api/v2/admin/collections/mdblist/link (checkAdminMDBListLink, capability mdblist_link_check) tells the admin editor whether a pasted link needs a key the server lacks. Admin collections and sync runs carry last_sync_reason / reason mdblist_api_key_required, which the web app shows in its own words. The two strings are in feat(web): add MDBList API key notice strings for synced lists silo-translations#236; this branch syncs them from that branch and re-syncs from its release before merge.

Known limits, documented in docs/architecture/collection-members.md: a list that mixes movies or shows with episodes syncs from the feed and leaves its episodes out; personal collections stay titles-only; a library whose episodes have no TMDB IDs (the TVDB plugin) matches episodes by number only; the collection page's filter options come from title members.

Validation

  • Go: build, vet, gofmt, go mod tidy -diff, make lint-changed, make lint-router-recovery and make test-go pass, with the DB tests run against a freshly migrated Postgres. One plugins DB test failed once while other packages shared that database and passes on its own. New DB tests are listed in scripts/ci/db-contracts.txt.
  • Not run locally: verify-actionlint and verify-shellcheck (tools not installed); this change touches no workflow or shell script.
  • Migration: up, down and up again on a fresh database. A DB test runs the previous release's collection writes verbatim against the new schema. Another runs the previous release's replace against title, episode and season members: it fails and all three stay, and the new replace still removes members. TestApplyEpisodeMergesDB now merges two episodes that sit in the same collection.
  • Web: lint, format, build, budget and make test-web pass.
  • Contracts: OpenAPI, web types, fixtures, contract lint and route inventory regenerated and verified.
  • End to end: a local server with a test TV library synced a public list of 1,116 Christmas episodes into 11 matched episodes, in the list's order, and showed them on the collection page, the collections card, Shuffle and the Jellyfin BoxSet. Without a key, the notice, toast, list row and editor alert appear as in the captures.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5937/

Surface and build: web app collection page (desktop and phone), library Collections card, Shuffle, and web admin collection editor (desktop and phone). Before on 835131fe1 (main), after on this branch's head, with the same local test library.

Risks

  • The migration rewrites library_collection_items (a stored generated column) under its lock. The table holds one row per member, small next to the catalog tables.
  • Rolling upgrade: servers of the previous release keep reading and writing title collections, but cannot read a collection that holds episodes or seasons. Only an upgraded server's sync creates one. During that window, a previous-release server's sync of such a collection fails instead of emptying it, and the next upgraded sync repairs it. A later release can drop the trigger.
  • Rolling back the migration deletes every episode and season member.
  • Each sync of an episode list spends MDBList API reads from the server key's daily quota: one per page of items, plus one to resolve an owner-and-slug link.
  • Before merge: feat(web): add MDBList API key notice strings for synced lists silo-translations#236 merges first, then this branch re-syncs translations with --version <release>.
  • User manual: Collections guide: MDBList episode and season lists siloserver.org#506.
  • Merge order with feat(collections): let MDBList lists follow their Custom Order #5933 (Custom order): this branch reads a public list of episodes or seasons through the MDBList API, which keeps MDBList ranking and ignores the link's sort=usort. With Max titles set, ranking also decides which members the collection keeps. The two PRs don't conflict in code. Whichever lands second updates web.collections.syncedList.listOrderHelp to say that private lists and lists of episodes or seasons always come in MDBList ranking. docs/catalog-api.md and docs/architecture/collection-members.md already say this. The manual follow-ups stay in Docs: describe the MDBList order choice for synced lists siloserver.org#505 and FR: Import/Export Home screen configuration #506.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: T3 Code (Claude Code via the Claude Agent SDK)
  • Tool(s): Claude Code; Codex CLI for review
  • Model(s): claude-opus-5-5; gpt-6.2-sol (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews by gpt-6.2-sol (Codex CLI) and claude-opus-5-5 over sixteen rounds, covering correctness, design and blast radius, standards and spec. Findings were fixed (visibility of members in restricted libraries, the watched filter under a series scope, BoxSet season artwork, keyless-sync messaging, rolling-upgrade writes) or recorded above as known limits.

Note

Add episode and season members to MDBList library collection sync

  • Collection members can now be a title, an episode, or a season. The migration makes media_item_id nullable, adds episode_id/season_id, and a generated member_id used for primary keys, ordering, and dedup (migration).
  • MDBList sync resolves season and episode entries via new batch lookups (SeasonRepository.ListIDsByNumbers, EpisodeRepository.ListByProviderNumbers) and stores them as typed members (lists.go, library_collection_service.go).
  • Adds an admin link-check endpoint GET /api/v2/admin/collections/mdblist/link plus a last_sync_reason code so the web UI can show a localized 'MDBList API key required' warning with a link to provider settings (admin_collections.go, mdblistLinkCheck.ts).
  • Season members surface everywhere: catalog pages, section rails, Jellyfin BoxSet children (with Play All and leaf expansion), shuffle pools, backup planning, and reattribution.
  • Risk: a database trigger rejects direct deletes of episode/season member rows unless silo.collection_member_writes is set — check AllowCollectionMemberDeletes callers in library_collection_mutations.go and the reattribution path in reattribute.go. Down migration deletes non-title member rows.

Macroscope summarized 7b2e542.

MDBList's public /json feed leaves episodes out, so a list of episodes
reads as empty and its collection never fills. An empty feed now falls
through to the MDBList API when the server has a key. The API client
reads /items/episode when /items is empty, and the sync matches each
episode by its show's TMDB ID and TMDB numbers, which are the provider
numbers of a TMDB-matched series.
The live API returns an episode list's episodes in an episodes array
on /lists/{id}/items. /items/episode answers 405, so the fallback to
it would have failed the sync of every empty list.
library_collection_items gains episode_id and season_id beside
media_item_id, each with its own cascading foreign key, and a generated
member_id that is the primary key. Writers and plain-ID readers move to
member_id; ReplaceItems stores a member in the column its kind names.
The MDBList API lists a list's seasons in their own array, named by
show TMDB ID and season number. A synced collection now matches them
to the catalog's seasons and stores episodes and seasons as members of
their own kind. A season counts as in a library when any of its
episodes has a file there.
A stored collection's page reads its members as titles, episodes, or
seasons. Episodes come from the episode relation and seasons from a new
relation in the same shape; both pass through their series' access.
Season cards name their series and number as episode cards do.
A collection's stored and per-viewer item counts include its episode and
season members, judged as its page shows them: an episode with a file in
some library, a season with such an episode, and for a viewer only those
whose series they can open. Rating limits and excluded types now judge
the series row, which fixes the page's member fetch under a rating limit.
An episode or season member lends the collection's collage its season's
or series' poster, under the same access rules as its card. A poster
already chosen is not repeated, so a list of one show's episodes shows
that show once; the collage is picked from a bounded window of members
so the query still stops early on large collections.
A stored collection's episode and season members are BoxSet children in
curated order and count toward its total, under the native page's access
rules. An episode member lists as an Episode with its series context and a
season member as a Season a client can open. Play all plays an episode
member as it is and a season member as its visible episodes, each leaf
once. Counts, collages and the BoxSet page share one catalog helper for
the member branches.
… rows

The catalog reads a stored collection that holds episodes or seasons
through one relation of its titles, episodes and seasons, each branch
applying membership, library scope and the viewer's access, so the web
collection page, Jellyfin's resolved order, home rows built from the
collection and shuffle list them in curated order or under a sort.
Collections of titles only keep their current queries. Season cards in
the catalog and in rows name their series and number, and shuffle plays a
season member's episodes.
…e rows cheaply

Readers switch to the member relation through one helper, the preview takes
the library scope and skips an unused count, a partial index finds a
collection's episode and season members, and the BoxSet's Play all looks up
seasons only among members that are not episodes. Docs and comments match
the code.
A season 0 member with no title of its own showed as "Season 0" on
collection cards, rows and the Jellyfin BoxSet, where its own page says
Specials. Both readers now share one season title expression.
MDBList names an episode by TMDB's season and episode numbers, which differ
from a series numbered by TVDB or in another order, so the sync could store
the wrong episode. The API also gives each episode and season its TMDB ID;
matching tries that first and falls back to the numbers.
…nd no key is set

The public feed answers a list of episodes or seasons empty, and without a
server MDBList key the sync stored that as an empty success, so clearing or
rotating the key emptied a collection the key had filled. The sync now fails
with a message naming the key and keeps the members.
… all by access

A sorted BoxSet request browsed the catalog, which reads titles only, so a
collection of episodes answered empty. Such a collection now keeps its
curated order under a sort. Play all counted an episode member whose series
was above the viewer's rating, leaving an empty first page; it now judges
episode members as the BoxSet's children are judged.
A selective restore looked a collection's members up among titles only, so
it counted an MDBList collection's episodes and seasons unknown and added
none of them. It now finds them in episodes and seasons too.
The collage read a collection's titles under a union with its episode and
season members, which could read every title member before the limit. The
title branch now stops at the window in member order.
…MDB ID

The number fallback could pick an episode or season at the entry's numbers
that carries a different TMDB ID, the case a library numbered unlike TMDB
produces. Rows without a TMDB ID still match by number.
An import of an episode list on a server without an MDBList key answered a
generic 500 and left the created collection behind. The sync now records a
warning run naming the key and keeps the members, so the import returns the
collection and the reason.
…he viewer can't open

A series can span libraries with different access. An episode member whose
only file sat in a library the viewer couldn't open was listed, counted and
queued by Play all, though playback had no file to play.
Season children of a BoxSet carried a poster path but no poster URL, so the
season mapper set no Primary image tag and Jellyfin clients drew the season
without artwork.
…es category

Roku and Android TV open a collection with the library category's media
scope. The executor tested that scope against each member's own type, so a
Series category showed none of a collection's episodes or seasons. An
episode or season member now counts as its series under a scope, and a
Movies category still lists movies alone.
A season without artwork took its series' poster as its Primary tag, but
the image endpoint serves a season's own poster only, so a client fetching
that tag on a node without the cached URL got a 404.
With a library's Series category the executor still treated every row as a
series, so a watched filter looked for episodes of an episode or season
member, found none, and listed a watched episode as unwatched.
The stored message names the MDBList key, but the v2 admin API reports no
sync message, so admins see only the warning status.
A private list, and a list of episodes or seasons, sync only with an
MDBList API key, but the admin API reported only a generic sync failure or
a warning. checkAdminMDBListLink tells an admin before creating whether a
link needs a key the server lacks, and admin collections and sync runs
carry a mdblist_api_key_required reason that clients show in their own
words.
Pasting a link to a private list, or a list of episodes or seasons, on a
server without an MDBList key now says under the field that the list syncs
only after a key is added in Settings > Providers. A saved list whose sync
read nothing for want of the key shows that in its sync alert, its row in
the collection list, the toast after it is created and Sync now.
@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

CodeRabbit ASCII loading animation

Currently processing new changes in this PR. This may take a few minutes, please wait...

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fc1907e-7c01-495a-adf0-cc18a2d8b344
Commits

Reviewing files that changed from the base of the PR and between db0fd94 and ca4faf6.

Files selected for processing: 78

  • .silo-translations
  • contracts/api/v2/fixtures/get_admin_collection_capabilities_ok.json
  • contracts/api/v2/fixtures/index.json
  • contracts/api/v2/openapi.json
  • docs/architecture/api-contract.md
  • docs/architecture/collection-members.md
  • docs/catalog-api.md
  • internal/api/handlers/admin_collection_editors_service.go
  • internal/api/handlers/catalog.go
  • internal/api/handlers/collections_paging_service.go
  • internal/api/handlers/library_collection_episode_members_db_test.go
  • internal/api/handlers/library_collections.go
  • internal/api/handlers/sections.go
  • internal/api/router.go
  • internal/api/testdata/media_routes.txt
  • internal/apiv2/admin_collection_mdblist_key_test.go
  • internal/apiv2/admin_collection_types.go
  • internal/apiv2/admin_collections.go
  • internal/backup/restoreset_write.go
  • internal/backup/selective_collection_members_postgres_test.go
  • internal/backup/selective_plan.go
  • internal/catalog/browse.go
  • internal/catalog/catalog_collection_cursor.go
  • internal/catalog/catalog_resolver.go
  • internal/catalog/collection_members.go
  • internal/catalog/collection_pages.go
  • internal/catalog/collection_pages_test.go
  • internal/catalog/episode_file_number_db_test.go
  • internal/catalog/episode_repo.go
  • internal/catalog/library_collection_counts.go
  • internal/catalog/library_collection_mdblist.go
  • internal/catalog/library_collection_mdblist_key_test.go
  • internal/catalog/library_collection_mdblist_members_db_test.go
  • internal/catalog/library_collection_mutations.go
  • internal/catalog/library_collection_page.go
  • internal/catalog/library_collection_posters.go
  • internal/catalog/library_collection_replace_items_db_test.go
  • internal/catalog/library_collection_repo.go
  • internal/catalog/library_collection_service.go
  • internal/catalog/library_repo.go
  • internal/catalog/query_cursor_test.go
  • internal/catalog/query_executor.go
  • internal/catalog/reattribute/reattribute.go
  • internal/catalog/season_episode_locks.go
  • internal/catalog/season_repo.go
  • internal/collectionutil/mdblist_private.go
  • internal/collectionutil/mdblist_test.go
  • internal/jellycompat/batch_loaders.go
  • internal/jellycompat/handlers_collections.go
  • internal/jellycompat/handlers_collections_members_db_test.go
  • internal/jellycompat/mapping.go
  • internal/mdblist/lists.go
  • internal/mdblist/lists_test.go
  • internal/metadata/episode_renumber_db_test.go
  • internal/metadata/provider_id_integrity.go
  • internal/models/library_collection.go
  • internal/sections/collection_rail_members_db_test.go
  • internal/sections/fetcher.go
  • internal/shuffle/pool.go
  • internal/usercollections/sync.go
  • migrations/sql/20261206153438_library_collection_episode_season_members.sql
  • scripts/ci/db-contracts.txt
  • web/src/api/types.ts
  • web/src/api/v2/operations.ts
  • web/src/api/v2/schema.ts
  • web/src/components/CollectionTemplateGallery/MDBListBrowser.tsx
  • web/src/components/collections/admin/CollectionListItem.tsx
  • web/src/components/collections/editor/SyncedListPanel.tsx
  • web/src/hooks/queries/collectionScope.ts
  • web/src/hooks/queries/keys.ts
  • web/src/hooks/queries/mdblistKeyNotice.test.tsx
  • web/src/hooks/queries/mdblistLinkCheck.ts
  • web/src/lib/collections/copy.ts
  • web/src/lib/collections/scope.ts
  • web/src/locales/ar-XB.json
  • web/src/locales/en-XA.json
  • web/src/locales/en.json
  • web/src/locales/keys.ts

@silo-triage silo-triage Bot added enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Dec 6, 2026
@silo-triage

silo-triage Bot commented Dec 6, 2026

Copy link
Copy Markdown

Please add before-and-after phone-width captures of the missing-key result after creating a collection (toast and admin list row), and the sync-failure alert in the existing collection editor. These are changed user-visible states, and the evidence requirement covers mobile web separately from desktop. If either state is desktop-only, explain why mobile is unaffected.

…wn file

library_collection_service.go crossed the repository's 1000-line limit;
the MDBList key reasons, link check and episode and season matching move
unchanged into library_collection_mdblist.go.
Comment thread internal/catalog/episode_repo.go Resolved
Comment thread internal/jellycompat/batch_loaders.go Resolved
Comment thread internal/jellycompat/batch_loaders.go Resolved
Comment thread internal/mdblist/lists.go Resolved
…nd season members

The previous release replaces a collection's members by deleting every row
whose media_item_id its list leaves out, which an episode or season member
never matches; one of its servers syncing an episode list during a rolling
upgrade would empty the collection. A trigger now refuses a direct delete of
such a member unless the transaction marks itself as this release's, so the
old sync fails and the members stay. Cascading deletes still go through.
The episode merge deletes the source's collection member when the kept
episode is already in that collection, a direct delete the new member
guard refuses unless the transaction opts in. It now opts in, through
the helper catalog's own member deletes use.
@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Offset paging counted only the items it kept, so a page of episodes or
seasons without a show ID made it ask for the same page again, forever
when the first page held nothing usable.
…r can open

A season member of a series spanning libraries was listed and counted
from episodes in any library, so a viewer could see a season whose
episodes all sit in a library they can't open. It now uses the native
member relation's library check.
@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

A list the feed answers empty is read through the MDBList API, which
returns MDBList's rank order and is capped by rank, whatever sort the
link names. Only the public feed follows a link's sort, so a public
list of episodes or seasons keeps rank order, like a private one.
@silo-kody

silo-kody Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 5 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility
  • Make capability responses reflect effective permissions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/XXXL 3000+ added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant