mirror of
https://github.com/vexorian/dizquetv.git
synced 2025-12-10 00:28:08 -06:00
Use the median to decide what filler to play. This has memory consequences unfortunately.
This commit is contained in:
parent
2e3c0b63b2
commit
ad1302aae4
@ -1,6 +1,6 @@
|
||||
FROM node:12.18-alpine3.12
|
||||
WORKDIR /home/node/app
|
||||
COPY package*.json ./
|
||||
COPY package.json ./
|
||||
RUN npm install && npm install -g browserify nexe@3.3.7
|
||||
COPY --from=vexorian/dizquetv:nexecache /var/nexe/linux-x64-12.16.2 /var/nexe/
|
||||
COPY . .
|
||||
|
||||
@ -37,7 +37,8 @@
|
||||
"node-ssdp": "^4.0.0",
|
||||
"random-js": "2.1.0",
|
||||
"request": "^2.88.2",
|
||||
"uuid": "^8.0.0",
|
||||
"quickselect": "2.0.0",
|
||||
"uuid" : "9.0.1",
|
||||
"xml-writer": "^1.7.0"
|
||||
},
|
||||
"bin": "dist/index.js",
|
||||
|
||||
@ -8,6 +8,7 @@ module.exports = {
|
||||
let channelCache = require('./channel-cache');
|
||||
const SLACK = require('./constants').SLACK;
|
||||
const randomJS = require("random-js");
|
||||
const quickselect = require("quickselect");
|
||||
const Random = randomJS.Random;
|
||||
const random = new Random( randomJS.MersenneTwister19937.autoSeed() );
|
||||
|
||||
@ -194,7 +195,11 @@ function pickRandomWithMaxDuration(channel, fillers, maxDuration) {
|
||||
}
|
||||
let listM = 0;
|
||||
let fillerId = undefined;
|
||||
for (let j = 0; j < fillers.length; j++) {
|
||||
|
||||
let median = getMedian(channelCache, channel, fillers);
|
||||
|
||||
for (let medianCheck = 1; medianCheck >= 0; medianCheck--) {
|
||||
for (let j = 0; j < fillers.length; j++) {
|
||||
list = fillers[j].content;
|
||||
let pickedList = false;
|
||||
let n = 0;
|
||||
@ -204,6 +209,9 @@ function pickRandomWithMaxDuration(channel, fillers, maxDuration) {
|
||||
// a few extra milliseconds won't hurt anyone, would it? dun dun dun
|
||||
if (clip.duration <= maxDuration + SLACK ) {
|
||||
let t1 = channelCache.getProgramLastPlayTime( channel.number, clip );
|
||||
if ( (medianCheck==1) && (t1 > median) ) {
|
||||
continue;
|
||||
}
|
||||
let timeSince = ( (t1 == 0) ? D : (t0 - t1) );
|
||||
|
||||
if (timeSince < channel.fillerRepeatCooldown - SLACK) {
|
||||
@ -247,11 +255,13 @@ function pickRandomWithMaxDuration(channel, fillers, maxDuration) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pick1 != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let pick = pick1;
|
||||
let pickTitle = "null";
|
||||
if (pick != null) {
|
||||
pickTitle = pick.title;
|
||||
pick = JSON.parse( JSON.stringify(pick) );
|
||||
pick.fillerId = fillerId;
|
||||
}
|
||||
@ -322,6 +332,24 @@ function getWatermark( ffmpegSettings, channel, type) {
|
||||
}
|
||||
|
||||
|
||||
function getMedian(channelCache, channel, fillers) {
|
||||
let times = [];
|
||||
for (let j = 0; j < fillers.length; j++) {
|
||||
list = fillers[j].content;
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
let clip = list[i];
|
||||
let t = channelCache.getProgramLastPlayTime( channel.number, clip);
|
||||
times.push(t);
|
||||
}
|
||||
}
|
||||
if (times.length == 0) {
|
||||
return null;
|
||||
}
|
||||
quickselect(times, times.length / 2)
|
||||
return times[times.length / 2];
|
||||
|
||||
}
|
||||
|
||||
function generateChannelContext(channel) {
|
||||
let channelContext = {};
|
||||
for (let i = 0; i < CHANNEL_CONTEXT_KEYS.length; i++) {
|
||||
|
||||
13
src/video.js
13
src/video.js
@ -291,8 +291,17 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
|
||||
throw "No video to play, this means there's a serious unexpected bug or the channel db is corrupted."
|
||||
}
|
||||
let fillers = await fillerDB.getFillersFromChannel(brandChannel);
|
||||
let lineup = helperFuncs.createLineup(prog, brandChannel, fillers, isFirst)
|
||||
lineupItem = lineup.shift();
|
||||
try {
|
||||
let lineup = helperFuncs.createLineup(prog, brandChannel, fillers, isFirst)
|
||||
lineupItem = lineup.shift();
|
||||
} catch (err) {
|
||||
console.log("Error when attempting to pick video: " +err.stack);
|
||||
lineupItem = {
|
||||
isOffline: true,
|
||||
err: err,
|
||||
duration : 60000,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( !isBetween && !isLoading && (lineupItem != null) ) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user