mirror of
https://github.com/vexorian/dizquetv.git
synced 2025-12-10 00:28:08 -06:00
tem
This commit is contained in:
parent
44a2cd9b8b
commit
11cf105ea5
@ -163,10 +163,7 @@ class FillerDB {
|
||||
}
|
||||
|
||||
async getFillersFromChannel(channel) {
|
||||
let f = [];
|
||||
if (typeof(channel.fillerCollections) !== 'undefined') {
|
||||
f = channel.fillerContent;
|
||||
}
|
||||
|
||||
let loadChannelFiller = async(fillerEntry) => {
|
||||
let content = [];
|
||||
try {
|
||||
|
||||
@ -121,7 +121,7 @@ function createLineup(programPlayTime, obj, channel, fillers, isFirst) {
|
||||
if ( (channel.offlineMode === 'clip') && (channel.fallback.length != 0) ) {
|
||||
special = JSON.parse(JSON.stringify(channel.fallback[0]));
|
||||
}
|
||||
let randomResult = pickRandomWithMaxDuration(programPlayTime, channel, fillers, remaining + (isFirst? (7*24*60*60*1000) : 0) );
|
||||
let randomResult = pickRandomWithMaxDuration(programPlayTime, channel, fillers, remaining + (isFirst? (7*24*60*60*1000) : 0) , isFirst );
|
||||
filler = randomResult.filler;
|
||||
if (filler == null && (typeof(randomResult.minimumWait) !== undefined) && (remaining > randomResult.minimumWait) ) {
|
||||
remaining = randomResult.minimumWait;
|
||||
@ -137,8 +137,6 @@ function createLineup(programPlayTime, obj, channel, fillers, isFirst) {
|
||||
if (isSpecial) {
|
||||
if (filler.duration > remaining) {
|
||||
fillerstart = filler.duration - remaining;
|
||||
} else {
|
||||
ffillerstart = 0;
|
||||
}
|
||||
} else if(isFirst) {
|
||||
fillerstart = Math.max(0, filler.duration - remaining);
|
||||
@ -147,6 +145,7 @@ function createLineup(programPlayTime, obj, channel, fillers, isFirst) {
|
||||
let more = Math.max(0, filler.duration - fillerstart - 15000 - SLACK);
|
||||
fillerstart += random.integer(0, more);
|
||||
}
|
||||
console.log(`${remaining} ${filler.duration} ${isFirst} ${fillerstart}`);
|
||||
lineup.push({ // just add the video, starting at 0, playing the entire duration
|
||||
type: 'commercial',
|
||||
title: filler.title,
|
||||
@ -155,7 +154,7 @@ function createLineup(programPlayTime, obj, channel, fillers, isFirst) {
|
||||
file: filler.file,
|
||||
ratingKey: filler.ratingKey,
|
||||
start: fillerstart,
|
||||
streamDuration: Math.max(1, Math.min(filler.duration - fillerstart, remaining) ),
|
||||
streamDuration: Math.max(1, Math.min(filler.duration - fillerstart, remaining + SLACK ) ),
|
||||
duration: filler.duration,
|
||||
fillerId: filler.fillerId,
|
||||
beginningOffset: beginningOffset,
|
||||
@ -213,7 +212,7 @@ function weighedPick(a, total) {
|
||||
return random.bool(a, total);
|
||||
}
|
||||
|
||||
function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuration) {
|
||||
function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuration, isFirst) {
|
||||
let list = [];
|
||||
for (let i = 0; i < fillers.length; i++) {
|
||||
list = list.concat(fillers[i].content);
|
||||
@ -223,7 +222,14 @@ function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuratio
|
||||
let t0 = (new Date()).getTime();
|
||||
let minimumWait = 1000000000;
|
||||
const D = 7*24*60*60*1000;
|
||||
const E = 5*60*60*1000;
|
||||
|
||||
let minPick = null;
|
||||
let minPickN = 0;
|
||||
let minPickSet = 0;
|
||||
let minPickPlayTime = t0 + 1;
|
||||
let minPickFillerId = 0;
|
||||
let pickLastPlayed = null;
|
||||
|
||||
if (typeof(channel.fillerRepeatCooldown) === 'undefined') {
|
||||
channel.fillerRepeatCooldown = 30*60*1000;
|
||||
}
|
||||
@ -267,7 +273,7 @@ function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuratio
|
||||
minimumWait = Math.min(minimumWait, w);
|
||||
}
|
||||
timeSince = 0;
|
||||
//30 minutes is too little, don't repeat it at all
|
||||
//Can't pick from this filler list due to cooldown
|
||||
} else if (!pickedList) {
|
||||
let t1 = channelCache.getFillerLastPlayTime( channel.number, fillers[j].id );
|
||||
let timeSince = ( (t1 == 0) ? D : (t0 - t1) );
|
||||
@ -293,12 +299,26 @@ function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuratio
|
||||
if (timeSince <= 0) {
|
||||
continue;
|
||||
}
|
||||
let s = norm_s( (timeSince >= E) ? E : timeSince );
|
||||
minPickSet += 1;
|
||||
if (t1 < minPickPlayTime) {
|
||||
// new minimum
|
||||
minPickN = 0;
|
||||
minPickPlayTime = t1;
|
||||
}
|
||||
if (t1 == minPickPlayTime) {
|
||||
// tie
|
||||
minPickN += 1;
|
||||
if ( (minPickN == 1) || weighedPick(1,minPickN)) {
|
||||
minPick = clip;
|
||||
minPickFillerId = fillers[j].id;
|
||||
}
|
||||
}
|
||||
let d = norm_d( clip.duration);
|
||||
let w = s + d;
|
||||
let w = d;
|
||||
n += w;
|
||||
if (weighedPick(w,n)) {
|
||||
pick1 = clip;
|
||||
pickLastPlayed = t1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,6 +328,13 @@ function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuratio
|
||||
}
|
||||
}
|
||||
let pick = pick1;
|
||||
let Q = Math.max(30, Math.ceil(10* Math.log(minPickSet) / Math.log(2) ) );
|
||||
console.log( minPickPlayTime + " : " + Q + " ! " + pickLastPlayed );
|
||||
if (!isFirst && (minPick != null) && weighedPick(10,Q) ) {
|
||||
console.log( minPickPlayTime + " : " + minPickFillerId + " : " + JSON.stringify(minPick) );
|
||||
pick = minPick;
|
||||
pick.fillerId = minPickFillerId;
|
||||
}
|
||||
if (pick != null) {
|
||||
pick = JSON.parse( JSON.stringify(pick) );
|
||||
pick.fillerId = fillerId;
|
||||
@ -321,18 +348,7 @@ function pickRandomWithMaxDuration(programPlayTime, channel, fillers, maxDuratio
|
||||
}
|
||||
|
||||
function norm_d(x) {
|
||||
x /= 60 * 1000;
|
||||
if (x >= 3.0) {
|
||||
x = 3.0 + Math.log(x);
|
||||
}
|
||||
let y = 10000 * ( Math.ceil(x * 1000) + 1 );
|
||||
return Math.ceil(y / 1000000) + 1;
|
||||
}
|
||||
|
||||
function norm_s(x) {
|
||||
let y = Math.ceil(x / 600) + 1;
|
||||
y = y*y;
|
||||
return Math.ceil(y / 1000000) + 1;
|
||||
return 1 + Math.ceil( Math.log(x+1) / Math.log(2) )
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -332,9 +332,9 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
|
||||
if (typeof(u) !== 'undefined') {
|
||||
let u2 = upperBound;
|
||||
if ( typeof(lineupItem.streamDuration) !== 'undefined') {
|
||||
u2 = Math.min(u2, lineupItem.streamDuration);
|
||||
u2 = Math.min(u2 , lineupItem.streamDuration);
|
||||
}
|
||||
lineupItem.streamDuration = Math.min(u2, u);
|
||||
lineupItem.streamDuration = Math.min(lineupItem.streamDuration, Math.min(u2, u) + constants.SLACK);
|
||||
upperBound = lineupItem.streamDuration;
|
||||
}
|
||||
channelCache.recordPlayback( programPlayTimeDB, redirectChannels[i].number, t0, lineupItem );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user