diff --git a/e2e/jellyfin.e2e.test.ts b/e2e/jellyfin.e2e.test.ts index a6957918..d71bfd13 100644 --- a/e2e/jellyfin.e2e.test.ts +++ b/e2e/jellyfin.e2e.test.ts @@ -21,7 +21,7 @@ after(async () => { if (clipsDir) fs.rmSync(clipsDir, { recursive: true, force: true }); }); -type PlaylistEntry = { filename: string; current?: boolean }; +type PlaylistEntry = { filename: string; current?: boolean; title?: string }; // The episode ids in mpv's playlist, the current one marked with `*`. async function playlistIds(mpv: E2eSession['mpv']): Promise { @@ -79,6 +79,19 @@ test( timeoutMs: 30_000, }); assert.ok(reported('playing', 'ep2') >= 0, 'Jellyfin hears ep2 start'); + // mpv's playlist lists entry titles, not stream URLs carrying the API key. + const titles = [ + 'E2E Show S01E01 Episode 1', + 'E2E Show S01E02 Episode 2', + 'E2E Show S01E03 Episode 3', + ]; + await waitUntil( + async () => { + const playlist = (await mpv.command('get_property', 'playlist')) as PlaylistEntry[]; + return playlist.map((entry) => entry.title).join('|') === titles.join('|'); + }, + { description: 'queued playlist entries titled like the playing episode', timeoutMs: 10_000 }, + ); await mpv.command('playlist-next'); await waitUntil(() => reported('playing', 'ep3') >= 0, { diff --git a/src/main/runtime/jellyfin-episode-playlist.test.ts b/src/main/runtime/jellyfin-episode-playlist.test.ts index afef087e..f853cee1 100644 --- a/src/main/runtime/jellyfin-episode-playlist.test.ts +++ b/src/main/runtime/jellyfin-episode-playlist.test.ts @@ -41,13 +41,14 @@ const entry = (itemId: string): Entry => ({ seriesId: 'series', playbackUrl: url(itemId), loadfileOptions: `opts-${itemId}`, + title: `Show ${itemId}`, }); /** mpv's playlist, kept in sync with the commands the queue sends. */ function makeHarness( settings: JellyfinEpisodePlaylistSettings = { enabled: true, maxEpisodes: 3 }, ) { - const playlist: Array<{ filename: string; current: boolean }> = []; + const playlist: Array<{ filename: string; current: boolean; title?: string }> = []; const commands: Array> = []; let episodeListCalls = 0; const queue = createJellyfinEpisodePlaylist({ @@ -64,6 +65,10 @@ function makeHarness( if (command[0] === 'loadfile') { playlist.splice(Number(command[3]), 0, { filename: String(command[1]), current: false }); } + const titleIndex = /^playlist\/(\d+)\/title$/.exec(String(command[1]))?.[1]; + if (command[0] === 'set_property' && titleIndex !== undefined) { + playlist[Number(titleIndex)]!.title = String(command[2]); + } }, logDebug: () => {}, }); @@ -80,6 +85,7 @@ function makeHarness( playing, episodeListCalls: () => episodeListCalls, filenames: () => playlist.map((item) => item.filename), + titles: () => playlist.map((item) => item.title), }; } @@ -104,6 +110,7 @@ test('queueNeighbors inserts the episode window around the current entry', async url('e4'), url('e2'), ]); + assert.deepEqual(harness.titles(), ['Show e2', 'Show e3', 'Show e4']); assert.equal(harness.queue.find(url('e4'))?.entry.itemId, 'e4'); assert.equal(harness.queue.find(url('e5')), null); }); @@ -117,6 +124,7 @@ test('queueNeighbors slides the window when mpv moves to a queued episode', asyn await harness.queue.queueNeighbors(null, entry('e4')); assert.deepEqual(harness.filenames(), [url('e3'), url('e4'), url('e5')]); + assert.deepEqual(harness.titles(), ['Show e3', 'Show e4', 'Show e5']); assert.equal(harness.queue.find(url('e2')), null); assert.equal(harness.episodeListCalls(), 1, 'series order is reused while navigating'); }); diff --git a/src/main/runtime/jellyfin-episode-playlist.ts b/src/main/runtime/jellyfin-episode-playlist.ts index 11363f2f..cf0aa167 100644 --- a/src/main/runtime/jellyfin-episode-playlist.ts +++ b/src/main/runtime/jellyfin-episode-playlist.ts @@ -7,6 +7,8 @@ export type JellyfinPlaylistEntry = { playbackUrl: string; /** Per-file mpv options, applied whenever mpv starts this entry. */ loadfileOptions: string; + /** Shown in mpv's playlist, which otherwise lists the stream URL and its API key. */ + title: string; }; export type JellyfinEpisodePlaylistSettings = { @@ -132,28 +134,23 @@ export function createJellyfinEpisodePlaylist { + deps.sendMpvCommand([ + 'loadfile', + entry.playbackUrl, + 'insert-at', + index, + entry.loadfileOptions, + ]); + deps.sendMpvCommand(['set_property', `playlist/${index}/title`, entry.title]); + queued.set(entry.playbackUrl, { context, entry }); + }; queued = new Map([[current.playbackUrl, { context, entry: current }]]); - next.forEach((entry, offset) => { - deps.sendMpvCommand([ - 'loadfile', - entry.playbackUrl, - 'insert-at', - currentAt + 1 + offset, - entry.loadfileOptions, - ]); - queued.set(entry.playbackUrl, { context, entry }); - }); + deps.sendMpvCommand(['set_property', `playlist/${currentAt}/title`, current.title]); + next.forEach((entry, offset) => insertEntry(entry, currentAt + 1 + offset)); // Each insert before the current entry pushes it one slot later. - previous.forEach((entry, offset) => { - deps.sendMpvCommand([ - 'loadfile', - entry.playbackUrl, - 'insert-at', - currentAt + offset, - entry.loadfileOptions, - ]); - queued.set(entry.playbackUrl, { context, entry }); - }); + previous.forEach((entry, offset) => insertEntry(entry, currentAt + offset)); deps.sendMpvCommand([ 'script-message', MANAGED_PLAYLIST_ENTRIES_SCRIPT_MESSAGE, diff --git a/src/main/runtime/jellyfin-playback-launch.ts b/src/main/runtime/jellyfin-playback-launch.ts index 43939083..1db6c85f 100644 --- a/src/main/runtime/jellyfin-playback-launch.ts +++ b/src/main/runtime/jellyfin-playback-launch.ts @@ -121,6 +121,7 @@ function resolveEffectiveStartTimeTicks( type JellyfinPreparedPlayback = { itemId: string; seriesId: string | null; + title: string; plan: JellyfinPlaybackPlan; playbackUrl: string; loadfileOptions: string; @@ -173,6 +174,7 @@ function prepareJellyfinPlayback( return { itemId, seriesId: plan.seriesId, + title: plan.title, plan, playbackUrl: stripManagedSubtitleStreamFromPlaybackUrl(playbackUrlBase), loadfileOptions: buildJellyfinLoadfileOptions(