From 7355b52dcd13421dc8b4afa90baf767fc98b2bd6 Mon Sep 17 00:00:00 2001 From: Chris Barbara Date: Sun, 16 Aug 2020 12:12:02 -0700 Subject: [PATCH] genre support for movies --- web/directives/plex-library.js | 2 +- web/public/templates/plex-library.html | 2 +- web/services/plex.js | 28 ++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/web/directives/plex-library.js b/web/directives/plex-library.js index 272d783..10f4e5f 100644 --- a/web/directives/plex-library.js +++ b/web/directives/plex-library.js @@ -104,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, scope.errors); + x.nested = await plex.getNested(scope.plexServer, x, isLibrary, scope.errors); } } scope.getNested = (list, isLibrary) => { diff --git a/web/public/templates/plex-library.html b/web/public/templates/plex-library.html index a95c9c1..5d0e7ae 100644 --- a/web/public/templates/plex-library.html +++ b/web/public/templates/plex-library.html @@ -57,7 +57,7 @@ - + diff --git a/web/services/plex.js b/web/services/plex.js index 381b3a5..dafef50 100644 --- a/web/services/plex.js +++ b/web/services/plex.js @@ -84,13 +84,29 @@ module.exports = function ($http, $window, $interval) { const res = await client.Get('/library/sections') var sections = [] for (let i = 0, l = typeof res.Directory !== 'undefined' ? res.Directory.length : 0; i < l; i++) - if (res.Directory[i].type === 'movie' || res.Directory[i].type === 'show') + if (res.Directory[i].type === 'movie' || res.Directory[i].type === 'show') { + var genres = [] + if (res.Directory[i].type === 'movie') { + const genresRes = await client.Get(`/library/sections/${res.Directory[i].key}/genre`) + for (let q = 0, k = typeof genresRes.Directory !== 'undefined' ? genresRes.Directory.length : 0; q < k; q++) { + if (genresRes.Directory[q].type === 'genre') { + genres.push({ + title: 'Genre: ' + genresRes.Directory[q].title, + key: genresRes.Directory[q].fastKey, + type: 'genre' + }) + } + } + } + sections.push({ title: res.Directory[i].title, key: `/library/sections/${res.Directory[i].key}/all`, icon: `${server.uri}${res.Directory[i].composite}?X-Plex-Token=${server.accessToken}`, - type: res.Directory[i].type + type: res.Directory[i].type, + genres: genres }) + } return sections }, getPlaylists: async (server) => { @@ -119,10 +135,14 @@ module.exports = function ($http, $window, $interval) { return streams }) }, - getNested: async (server, key, includeCollections, errors) => { + getNested: async (server, lib, includeCollections, errors) => { var client = new Plex(server) + const key = lib.key const res = await client.Get(key) var nested = [] + if (typeof (lib.genres) !== 'undefined') { + nested = Array.from(lib.genres) + } var seenFiles = {}; var collections = {}; for (let i = 0, l = typeof res.Metadata !== 'undefined' ? res.Metadata.length : 0; i < l; i++) { @@ -226,7 +246,7 @@ module.exports = function ($http, $window, $interval) { let shows = collection.nested; let collectionContents = []; for (let i = 0; i < shows.length; i++) { - let seasons = await exported.getNested(server, shows[i].key, false); + let seasons = await exported.getNested(server, shows[i], false); for (let j = 0; j < seasons.length; j++) { seasons[j].title = shows[i].title + " - " + seasons[j].title; collectionContents.push(seasons[j]);