From d7bd6b0d131a14563745c12be27042b91e9517c2 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sat, 6 May 2017 09:45:21 +0200 Subject: [PATCH] Function to grab all Plex libraries from PMS --- resources/lib/PlexFunctions.py | 39 ++++------------------------------ resources/lib/librarysync.py | 8 +++---- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index 82e54cad..e6e9954e 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -258,43 +258,12 @@ def GetPlexOnDeck(viewId): return DownloadChunks("{server}/library/sections/%s/onDeck?" % viewId) -def GetPlexCollections(mediatype): +def get_plex_sections(): """ - Input: - mediatype String or list of strings with possible values - 'movie', 'show', 'artist', 'photo' - Output: - List with an entry of the form: - { - 'name': xxx Plex title for the media section - 'type': xxx Plex type: 'movie', 'show', 'artist', 'photo' - 'id': xxx Plex unique key for the section (1, 2, 3...) - 'uuid': xxx Other unique Plex key, e.g. - 74aec9f2-a312-4723-9436-de2ea43843c1 - } - Returns an empty list if nothing is found. + Returns all Plex sections (libraries) of the PMS as an etree xml """ - collections = [] - url = "{server}/library/sections" - xml = downloadutils.DownloadUtils().downloadUrl(url) - try: - xml.attrib - except AttributeError: - log.error('Could not download PMS sections for %s' % url) - return {} - for item in xml: - contentType = item['type'] - if contentType in mediatype: - name = item['title'] - contentId = item['key'] - uuid = item['uuid'] - collections.append({ - 'name': name, - 'type': contentType, - 'id': str(contentId), - 'uuid': uuid - }) - return collections + return downloadutils.DownloadUtils().downloadUrl( + '{server}/library/sections') def init_plex_playqueue(itemid, librarySectionUUID, mediatype='movie', diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 017e4cf9..c736317c 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -23,7 +23,7 @@ import videonodes import variables as v from PlexFunctions import GetPlexMetadata, GetAllPlexLeaves, scrobble, \ - GetPlexSectionResults, GetAllPlexChildren, GetPMSStatus + GetPlexSectionResults, GetAllPlexChildren, GetPMSStatus, get_plex_sections import PlexAPI from library_sync.get_metadata import Threaded_Get_Metadata from library_sync.process_metadata import Threaded_Process_Metadata @@ -126,8 +126,7 @@ class LibrarySync(Thread): # change in lastViewedAt # Get all Plex libraries - sections = downloadutils.DownloadUtils().downloadUrl( - "{server}/library/sections") + sections = get_plex_sections() try: sections.attrib except AttributeError: @@ -477,8 +476,7 @@ class LibrarySync(Thread): vnodes = self.vnodes # Get views - sections = downloadutils.DownloadUtils().downloadUrl( - "{server}/library/sections") + sections = get_plex_sections() try: sections.attrib except AttributeError: