fix: backfill chapter end times for cached videos
Videos cached before the chapter end-time change would silently lack the 'end' field when loaded from cache. This adds a migration that detects missing 'end' fields on cache hit, computes them from adjacent chapters, and persists the updated meta.json. This ensures consistent output regardless of whether the data was freshly fetched or loaded from cache.
This commit is contained in:
parent
8d973f2bc5
commit
c7e32b4590
|
|
@ -699,6 +699,15 @@ async function processVideo(videoId: string, opts: Options): Promise<VideoResult
|
|||
sentences = loadSentences(videoDir);
|
||||
const wantLangs = opts.translate ? [opts.translate] : opts.languages;
|
||||
if (!wantLangs.includes(meta.language.code)) needsFetch = true;
|
||||
// Backfill chapter end times for caches created before this field existed
|
||||
if (meta.chapters.length > 0 && meta.chapters[0].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 + 1].start
|
||||
: meta.duration;
|
||||
}
|
||||
writeFileSync(join(videoDir, "meta.json"), JSON.stringify(meta, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (needsFetch) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue