Files
ersatztv/docs/decisions/records/scan/mediaserver-statistics-from-server.md
T
timothyandClaude Opus 5.5 1f7b763a7b
Build ErsatzTV Image / CI toolchain image resolves (push) Successful in 25s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 8m19s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (push) Skipped
Build ErsatzTV Image / Delimiter ban (release path) (push) Successful in 45s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Skipped
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 9m22s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 6m30s
fix(924): media-server music videos read their statistics from the server's playback info (#928)
Jellyfin's library-items projection builds every music video's MediaVersion with Streams = [] and no width/height; the server reports those only through per-item PlaybackInfo. MediaServerMusicVideoLibraryScanner.UpdateStatistics wrote that empty projection straight through (also removing any streams a stored row already had), so every Jellyfin music video was stored without streams and FFmpegStreamSelector.SelectVideoStream threw "Sequence contains no matching element" on play. Prod 2026-10-21: the Jellyfin "Music Videos" library (id 16), 1520/1520 versions with zero MediaStream rows.

- UpdateStatistics mirrors the movie scanner: on deep scan, new item, changed etag or no stored streams it asks the abstract GetMediaServerStatistics, and writes nothing when the server cannot answer.
- JellyfinMusicVideoLibraryScanner implements it via GetPlaybackInfo; chapters come from the incoming projection.
- SelectVideoStream fails with the version id, file and remediation (deep scan, or remove a file that has no video stream) instead of a bare First() throw.
- Other-video and TV scanners checked: no such gap.
- Record scan.mediaserver-statistics-from-server.

Existing rows heal only on a DEEP scan (a regular scan skips unchanged etags): POST /api/v1/libraries/16/scan?deep=true after deploy.

fixes #924

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: 99d1dedb-f027-4e05-baab-2111f3a7d951
Co-authored-by: Timothy <timothy@noreply.gitea.tblindustries.be>
2026-10-22 06:24:18 +00:00

4.6 KiB

key, title, status, since, supersedes, superseded-by, rule, signals, mechanics
key title status since supersedes superseded-by rule signals mechanics
scan.mediaserver-statistics-from-server 2026-10-21 — A media-server scanner reads a version's statistics from the server, never from the library-items projection (#924) active 2026-10-21 none none Every media-server scanner writes a head `MediaVersion`'s statistics (streams, width/height, aspect, frame rate) from what the server reports per item — `GetMediaServerStatistics` (Jellyfin/Emby playback info) or the metadata call that carries them (`ServerReturnsStatisticsWithMetadata`, Plex) — and NEVER writes the library-items projection's version, whose `Streams` list is empty. When the server cannot supply them, nothing is written. In `MediaServerMusicVideoLibraryScanner` the hook is `abstract`, not a virtual returning `None`. zero MediaStream rows, Width/Height 0, Sequence contains no matching element, SelectVideoStream, playback info, GetPlaybackInfo, projection Streams = [], deep scan to heal, music videos will not play · paths: `MediaServerMusicVideoLibraryScanner.UpdateStatistics`, `JellyfinMusicVideoLibraryScanner.GetMediaServerStatistics`, `MediaServerMovieLibraryScanner.UpdateStatistics`, `IMetadataRepository.UpdateStatistics`, `FFmpegStreamSelector.SelectVideoStream` · issues: #924, #496 `JellyfinMusicVideoLibraryScannerTests` (`ScanLibrary_Should_Store_PlaybackInfo_Statistics_For_A_New_MusicVideo`, `..._Deep_Scan_Should_Read_Statistics_For_An_Unchanged_MusicVideo_Without_Streams`, `..._Should_Read_Statistics_For_A_Returning_Unavailable_MusicVideo_Without_Streams`, `..._Should_Keep_Stored_Statistics_When_PlaybackInfo_Fails_On_Rescan`, `..._Should_Refresh_Statistics_And_Projection_Chapters_When_The_Etag_Changes`, against the real `MetadataRepository`); `FFmpegStreamSelectorTests.SelectVideoStream`

The Jellyfin and Emby library-items projections build every movie, episode and music-video version with Streams = [] and no dimensions; only the per-item playback info carries them. The movie and TV scanners fetch statistics when the item is new, changed, deep-scanned or has no stored streams. The music-video scanner wrote the projection's version instead, so every Jellyfin music video was stored without streams and FFmpegStreamSelector.SelectVideoStream threw on play. Measured on prod 2026-10-21 (#924): the Jellyfin "Music Videos" library (id 16), 1520 of 1520 music-video versions with zero MediaStream rows (movies 0, episodes 4).

  • Writing the projection is worse than writing nothing. IMetadataRepository.UpdateStatistics reconciles the stored streams against the version it is handed, so an empty stream list REMOVES every stream an existing row has. A failed statistics read therefore leaves the row untouched, matching the movie scanner.
  • The refresh condition is the movie scanner's: deepScan || IsAdded || etag changed || no stored streams. For music videos IsAdded is implied by the empty-streams arm while the projection carries no streams; it is kept so the two conditions read the same.
  • abstract, not virtual-None. The movie base defaults GetMediaServerStatistics to None; Jellyfin and Emby override it, and Plex takes statistics from its metadata call (ServerReturnsStatisticsWithMetadata). Music videos have one implementation, and a None default is the defect itself, so a future Emby/Plex music-video scanner must answer the question to compile.
  • Chapters come from the incoming projection, not from the stored item as in JellyfinMovieLibraryScanner: JellyfinMusicVideoRepository.GetByItemId does not eager-load chapters, so the stored item has none to write.
  • Healing stored rows takes a deep scan. A regular scan skips an item whose etag is unchanged before the refresh condition is reached, so rows already stored without streams stay that way until their library is deep-scanned or the server changes the item. On a live instance that scan is a channel operation (media-management), not part of shipping the fix.
  • The player names the gap. SelectVideoStream on a version with no video stream fails with the version id, its file and the remediation (rescan; deep scan for a media-server library) instead of First()'s bare Sequence contains no matching element.
  • Known residual, shared with movies: when the server cannot answer, the item's etag is still recorded, so a transient playback-info failure on a new or changed item leaves it without streams until the next deep scan or server-side change. Not changed here: skipping the etag write would retry the item on every scan, and the same trade-off already holds for movies and episodes.