From ad666ff48707bf68483ef8f096bfe5a67ba4b49b Mon Sep 17 00:00:00 2001 From: Ajay Date: Sun, 24 Sep 2023 16:53:55 -0400 Subject: [PATCH] Don't allow random time after 90% of video if no endcard submitted --- src/routes/getBranding.ts | 12 +++++++++--- src/types/branding.model.ts | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/routes/getBranding.ts b/src/routes/getBranding.ts index 23d220d..b832f3e 100644 --- a/src/routes/getBranding.ts +++ b/src/routes/getBranding.ts @@ -42,7 +42,7 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service: const getSegments = () => db.prepare( "all", - `SELECT "startTime", "endTime", "videoDuration" FROM "sponsorTimes" + `SELECT "startTime", "endTime", "category", "videoDuration" FROM "sponsorTimes" WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "videoID" = ? AND "service" = ?`, [videoID, service], { useReplica: true } @@ -106,7 +106,7 @@ export async function getVideoBrandingByHash(videoHashPrefix: VideoIDHash, servi const getSegments = () => db.prepare( "all", - `SELECT "videoID", "startTime", "endTime", "videoDuration" FROM "sponsorTimes" + `SELECT "videoID", "startTime", "endTime", "category", "videoDuration" FROM "sponsorTimes" WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "hashedVideoID" LIKE ? AND "service" = ?`, [`${videoHashPrefix}%`, service], { useReplica: true } @@ -227,7 +227,13 @@ async function shouldKeepSubmission(submissions: BrandingDBSubmission[], type: B } export function findRandomTime(videoID: VideoID, segments: BrandingSegmentDBResult[]): number { - const randomTime = SeedRandom.alea(videoID)(); + let randomTime = SeedRandom.alea(videoID)(); + + // Don't allow random times past 90% of the video if no endcard + if (!segments.some((s) => s.category === "outro") && randomTime > 0.9) { + randomTime -= 0.9; + } + if (segments.length === 0) return randomTime; const videoDuration = segments[0].videoDuration || Math.max(...segments.map((s) => s.endTime)); diff --git a/src/types/branding.model.ts b/src/types/branding.model.ts index faf08f7..db0e289 100644 --- a/src/types/branding.model.ts +++ b/src/types/branding.model.ts @@ -1,4 +1,4 @@ -import { Service, VideoID, VideoIDHash } from "./segments.model"; +import { Category, Service, VideoID, VideoIDHash } from "./segments.model"; import { UserID } from "./user.model"; export type BrandingUUID = string & { readonly __brandingUUID: unique symbol }; @@ -88,11 +88,13 @@ export interface BrandingSubmission { export interface BrandingSegmentDBResult { startTime: number; endTime: number; + category: Category; videoDuration: number; } export interface BrandingSegmentHashDBResult extends BrandingDBSubmissionData { startTime: number; endTime: number; + category: Category; videoDuration: number; } \ No newline at end of file