@@ -42,7 +42,7 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service:
42
42
43
43
const getSegments = ( ) => db . prepare (
44
44
"all" ,
45
- `SELECT "startTime", "endTime", "videoDuration" FROM "sponsorTimes"
45
+ `SELECT "startTime", "endTime", "category", " videoDuration" FROM "sponsorTimes"
46
46
WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "videoID" = ? AND "service" = ?` ,
47
47
[ videoID , service ] ,
48
48
{ useReplica : true }
@@ -106,7 +106,7 @@ export async function getVideoBrandingByHash(videoHashPrefix: VideoIDHash, servi
106
106
107
107
const getSegments = ( ) => db . prepare (
108
108
"all" ,
109
- `SELECT "videoID", "startTime", "endTime", "videoDuration" FROM "sponsorTimes"
109
+ `SELECT "videoID", "startTime", "endTime", "category", " videoDuration" FROM "sponsorTimes"
110
110
WHERE "votes" > -2 AND "shadowHidden" = 0 AND "hidden" = 0 AND "actionType" = 'skip' AND "hashedVideoID" LIKE ? AND "service" = ?` ,
111
111
[ `${ videoHashPrefix } %` , service ] ,
112
112
{ useReplica : true }
@@ -227,7 +227,13 @@ async function shouldKeepSubmission(submissions: BrandingDBSubmission[], type: B
227
227
}
228
228
229
229
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
+
231
237
if ( segments . length === 0 ) return randomTime ;
232
238
233
239
const videoDuration = segments [ 0 ] . videoDuration || Math . max ( ...segments . map ( ( s ) => s . endTime ) ) ;
0 commit comments