2.7 KiB
Stream Metadata Fallback Design
Context
mpv-youtube-queue.lua currently imports externally opened playlist items by calling sync_with_playlist(). For non-YouTube streams such as Jellyfin or custom extractor URLs, yt-dlp --dump-single-json can fail. The current listener flow also retries that import path on playback-restart, which fires during seeks, causing repeated metadata fetch attempts and repeated failures.
Goal
Keep externally opened streams in the queue while preventing seek-triggered metadata retries. When extractor metadata is unavailable, use mpv metadata, preferring media-title.
Chosen Approach
- Stop using
playback-restartas the trigger for queue import. - Import external items on real file loads and startup sync only.
- Add a metadata fallback path for playlist items:
- use cached metadata first
- try
yt-dlponce - if that fails, build queue metadata from mpv properties, preferring
media-title
- Cache fallback metadata too so later syncs do not retry
yt-dlpfor the same URL.
Why This Approach
- Fixes root cause instead of hiding repeated failures behind a negative cache alone.
- Preserves current rich metadata for URLs that
yt-dlpunderstands. - Keeps Jellyfin/custom extractor streams visible in the queue with a usable title.
Metadata Resolution
For a playlist URL, resolve metadata in this order:
- Existing cached metadata entry
yt-dlpmetadata- mpv fallback metadata using:
media-title- then filename/path-derived title
- placeholder values for channel/category fields
Fallback entries should be marked so the script can distinguish rich extractor metadata from mpv-derived metadata if needed later.
Listener Changes
- Keep startup
on_loadsync. - Keep
file-loadedhandling. - Remove external queue bootstrap from
playback-restart, because seeks trigger it. - Keep existing index-tracking listeners that do not rebuild queue state.
Error Handling
- Failing extractor metadata should no longer drop the playlist item.
- Missing uploader/channel data should not be treated as fatal for fallback entries.
- Queue sync should remain best-effort per item: one bad URL should not abort the whole playlist import.
Regression Coverage
- Non-extractor stream gets queued with
media-titlefallback. - Repeated sync for the same URL reuses cached fallback metadata instead of calling extractor again.
- Standard supported URLs still keep extractor metadata.
Risks
- mpv properties available during playlist sync may differ by source; fallback builder must handle missing values safely.
- The repo currently has no obvious test harness, so regression coverage may require a small isolated Lua test scaffold.