From fe185234cfb88611c95411fd70474bfce08064d1 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 8 Jun 2023 18:05:40 -0400 Subject: [PATCH] Add fallback video duration when finding random timestamp --- src/routes/getBranding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/getBranding.ts b/src/routes/getBranding.ts index 8d23904..1201f50 100644 --- a/src/routes/getBranding.ts +++ b/src/routes/getBranding.ts @@ -221,7 +221,7 @@ export function findRandomTime(videoID: VideoID, segments: BrandingSegmentDBResu const randomTime = SeedRandom.alea(videoID)(); if (segments.length === 0) return randomTime; - const videoDuration = segments[0].videoDuration; + const videoDuration = segments[0].videoDuration || Math.max(...segments.map((s) => s.endTime)); // There are segments, treat this as a relative time in the chopped up video const sorted = segments.sort((a, b) => a.startTime - b.startTime);