diff --git a/src/tv-guide-service.js b/src/tv-guide-service.js index 841f6b6..8d69b41 100644 --- a/src/tv-guide-service.js +++ b/src/tv-guide-service.js @@ -167,6 +167,7 @@ class TVGuideService let x = await this.getChannelPlaying(channel, undefined, t0); if (x.program.duration == 0) throw Error("A " + channel.name + " " + JSON.stringify(x) ); + let melded = 0; let push = async (x) => { await this._throttle(); @@ -181,18 +182,26 @@ class TVGuideService //meld with previous let y = clone( programs[ programs.length - 1] ); y.program.duration += x.program.duration; - programs[ programs.length - 1] = y; - } else if (isProgramFlex(x.program) ) { - if (programs.length > 0) { - let y = programs[ programs.length - 1]; - let a = y.start; - let b = a + y.program.duration; - let a2 = x.start; - if (b > a2) { - throw Error( [ "darn0", b, a2, JSON.stringify(y) , JSON.stringify(x) ] ); - } + melded += x.program.duration; + if ( + (melded > constants.TVGUIDE_MAXIMUM_PADDING_LENGTH_MS) + && !isProgramFlex(programs[ programs.length - 1].program) + ) { + y.program.duration -= melded; + programs[ programs.length - 1] = y; + programs.push( { + start: y.start + y.program.duration, + program: { + isOffline : true, + duration: melded, + }, + } ); + melded = 0; + } else { + programs[ programs.length - 1] = y; } - + } else if (isProgramFlex(x.program) ) { + melded = 0; programs.push( { start: x.start, program: { @@ -201,15 +210,7 @@ class TVGuideService }, } ); } else { - if (programs.length > 0) { - let y = programs[ programs.length - 1]; - let a = y.start; - let b = a + y.program.duration; - let a2 = x.start; - if (b > a2) { - throw Error( [ "darn", b, a2, JSON.stringify(y) , JSON.stringify(x) ] ); - } - } + melded = 0; programs.push(x); } }; @@ -249,18 +250,7 @@ class TVGuideService result.programs.push( makeEntry(channel,x) ); } } else { - if (i > 0) { - let y = programs[ i - 1]; - let x = programs[i]; - let a = y.start; - let b = a + y.program.duration; - let a2 = x.start; - if (b > a2) { - console.error( "darn2", b, a2 ); - } - - } - result.programs.push( makeEntry(channel, programs[i] ) ); + result.programs.push( makeEntry(channel, programs[i] ) ); } } diff --git a/src/video.js b/src/video.js index 5e80f3d..0468820 100644 --- a/src/video.js +++ b/src/video.js @@ -158,8 +158,8 @@ function video( channelDB , db) { if (isLoading) { lineupItem = { type: 'loading', - streamDuration: 1000, - duration: 1000, + streamDuration: 40, + duration: 40, start: 0, }; } else if (lineupItem == null) { diff --git a/web/controllers/guide.js b/web/controllers/guide.js index f1594f4..1cbbb75 100644 --- a/web/controllers/guide.js +++ b/web/controllers/guide.js @@ -11,6 +11,7 @@ module.exports = function ($scope, $timeout, dizquetv) { $scope.enableBack = false; $scope.showNow = false; $scope.nowPosition = 0; + $scope.refreshHandle = null; const intl = new Intl.DateTimeFormat('default', { @@ -146,8 +147,26 @@ module.exports = function ($scope, $timeout, dizquetv) { $scope.enableBack = false; $scope.enableNext = false; await Promise.all($scope.channelNumbers.map( $scope.loadChannel) ); + setupTimer(); }; + let cancelTimerIfExists = () => { + if ($scope.refreshHandle != null) { + $timeout.cancel($scope.refreshHandle); + } + } + + $scope.$on('$locationChangeStart', () => { + console.log("$locationChangeStart" ); + cancelTimerIfExists(); + } ); + + + let setupTimer = () => { + cancelTimerIfExists(); + $scope.refreshHandle = $timeout( () => $scope.checkUpdates(), 60000 ); + } + $scope.adjustZoom = async() => { switch ($scope.zoomLevel) { case 1: @@ -310,8 +329,6 @@ module.exports = function ($scope, $timeout, dizquetv) { } $scope.channels[number] = ch; $scope.applyLater(); - $timeout( () => $scope.checkUpdates(), 60000 ); - } @@ -327,12 +344,13 @@ module.exports = function ($scope, $timeout, dizquetv) { $scope.checkUpdates = async () => { try { + console.log("get status " + new Date() ); let status = await dizquetv.getGuideStatus(); let t = new Date(status.lastUpdate).getTime(); if ( t > $scope.lastUpdate) { $scope.refreshManaged(); } else { - $timeout( () => $scope.checkUpdates(), 60000 ); + setupTimer(); } } catch(err) { console.error(err); diff --git a/web/directives/offline-config.js b/web/directives/offline-config.js index 7b7ff73..48f6e25 100644 --- a/web/directives/offline-config.js +++ b/web/directives/offline-config.js @@ -33,6 +33,9 @@ module.exports = function ($timeout) { scope.onDone(JSON.parse(angular.toJson(prog))) scope.program = null } + scope.showList = () => { + return ! scope.showPlexLibrary && ! scope.showFallbackPlexLibrary; + } scope.sortFillers = () => { scope.program.filler.sort( (a,b) => { return a.duration - b.duration } ); } @@ -60,6 +63,7 @@ module.exports = function ($timeout) { selectedPrograms[i].commercials = [] } scope.program.filler = scope.program.filler.concat(selectedPrograms); + scope.showPlexLibrary = false; } scope.importFallback = (selectedPrograms) => { @@ -70,6 +74,7 @@ module.exports = function ($timeout) { if (selectedPrograms.length > 0) { scope.program.fallback = [ selectedPrograms[0] ]; } + scope.showFallbackPlexLibrary = false; } diff --git a/web/public/templates/offline-config.html b/web/public/templates/offline-config.html index 69d27a7..2c29eb2 100644 --- a/web/public/templates/offline-config.html +++ b/web/public/templates/offline-config.html @@ -138,7 +138,7 @@
Click the to import filler content from your Plex server(s).