Merge remote-tracking branch 'origin/dev/1.4.x' into dev/1.5.x

This commit is contained in:
vexorian 2021-09-19 16:53:19 -04:00
commit b2024479f2
10 changed files with 73 additions and 25 deletions

View File

@ -167,6 +167,10 @@ function recordPlayback(channelId, t0, lineupItem) {
}
}
function clearPlayback(channelId) {
delete cache[channelId];
}
function clear() {
//it's not necessary to clear the playback cache and it may be undesirable
configCache = {};
@ -184,4 +188,5 @@ module.exports = {
getChannelConfig: getChannelConfig,
saveChannelConfig: saveChannelConfig,
getFillerLastPlayTime: getFillerLastPlayTime,
clearPlayback: clearPlayback,
}

View File

@ -29,10 +29,8 @@ class ChannelDB {
}
async saveChannel(number, json) {
if (typeof(number) === 'undefined') {
throw Error("Mising channel number");
}
let f = path.join(this.folder, `${number}.json` );
await this.validateChannelJson(number, json);
let f = path.join(this.folder, `${json.number}.json` );
return await new Promise( (resolve, reject) => {
let data = undefined;
try {
@ -50,12 +48,30 @@ class ChannelDB {
}
saveChannelSync(number, json) {
json.number = number;
this.validateChannelJson(number, json);
let data = JSON.stringify(json);
let f = path.join(this.folder, `${number}.json` );
let f = path.join(this.folder, `${json.number}.json` );
fs.writeFileSync( f, data );
}
validateChannelJson(number, json) {
json.number = number;
if (typeof(json.number) === 'undefined') {
throw Error("Expected a channel.number");
}
if (typeof(json.number) === 'string') {
try {
json.number = parseInt(json.number);
} catch (err) {
console.error("Error parsing channel number.", err);
}
}
if ( isNaN(json.number)) {
throw Error("channel.number must be a integer");
}
}
async deleteChannel(number) {
let f = path.join(this.folder, `${number}.json` );
await new Promise( (resolve, reject) => {

View File

@ -135,7 +135,7 @@ class PlexServerDB
s = s[0];
let arGuide = server.arGuide;
if (typeof(arGuide) === 'undefined') {
arGuide = true;
arGuide = false;
}
let arChannels = server.arChannels;
if (typeof(arChannels) === 'undefined') {
@ -177,7 +177,7 @@ class PlexServerDB
name = resultName;
let arGuide = server.arGuide;
if (typeof(arGuide) === 'undefined') {
arGuide = true;
arGuide = false;
}
let arChannels = server.arGuide;
if (typeof(arChannels) === 'undefined') {

View File

@ -485,7 +485,7 @@ function splitServersSingleChannels(db, channelDB ) {
let saveServer = (name, uri, accessToken, arGuide, arChannels) => {
if (typeof(arGuide) === 'undefined') {
arGuide = true;
arGuide = false;
}
if (typeof(arChannels) === 'undefined') {
arChannels = false;

View File

@ -243,10 +243,7 @@ function pickRandomWithMaxDuration(channel, fillers, maxDuration) {
let w = s + d;
n += w;
if (weighedPick(w,n)) {
console.log(`${s} ${d} ${clip.title} picked `);
pick1 = clip;
} else {
console.log(`${s} ${d} ${clip.title} not picked `);
}
}
}

View File

@ -36,7 +36,15 @@ class TVGuideService extends events.EventEmitter
let t = (new Date()).getTime();
this.updateTime = t;
this.updateLimit = t + limit;
let channels = inputChannels;
let channels = [];
for (let i = 0; i < inputChannels.length; i++) {
if (typeof(inputChannels[i]) !== 'undefined') {
channels.push(inputChannels[i]);
} else {
console.error(`There is an issue with one of the channels provided to TV-guide service, it will be ignored: ${i}` );
}
}
this.updateChannels = channels;
return t;
}

View File

@ -2,11 +2,11 @@ const express = require('express')
const helperFuncs = require('./helperFuncs')
const FFMPEG = require('./ffmpeg')
const FFMPEG_TEXT = require('./ffmpegText')
const constants = require('./constants')
const fs = require('fs')
const ProgramPlayer = require('./program-player');
const channelCache = require('./channel-cache')
const wereThereTooManyAttempts = require('./throttler');
const constants = require('./constants');
module.exports = { router: video, shutdown: shutdown }
@ -131,7 +131,7 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
} );
// Stream individual video to ffmpeg concat above. This is used by the server, NOT the client
router.get('/stream', async (req, res) => {
let streamFunction = async (req, res, t0, allowSkip) => {
if (stopPlayback) {
res.status(503).send("Server is shutting down.")
return;
@ -180,7 +180,6 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
// Get video lineup (array of video urls with calculated start times and durations.)
let t0 = (new Date()).getTime();
let lineupItem = channelCache.getCurrentLineupItem( channel.number, t0);
let prog = null;
let brandChannel = channel;
@ -261,12 +260,15 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
duration: t,
isOffline : true,
};
} else if (prog.program.isOffline && prog.program.duration - prog.timeElapsed <= 10000) {
} else if ( allowSkip && (prog.program.isOffline && prog.program.duration - prog.timeElapsed <= constants.SLACK + 1) ) {
//it's pointless to show the offline screen for such a short time, might as well
//skip to the next program
prog.programIndex = (prog.programIndex + 1) % channel.programs.length;
prog.program = channel.programs[prog.programIndex ];
prog.timeElapsed = 0;
let dt = prog.program.duration - prog.timeElapsed;
for (let i = 0; i < redirectChannels.length; i++) {
channelCache.clearPlayback(redirectChannels[i].number );
}
console.log("Too litlle time before the filler ends, skip to next slot");
return await streamFunction(req, res, t0 + dt + 1, false);
}
if ( (prog == null) || (typeof(prog) === 'undefined') || (prog.program == null) || (typeof(prog.program) == "undefined") ) {
throw "No video to play, this means there's a serious unexpected bug or the channel db is corrupted."
@ -443,6 +445,11 @@ function video( channelService, fillerDB, db, programmingService, activeChannelS
console.log("Client Closed");
stop();
});
};
router.get('/stream', async (req, res) => {
let t0 = (new Date).getTime();
return await streamFunction(req, res, t0, true);
});

View File

@ -989,7 +989,7 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions, get
scope.error.any = true;
if (typeof channel.number === "undefined" || channel.number === null || channel.number === "") {
if (typeof channel.number === "undefined" || channel.number === null || channel.number === "" ) {
scope.error.number = "Select a channel number"
scope.error.tab = "basic";
} else if (channelNumbers.indexOf(parseInt(channel.number, 10)) !== -1 && scope.isNewChannel) { // we need the parseInt for indexOf to work properly
@ -998,6 +998,9 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions, get
} else if (!scope.isNewChannel && channel.number !== scope.beforeEditChannelNumber && channelNumbers.indexOf(parseInt(channel.number, 10)) !== -1) {
scope.error.number = "Channel number already in use."
scope.error.tab = "basic";
} else if ( ! checkChannelNumber(channel.number) ) {
scope.error.number = "Invalid channel number.";
scope.error.tab = "basic";
} else if (channel.number < 0 || channel.number > 9999) {
scope.error.name = "Enter a valid number (0-9999)"
scope.error.tab = "basic";
@ -1706,3 +1709,12 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions, get
function validURL(url) {
return /^(ftp|http|https):\/\/[^ "]+$/.test(url);
}
function checkChannelNumber(number) {
if ( /^[1-9][0-9]+$/.test(number) ) {
let x = parseInt(number);
return (0 <= x && x < 10000);
} else {
return false;
}
}

View File

@ -192,7 +192,7 @@ module.exports = function (plex, dizquetv, $timeout) {
accessToken: server.accessToken,
}
}
connection.arGuide = true
connection.arGuide = false
connection.arChannels = false // should not be enabled unless dizqueTV tuner already added to plex
await dizquetv.addPlexServer(connection);
} catch (err) {

View File

@ -286,9 +286,12 @@ module.exports = function ($http, $window, $interval) {
if ( (includeCollections === true) && (res.viewGroup !== "artist" ) ) {
let k = res.librarySectionID;
k = `/library/sections/${k}/collection`;
k = `/library/sections/${k}/collections`;
let collections = await client.Get(k);
let directories = collections.Directory;
if ( typeof(collections.Metadata) === 'undefined') {
collections.Metadata = [];
}
let directories = collections.Metadata;
let nestedCollections = [];
for (let i = 0; i < directories.length; i++) {
let title;
@ -299,7 +302,7 @@ module.exports = function ($http, $window, $interval) {
}
nestedCollections.push( {
key : directories[i].fastKey,
key : directories[i].key,
title : title,
type: "collection",
collectionType : res.viewGroup,