Made the library browser more reslient, hopefully errors won't cut the loading of programs but they will be reported in the page.

This commit is contained in:
vexorian 2020-08-15 18:23:31 -04:00
parent 01494250e9
commit 52f9b20764
3 changed files with 16 additions and 3 deletions

View File

@ -10,6 +10,7 @@ module.exports = function (plex, dizquetv, $timeout) {
limit: "@limit",
},
link: function (scope, element, attrs) {
scope.errors=[];
if ( typeof(scope.limit) == 'undefined') {
scope.limit = 1000000000;
}
@ -45,8 +46,12 @@ module.exports = function (plex, dizquetv, $timeout) {
await scope.wait(0);
scope.pending += 1;
try {
item.streams = await plex.getStreams(scope.plexServer, item.key)
item.streams = await plex.getStreams(scope.plexServer, item.key, scope.errors)
scope.selection.push(JSON.parse(angular.toJson(item)))
} catch (err) {
let msg = "Unable to add item: " + item.key + " " + item.title;
scope.errors.push(msg);
console.error(msg, err);
} finally {
scope.pending -= 1;
}
@ -99,7 +104,7 @@ module.exports = function (plex, dizquetv, $timeout) {
}
scope.fillNestedIfNecessary = async (x, isLibrary) => {
if ( (typeof(x.nested) === 'undefined') && (x.type !== 'collection') ) {
x.nested = await plex.getNested(scope.plexServer, x.key, isLibrary);
x.nested = await plex.getNested(scope.plexServer, x.key, isLibrary, scope.errors);
}
}
scope.getNested = (list, isLibrary) => {

View File

@ -107,6 +107,8 @@
<div class="loader" ng-if="pending &gt; 0" ></div> <h6 style='display:inline-block'>Selected Items</h6>
<div class="text-info small" ng-show='selection.length &gt; 10'>{{ selection.length }} elements added in total. Only the last 10 elements are displayed:</div>
<div class="text-danger small" ng-repeat="e in errors track by $index">{{ e }}</div>
<ul class="list-group list-group-root" style="height: 180px; overflow-y: scroll" dnd-list="selection" scroll-glue>
<div ng-if="selection.length === 0">Select media items from your plex library above.</div>
<li ng-if="selection.length + x &gt;= 0" class="list-group-item" ng-repeat="x in allowedIndexes" style="cursor:default;" dnd-draggable="x" dnd-moved="selection.splice(selection.length + x, 1)" dnd-effect-allowed="move">

View File

@ -119,13 +119,14 @@ module.exports = function ($http, $window, $interval) {
return streams
})
},
getNested: async (server, key, includeCollections) => {
getNested: async (server, key, includeCollections, errors) => {
var client = new Plex(server)
const res = await client.Get(key)
var nested = []
var seenFiles = {};
var collections = {};
for (let i = 0, l = typeof res.Metadata !== 'undefined' ? res.Metadata.length : 0; i < l; i++) {
try {
// Skip any videos (movie or episode) without a duration set...
if (typeof res.Metadata[i].duration === 'undefined' && (res.Metadata[i].type === "episode" || res.Metadata[i].type === "movie"))
continue
@ -194,6 +195,11 @@ module.exports = function ($http, $window, $interval) {
}
}
nested.push(program)
} catch(err) {
let msg = "Error when attempting to read nested data for " + key + " " + res.Metadata[i].title;
errors.push(msg);
console.error(msg , err);
}
}
if (includeCollections === true) {
let nestedCollections = [];