Skip to content

Commit ad666ff

Browse files
committed
Don't allow random time after 90% of video if no endcard submitted
1 parent 65e7d24 commit ad666ff

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/routes/getBranding.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service:
4242

4343
const getSegments = () => db.prepare(
4444
"all",
45-
`SELECT "startTime", "endTime", "videoDuration" FROM "sponsorTimes"
45+
`SELECT "startTime", "endTime", "category", "videoDuration" FROM "sponsorTimes"
4646
WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "videoID" = ? AND "service" = ?`,
4747
[videoID, service],
4848
{ useReplica: true }
@@ -106,7 +106,7 @@ export async function getVideoBrandingByHash(videoHashPrefix: VideoIDHash, servi
106106

107107
const getSegments = () => db.prepare(
108108
"all",
109-
`SELECT "videoID", "startTime", "endTime", "videoDuration" FROM "sponsorTimes"
109+
`SELECT "videoID", "startTime", "endTime", "category", "videoDuration" FROM "sponsorTimes"
110110
WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "hashedVideoID" LIKE ? AND "service" = ?`,
111111
[`${videoHashPrefix}%`, service],
112112
{ useReplica: true }
@@ -227,7 +227,13 @@ async function shouldKeepSubmission(submissions: BrandingDBSubmission[], type: B
227227
}
228228

229229
export function findRandomTime(videoID: VideoID, segments: BrandingSegmentDBResult[]): number {
230-
const randomTime = SeedRandom.alea(videoID)();
230+
let randomTime = SeedRandom.alea(videoID)();
231+
232+
// Don't allow random times past 90% of the video if no endcard
233+
if (!segments.some((s) => s.category === "outro") && randomTime > 0.9) {
234+
randomTime -= 0.9;
235+
}
236+
231237
if (segments.length === 0) return randomTime;
232238

233239
const videoDuration = segments[0].videoDuration || Math.max(...segments.map((s) => s.endTime));

src/types/branding.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Service, VideoID, VideoIDHash } from "./segments.model";
1+
import { Category, Service, VideoID, VideoIDHash } from "./segments.model";
22
import { UserID } from "./user.model";
33

44
export type BrandingUUID = string & { readonly __brandingUUID: unique symbol };
@@ -88,11 +88,13 @@ export interface BrandingSubmission {
8888
export interface BrandingSegmentDBResult {
8989
startTime: number;
9090
endTime: number;
91+
category: Category;
9192
videoDuration: number;
9293
}
9394

9495
export interface BrandingSegmentHashDBResult extends BrandingDBSubmissionData {
9596
startTime: number;
9697
endTime: number;
98+
category: Category;
9799
videoDuration: number;
98100
}

0 commit comments

Comments
 (0)