mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-23 04:46:08 -08:00
fix(jellyfin): title queued playlist entries instead of stream URLs
- Set playlist/N/title for the current and queued neighbor episodes so mpv's playlist doesn't show stream URLs that carry the API key - Thread the plan title through prepared Jellyfin playback - Cover titles in unit and e2e playlist tests
This commit is contained in:
4 files changed
+42
-22
No files matched your search
@@ -21,7 +21,7 @@ after(async () => {
|
|||||||
if (clipsDir) fs.rmSync(clipsDir, { recursive: true, force: true });
|
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 `*`.
|
// The episode ids in mpv's playlist, the current one marked with `*`.
|
||||||
async function playlistIds(mpv: E2eSession['mpv']): Promise<string[]> {
|
async function playlistIds(mpv: E2eSession['mpv']): Promise<string[]> {
|
||||||
@@ -79,6 +79,19 @@ test(
|
|||||||
timeoutMs: 30_000,
|
timeoutMs: 30_000,
|
||||||
});
|
});
|
||||||
assert.ok(reported('playing', 'ep2') >= 0, 'Jellyfin hears ep2 start');
|
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 mpv.command('playlist-next');
|
||||||
await waitUntil(() => reported('playing', 'ep3') >= 0, {
|
await waitUntil(() => reported('playing', 'ep3') >= 0, {
|
||||||
|
|||||||
@@ -41,13 +41,14 @@ const entry = (itemId: string): Entry => ({
|
|||||||
seriesId: 'series',
|
seriesId: 'series',
|
||||||
playbackUrl: url(itemId),
|
playbackUrl: url(itemId),
|
||||||
loadfileOptions: `opts-${itemId}`,
|
loadfileOptions: `opts-${itemId}`,
|
||||||
|
title: `Show ${itemId}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** mpv's playlist, kept in sync with the commands the queue sends. */
|
/** mpv's playlist, kept in sync with the commands the queue sends. */
|
||||||
function makeHarness(
|
function makeHarness(
|
||||||
settings: JellyfinEpisodePlaylistSettings = { enabled: true, maxEpisodes: 3 },
|
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<Array<string | number>> = [];
|
const commands: Array<Array<string | number>> = [];
|
||||||
let episodeListCalls = 0;
|
let episodeListCalls = 0;
|
||||||
const queue = createJellyfinEpisodePlaylist<null, Entry>({
|
const queue = createJellyfinEpisodePlaylist<null, Entry>({
|
||||||
@@ -64,6 +65,10 @@ function makeHarness(
|
|||||||
if (command[0] === 'loadfile') {
|
if (command[0] === 'loadfile') {
|
||||||
playlist.splice(Number(command[3]), 0, { filename: String(command[1]), current: false });
|
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: () => {},
|
logDebug: () => {},
|
||||||
});
|
});
|
||||||
@@ -80,6 +85,7 @@ function makeHarness(
|
|||||||
playing,
|
playing,
|
||||||
episodeListCalls: () => episodeListCalls,
|
episodeListCalls: () => episodeListCalls,
|
||||||
filenames: () => playlist.map((item) => item.filename),
|
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('e4'),
|
||||||
url('e2'),
|
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('e4'))?.entry.itemId, 'e4');
|
||||||
assert.equal(harness.queue.find(url('e5')), null);
|
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'));
|
await harness.queue.queueNeighbors(null, entry('e4'));
|
||||||
|
|
||||||
assert.deepEqual(harness.filenames(), [url('e3'), url('e4'), url('e5')]);
|
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.queue.find(url('e2')), null);
|
||||||
assert.equal(harness.episodeListCalls(), 1, 'series order is reused while navigating');
|
assert.equal(harness.episodeListCalls(), 1, 'series order is reused while navigating');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export type JellyfinPlaylistEntry = {
|
|||||||
playbackUrl: string;
|
playbackUrl: string;
|
||||||
/** Per-file mpv options, applied whenever mpv starts this entry. */
|
/** Per-file mpv options, applied whenever mpv starts this entry. */
|
||||||
loadfileOptions: string;
|
loadfileOptions: string;
|
||||||
|
/** Shown in mpv's playlist, which otherwise lists the stream URL and its API key. */
|
||||||
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type JellyfinEpisodePlaylistSettings = {
|
export type JellyfinEpisodePlaylistSettings = {
|
||||||
@@ -132,28 +134,23 @@ export function createJellyfinEpisodePlaylist<Context, Entry extends JellyfinPla
|
|||||||
if (index < currentIndex) currentAt -= 1;
|
if (index < currentIndex) currentAt -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each insert is followed by its title, sent while the entry is still at that index.
|
||||||
|
const insertEntry = (entry: Entry, index: number) => {
|
||||||
|
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 }]]);
|
queued = new Map([[current.playbackUrl, { context, entry: current }]]);
|
||||||
next.forEach((entry, offset) => {
|
deps.sendMpvCommand(['set_property', `playlist/${currentAt}/title`, current.title]);
|
||||||
deps.sendMpvCommand([
|
next.forEach((entry, offset) => insertEntry(entry, currentAt + 1 + offset));
|
||||||
'loadfile',
|
|
||||||
entry.playbackUrl,
|
|
||||||
'insert-at',
|
|
||||||
currentAt + 1 + offset,
|
|
||||||
entry.loadfileOptions,
|
|
||||||
]);
|
|
||||||
queued.set(entry.playbackUrl, { context, entry });
|
|
||||||
});
|
|
||||||
// Each insert before the current entry pushes it one slot later.
|
// Each insert before the current entry pushes it one slot later.
|
||||||
previous.forEach((entry, offset) => {
|
previous.forEach((entry, offset) => insertEntry(entry, currentAt + offset));
|
||||||
deps.sendMpvCommand([
|
|
||||||
'loadfile',
|
|
||||||
entry.playbackUrl,
|
|
||||||
'insert-at',
|
|
||||||
currentAt + offset,
|
|
||||||
entry.loadfileOptions,
|
|
||||||
]);
|
|
||||||
queued.set(entry.playbackUrl, { context, entry });
|
|
||||||
});
|
|
||||||
deps.sendMpvCommand([
|
deps.sendMpvCommand([
|
||||||
'script-message',
|
'script-message',
|
||||||
MANAGED_PLAYLIST_ENTRIES_SCRIPT_MESSAGE,
|
MANAGED_PLAYLIST_ENTRIES_SCRIPT_MESSAGE,
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ function resolveEffectiveStartTimeTicks(
|
|||||||
type JellyfinPreparedPlayback = {
|
type JellyfinPreparedPlayback = {
|
||||||
itemId: string;
|
itemId: string;
|
||||||
seriesId: string | null;
|
seriesId: string | null;
|
||||||
|
title: string;
|
||||||
plan: JellyfinPlaybackPlan;
|
plan: JellyfinPlaybackPlan;
|
||||||
playbackUrl: string;
|
playbackUrl: string;
|
||||||
loadfileOptions: string;
|
loadfileOptions: string;
|
||||||
@@ -173,6 +174,7 @@ function prepareJellyfinPlayback(
|
|||||||
return {
|
return {
|
||||||
itemId,
|
itemId,
|
||||||
seriesId: plan.seriesId,
|
seriesId: plan.seriesId,
|
||||||
|
title: plan.title,
|
||||||
plan,
|
plan,
|
||||||
playbackUrl: stripManagedSubtitleStreamFromPlaybackUrl(playbackUrlBase),
|
playbackUrl: stripManagedSubtitleStreamFromPlaybackUrl(playbackUrlBase),
|
||||||
loadfileOptions: buildJellyfinLoadfileOptions(
|
loadfileOptions: buildJellyfinLoadfileOptions(
|
||||||
|
|||||||
Reference in new issue
Block a user