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.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;
|
||||
// True once resolution for the current media has started (or finished).
|
||||
let resolutionStarted = false;
|
||||
// True when the last AniSkip lookup for the current media failed in a retryable way.
|
||||
let lastLookupFailed = false;
|
||||
// True when resolution for the current media hit a retryable failure (the
|
||||
// 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 };
|
||||
const promptShown: Record<SkipWindowKind, boolean> = { intro: false, outro: false };
|
||||
let boundButtonKey: string | null = null;
|
||||
@@ -190,7 +192,7 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
||||
function clearState(): void {
|
||||
requestGeneration += 1;
|
||||
resolutionStarted = false;
|
||||
lastLookupFailed = false;
|
||||
retryResolution = false;
|
||||
windows = { intro: null, outro: null };
|
||||
promptShown.intro = false;
|
||||
promptShown.outro = false;
|
||||
@@ -277,8 +279,11 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
||||
const generation = requestGeneration;
|
||||
const isStale = () => generation !== requestGeneration || mediaPath !== currentMediaPath;
|
||||
|
||||
const fromChapters = classifyChapterSkipIntervals(await readChapterList(), duration);
|
||||
const chapterList = await readChapterList();
|
||||
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 = {
|
||||
intro: fromChapters.intro ? { ...fromChapters.intro, 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);
|
||||
if (isStale()) return;
|
||||
lastLookupFailed = lookup === null;
|
||||
if (lookup === null) retryResolution = true;
|
||||
if (lookup) await mergeAniSkipWindows(lookup);
|
||||
}
|
||||
|
||||
@@ -374,14 +379,15 @@ export function createAniSkipRuntime(deps: AniSkipRuntimeDeps) {
|
||||
function handleDurationChange({ duration }: { duration: number }): void {
|
||||
if (!isUsableDuration(duration) || !currentMediaPath) return;
|
||||
currentDuration = duration;
|
||||
if (retryResolution) clearState();
|
||||
maybeStartResolution();
|
||||
}
|
||||
|
||||
function handleMediaPathChange({ path }: { path: string }): void {
|
||||
const nextPath = typeof path === 'string' ? path : '';
|
||||
if (nextPath === currentMediaPath && resolutionStarted) {
|
||||
if (lastLookupFailed) {
|
||||
// The last lookup failed transiently; a reload is the retry.
|
||||
if (retryResolution) {
|
||||
// The last resolution failed transiently; a reload is the retry.
|
||||
clearState();
|
||||
maybeStartResolution();
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user