From 4cdf5c3c4d1db53825dee016b31f0d787f221ae3 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 1 Mar 2016 18:00:19 -0600 Subject: [PATCH] Fix grouped views Something changed in the emby returned paths so the verification was failing. For now, we are getting one item from the media folder and comparing using the user view to make sure we are referring to the correct one with the tag name. Asked Luke for an api that would do this. --- resources/lib/librarysync.py | 33 +++++++++++++++++++++++--------- resources/lib/read_embyserver.py | 26 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 26b0bf24..e25f36b1 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -366,6 +366,7 @@ class LibrarySync(threading.Thread): log = self.logMsg # Compare the views to emby + emby = self.emby emby_db = embydb.Embydb_Functions(embycursor) kodi_db = kodidb.Kodidb_Functions(kodicursor) doUtils = self.doUtils @@ -404,7 +405,7 @@ class LibrarySync(threading.Thread): nodes = [] # Prevent duplicate for nodes of the same type playlists = [] # Prevent duplicate for playlists of the same type # Get media folders from server - folders = self.emby.getViews(mediatype, root=True) + folders = emby.getViews(mediatype, root=True) for folder in folders: folderid = folder['id'] @@ -413,14 +414,28 @@ class LibrarySync(threading.Thread): if folderid in groupedFolders: # Media folders are grouped into userview - for grouped_view in grouped_views: - # This is only reserved for the detection of grouped views - if (grouped_view['Type'] == "UserView" and - grouped_view.get('CollectionType') == mediatype and - grouped_view['Id'] in grouped_view.get('Path', "")): - # Take the name of the userview - foldername = grouped_view['Name'] - break + url = "{server}/emby/Users/{UserId}/Items?format=json" + params = { + 'ParentId': folderid, + 'Limit': 1 + } # Get one item from server using the folderid + result = doUtils(url, parameters=params) + try: + verifyitem = result['Items'][0]['Id'] + except (TypeError, IndexError): + # Something is wrong. Keep the same folder name. + # Could be the view is empty or the connection + pass + else: + for grouped_view in grouped_views: + # This is only reserved for the detection of grouped views + if (grouped_view['Type'] == "UserView" and + grouped_view.get('CollectionType') == mediatype): + # Take the userview, and validate the item belong to the view + if emby.verifyView(grouped_view['Id'], verifyitem): + # Take the name of the userview + foldername = grouped_view['Name'] + break # Get current media folders from emby database view = emby_db.getView_byId(folderid) diff --git a/resources/lib/read_embyserver.py b/resources/lib/read_embyserver.py index e879a5f0..c277d79c 100644 --- a/resources/lib/read_embyserver.py +++ b/resources/lib/read_embyserver.py @@ -367,6 +367,32 @@ class Read_EmbyServer(): return views + def verifyView(self, parentid, itemid): + + belongs = False + + url = "{server}/emby/Users/{UserId}/Items?format=json" + params = { + + 'ParentId': parentid, + 'CollapseBoxSetItems': False, + 'IsVirtualUnaired': False, + 'IsMissing': False, + 'Recursive': True, + 'Ids': itemid + } + result = self.doUtils(url, parameters=params) + try: + total = result['TotalRecordCount'] + except TypeError: + # Something happened to the connection + pass + else: + if total: + belongs = True + + return belongs + def getMovies(self, parentId, basic=False, dialog=None): items = self.getSection(parentId, "Movie", basic=basic, dialog=dialog)