From f53af25e65282880d24fdee83825df596e6828c1 Mon Sep 17 00:00:00 2001 From: jzocb Date: Sun, 22 Mar 2026 16:07:05 -0400 Subject: [PATCH] fix: address review feedback on chapter end times - Guard last chapter end against duration=0: use Math.max(duration, ch.start) - Remove unnecessary 'as any' cast in backfill - Check all chapters for missing end (not just first) via .some() - Skip backfill when needsFetch is true (about to refetch anyway) - Wrap backfill writeFileSync in try/catch (best-effort persistence) --- skills/baoyu-youtube-transcript/scripts/main.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/skills/baoyu-youtube-transcript/scripts/main.ts b/skills/baoyu-youtube-transcript/scripts/main.ts index d1ba3d9..3e618e7 100644 --- a/skills/baoyu-youtube-transcript/scripts/main.ts +++ b/skills/baoyu-youtube-transcript/scripts/main.ts @@ -263,7 +263,7 @@ function parseChapters(description: string, duration: number = 0): Chapter[] { return raw.map((ch, i) => ({ title: ch.title, start: ch.start, - end: i < raw.length - 1 ? raw[i + 1].start : duration, + end: i < raw.length - 1 ? raw[i + 1].start : Math.max(duration, ch.start), })); } @@ -700,13 +700,13 @@ async function processVideo(videoId: string, opts: Options): Promise 0 && meta.chapters[0].end === undefined) { + if (!needsFetch && meta.chapters.length > 0 && meta.chapters.some((ch: any) => ch.end === undefined)) { for (let i = 0; i < meta.chapters.length; i++) { - (meta.chapters[i] as any).end = i < meta.chapters.length - 1 + meta.chapters[i].end = i < meta.chapters.length - 1 ? meta.chapters[i + 1].start - : meta.duration; + : Math.max(meta.duration, meta.chapters[i].start); } - writeFileSync(join(videoDir, "meta.json"), JSON.stringify(meta, null, 2)); + try { writeFileSync(join(videoDir, "meta.json"), JSON.stringify(meta, null, 2)); } catch {} } }