Don't allow random time after 90% of video if no endcard submitted

This commit is contained in:
Ajay
2023-09-24 16:53:55 -04:00
parent 65e7d24b7d
commit ad666ff487
2 changed files with 12 additions and 4 deletions

View File

@@ -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));

View File

@@ -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;
}