diff --git a/package.json b/package.json index 88b4c8f..a5498d0 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "angular": "^1.7.9", "angular-router-browserify": "0.0.2", "angular-vs-repeat": "2.0.13", + "random-js" : "2.1.0", "axios": "^0.19.2", "body-parser": "^1.19.0", "diskdb": "^0.1.17", diff --git a/src/helperFuncs.js b/src/helperFuncs.js index d232f42..e1708ad 100644 --- a/src/helperFuncs.js +++ b/src/helperFuncs.js @@ -6,6 +6,9 @@ module.exports = { let channelCache = require('./channel-cache'); const SLACK = require('./constants').SLACK; +const randomJS = require("random-js"); +const Random = randomJS.Random; +const random = new Random( randomJS.MersenneTwister19937.autoSeed() ); function getCurrentProgramAndTimeElapsed(date, channel) { let channelStartTime = (new Date(channel.startTime)).getTime(); @@ -102,7 +105,7 @@ function createLineup(obj, channel, fillers, isFirst) { //it's boring and odd to tune into a channel and it's always //the start of a commercial. let more = Math.max(0, filler.duration - fillerstart - 15000 - SLACK); - fillerstart += Math.floor(more * Math.random() ); + fillerstart += random.integer(0, more); } lineup.push({ // just add the video, starting at 0, playing the entire duration type: 'commercial', @@ -152,12 +155,7 @@ function createLineup(obj, channel, fillers, isFirst) { } function weighedPick(a, total) { - if (a==total) { - return true; - } else { - let ran = Math.random(); - return ran * total < a; - } + return random.bool(a, total); } function pickRandomWithMaxDuration(channel, fillers, maxDuration) { diff --git a/src/plexTranscoder.js b/src/plexTranscoder.js index 00663a1..11f3def 100644 --- a/src/plexTranscoder.js +++ b/src/plexTranscoder.js @@ -182,7 +182,7 @@ lang=en` try { return this.getVideoStats().videoDecision === "copy"; } catch (e) { - console.log("Error at decision:" + e); + console.log("Error at decision:", e); return false; } } @@ -199,7 +199,7 @@ lang=en` try { return this.getVideoStats().videoDecision === "copy" && this.getVideoStats().audioDecision === "copy"; } catch (e) { - console.log("Error at decision:" + e); + console.log("Error at decision:" , e); return false; } } @@ -245,7 +245,7 @@ lang=en` } }.bind(this) ) } catch (e) { - console.log("Error at decision:" + e); + console.log("Error at decision:" , e); } this.log("Current video stats:") @@ -313,7 +313,7 @@ lang=en` async getDecision(directPlay) { try { - this.getDecisionUnmanaged(directPlay); + await this.getDecisionUnmanaged(directPlay); } catch (err) { console.error(err); }