commit
542d42cb76
@ -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) => {
|
||||
|
||||
@ -134,7 +134,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') {
|
||||
@ -176,7 +176,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') {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -11,6 +11,7 @@ class TVGuideService
|
||||
constructor(xmltv, db, cacheImageService, eventService) {
|
||||
this.cached = null;
|
||||
this.lastUpdate = 0;
|
||||
this.lastBackoff = 100;
|
||||
this.updateTime = 0;
|
||||
this.currentUpdate = -1;
|
||||
this.currentLimit = -1;
|
||||
@ -34,7 +35,15 @@ class TVGuideService
|
||||
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;
|
||||
}
|
||||
@ -345,10 +354,13 @@ class TVGuideService
|
||||
this.cached = await this.buildItManaged();
|
||||
console.log("Internal TV Guide data refreshed at " + (new Date()).toLocaleString() );
|
||||
await this.refreshXML();
|
||||
this.lastBackoff = 100;
|
||||
} catch(err) {
|
||||
console.error("Unable to update internal guide data", err);
|
||||
await _wait(100);
|
||||
console.error("Retrying TV guide...");
|
||||
let w = Math.min(this.lastBackoff * 2, 300000);
|
||||
await _wait(w);
|
||||
this.lastBackoff = w;
|
||||
console.error(`Retrying TV guide after ${w} milliseconds wait...`);
|
||||
await this.buildIt();
|
||||
|
||||
} finally {
|
||||
|
||||
@ -953,7 +953,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
|
||||
@ -962,6 +962,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";
|
||||
@ -1670,3 +1673,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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user