The Plex aggregation CTE used MAX(codec)/MAX(bit_depth) directly,
which produced two bugs that surfaced in the Albums grid for many
Plex-only libraries:
- format = "Unknown". Plex frequently omits the stream-level codec
when its analyzer hasn't seen the file yet. MAX(NULL) collapsed
the row's format to NULL, which the frontend parser mapped to
AudioFormat::Unknown — the Library grid then showed UNKNOWN even
though the file's container was clearly "flac" / "mp3".
- bit_depth = NULL. Plex commonly omits bitDepth on older releases
entirely; the album row inherited the gap and the UI rendered
"--/44.1" next to an otherwise valid quality string.
Two fallbacks applied to the plex_aggregated CTE only — the local
CTE is untouched because local indexing always writes a non-null
format string and a real bit depth via Symphonia:
- format: COALESCE(MAX(codec), MAX(container)). The `container`
column is populated for the same media and typically carries the
same value ("flac", "mp3"), so it's a safe fallback when codec
is fully NULL across the album.
- bit_depth: COALESCE(MAX(bit_depth), CASE WHEN <lossless> AND
sample_rate <= 48000 THEN 16 ELSE NULL END). Lossless formats
at CD-range rates are virtually always 16-bit redbook, so we
default to 16 in that narrow window. Higher rates stay NULL so
we don't lie about 24 vs 32. The per-track view shows the real
value when the user clicks in (lazy hydration via
plex_get_track_metadata).
cc