mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-22 16:46:10 -08:00
fix(aniskip): retry chapter detection after a failed chapter-list read
A failed read left resolution marked as started, so streams never got skip windows until a refresh or file change. It is now retried on the next duration change or same-media reload; a successful empty list stays final.
This commit is contained in:
2 files changed
+45
-7
No files matched your search
@@ -525,3 +525,35 @@ test('a same-media reload retries a transient lookup failure', async () => {
|
|||||||
assert.equal(state.resolveCalls.length, 2);
|
assert.equal(state.resolveCalls.length, 2);
|
||||||
assert.deepEqual(runtime.getSkipWindows().intro, { start: 10, end: 95.5, source: 'aniskip' });
|
assert.deepEqual(runtime.getSkipWindows().intro, { start: 10, end: 95.5, source: 'aniskip' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a failed chapter-list read is retried on the next duration change or reload', async () => {
|
||||||
|
const stream = 'https://jellyfin.example/Videos/1/stream.mkv';
|
||||||
|
const chapters = [
|
||||||
|
{ time: 0, title: 'OP' },
|
||||||
|
{ time: 90, title: 'Episode' },
|
||||||
|
];
|
||||||
|
for (const retry of ['duration', 'reload'] as const) {
|
||||||
|
const { runtime, state } = createHarness({ chapterList: chapters });
|
||||||
|
state.chapterListFails = true;
|
||||||
|
runtime.handleMediaPathChange({ path: stream });
|
||||||
|
await flushAsync();
|
||||||
|
assert.deepEqual(runtime.getSkipWindows(), NO_SKIP_TIMES);
|
||||||
|
|
||||||
|
state.chapterListFails = false;
|
||||||
|
if (retry === 'duration') runtime.handleDurationChange({ duration: 1440 });
|
||||||
|
else runtime.handleMediaPathChange({ path: stream });
|
||||||
|
await flushAsync();
|
||||||
|
assert.deepEqual(runtime.getSkipWindows().intro, { start: 0, end: 90, source: 'chapters' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a successful empty chapter list is not read again on a duration change', async () => {
|
||||||
|
const { runtime, state } = createHarness({
|
||||||
|
metadata: readyMetadata({ ...NO_SKIP_TIMES, lookupStatus: 'missing_payload' }),
|
||||||
|
});
|
||||||
|
runtime.handleMediaPathChange({ path: '/media/show.mkv' });
|
||||||
|
await flushAsync();
|
||||||
|
runtime.handleDurationChange({ duration: 1441 });
|
||||||
|
await flushAsync();
|
||||||
|
assert.equal(state.resolveCalls.length, 1);
|
||||||
|
});
|
||||||
@@ -81,8 +81,10 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
|||||||
let currentDuration: number | null = null;
|
let currentDuration: number | null = null;
|
||||||
// True once resolution for the current media has started (or finished).
|
// True once resolution for the current media has started (or finished).
|
||||||
let resolutionStarted = false;
|
let resolutionStarted = false;
|
||||||
// True when the last AniSkip lookup for the current media failed in a retryable way.
|
// True when resolution for the current media hit a retryable failure (the
|
||||||
let lastLookupFailed = false;
|
// chapter-list read or the AniSkip lookup), so a reload or duration change
|
||||||
|
// runs it again.
|
||||||
|
let retryResolution = false;
|
||||||
let windows: AniSkipWindows = { intro: null, outro: null };
|
let windows: AniSkipWindows = { intro: null, outro: null };
|
||||||
const promptShown: Record<SkipWindowKind, boolean> = { intro: false, outro: false };
|
const promptShown: Record<SkipWindowKind, boolean> = { intro: false, outro: false };
|
||||||
let boundButtonKey: string | null = null;
|
let boundButtonKey: string | null = null;
|
||||||
@@ -190,7 +192,7 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
|||||||
function clearState(): void {
|
function clearState(): void {
|
||||||
requestGeneration += 1;
|
requestGeneration += 1;
|
||||||
resolutionStarted = false;
|
resolutionStarted = false;
|
||||||
lastLookupFailed = false;
|
retryResolution = false;
|
||||||
windows = { intro: null, outro: null };
|
windows = { intro: null, outro: null };
|
||||||
promptShown.intro = false;
|
promptShown.intro = false;
|
||||||
promptShown.outro = false;
|
promptShown.outro = false;
|
||||||
@@ -277,8 +279,11 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
|||||||
const generation = requestGeneration;
|
const generation = requestGeneration;
|
||||||
const isStale = () => generation !== requestGeneration || mediaPath !== currentMediaPath;
|
const isStale = () => generation !== requestGeneration || mediaPath !== currentMediaPath;
|
||||||
|
|
||||||
const fromChapters = classifyChapterSkipIntervals(await readChapterList(), duration);
|
const chapterList = await readChapterList();
|
||||||
if (isStale()) return;
|
if (isStale()) return;
|
||||||
|
// A failed read is retried later; a successful empty list is a final answer.
|
||||||
|
if (chapterList === null) retryResolution = true;
|
||||||
|
const fromChapters = classifyChapterSkipIntervals(chapterList ?? [], duration);
|
||||||
const next: AniSkipWindows = {
|
const next: AniSkipWindows = {
|
||||||
intro: fromChapters.intro ? { ...fromChapters.intro, source: 'chapters' } : null,
|
intro: fromChapters.intro ? { ...fromChapters.intro, source: 'chapters' } : null,
|
||||||
outro: fromChapters.outro ? { ...fromChapters.outro, source: 'chapters' } : null,
|
outro: fromChapters.outro ? { ...fromChapters.outro, source: 'chapters' } : null,
|
||||||
@@ -293,7 +298,7 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
|||||||
|
|
||||||
const lookup = await lookUpAniSkip(mediaPath, duration, generation);
|
const lookup = await lookUpAniSkip(mediaPath, duration, generation);
|
||||||
if (isStale()) return;
|
if (isStale()) return;
|
||||||
lastLookupFailed = lookup === null;
|
if (lookup === null) retryResolution = true;
|
||||||
if (lookup) await mergeAniSkipWindows(lookup);
|
if (lookup) await mergeAniSkipWindows(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,14 +379,15 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
|||||||
function handleDurationChange({ duration }: { duration: number }): void {
|
function handleDurationChange({ duration }: { duration: number }): void {
|
||||||
if (!isUsableDuration(duration) || !currentMediaPath) return;
|
if (!isUsableDuration(duration) || !currentMediaPath) return;
|
||||||
currentDuration = duration;
|
currentDuration = duration;
|
||||||
|
if (retryResolution) clearState();
|
||||||
maybeStartResolution();
|
maybeStartResolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMediaPathChange({ path }: { path: string }): void {
|
function handleMediaPathChange({ path }: { path: string }): void {
|
||||||
const nextPath = typeof path === 'string' ? path : '';
|
const nextPath = typeof path === 'string' ? path : '';
|
||||||
if (nextPath === currentMediaPath && resolutionStarted) {
|
if (nextPath === currentMediaPath && resolutionStarted) {
|
||||||
if (lastLookupFailed) {
|
if (retryResolution) {
|
||||||
// The last lookup failed transiently; a reload is the retry.
|
// The last resolution failed transiently; a reload is the retry.
|
||||||
clearState();
|
clearState();
|
||||||
maybeStartResolution();
|
maybeStartResolution();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user