diff --git a/contextmenu.py b/contextmenu.py index 56a17c39..d462807a 100644 --- a/contextmenu.py +++ b/contextmenu.py @@ -59,7 +59,7 @@ if __name__ == '__main__': if embyid: item = PF.GetPlexMetadata(embyid) - if item is None: + if item is None or item == 401: logMsg('Could not get item metadata for item %s' % embyid, -1) return API = PlexAPI.API(item[0]) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 4833081b..9795590e 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -443,6 +443,8 @@ Plex playlists/nodes refresh failed Full library sync finished Sync had to skip some items because they could not be processed. Kodi may be instable now!! Please post your Kodi logs to the Plex forum. + The Plex Server did not like you asking for so much data at once and returned ERRORS. Try lowering the number of sync download threads in the settings. Skipped some items for now. + On Deck diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index f0393e33..a7f28a69 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -379,6 +379,7 @@ Plex Playlisten/Nodes Aktualisierung fehlgeschlagen Plex Bibliotheken aktualisiert Einige Plex Einträge mussten übersprungen werden, da sie nicht verarbeitet werden konnten. Kodi ist nun möglicherweise instabil!! Bitte teilen Sie Ihr Kodi log im Plex Forum. + Der Plex Server war überfordert und hat mit ERROR reagiert. Versuchen Sie, in den PKC Optionen die Download Sync Threads Anzahl zu reduzieren. Ein paar Plex Filme wurden nun übersprungen. Aktuell diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index 5f60b334..39abb002 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -184,6 +184,9 @@ def GetPlexMetadata(key): } url = url + '?' + urlencode(arguments) xml = downloadutils.DownloadUtils().downloadUrl(url) + if xml == 401: + # Either unauthorized (taken care of by doUtils) or PMS under strain + return 401 # Did we receive a valid XML? try: xml.attrib diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index ca5620e0..7fac1584 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -250,7 +250,7 @@ def doPlayback(itemid, dbid): int(sys.argv[1]), False, xbmcgui.ListItem()) item = PlexFunctions.GetPlexMetadata(itemid) - if item is None: + if item is None or item == 401: return xbmcplugin.setResolvedUrl( int(sys.argv[1]), False, xbmcgui.ListItem()) # Everything OK diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 92e15bf1..985ed3f6 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -1921,7 +1921,7 @@ class Music(Items): % parentId, 1) artist = GetPlexMetadata(parentId) # Item may not be an artist, verification necessary. - if artist is not None: + if artist is not None and artist != 401: if artist[0].attrib.get('type') == "artist": # Update with the parentId, for remove reference emby_db.addReference( @@ -1942,7 +1942,7 @@ class Music(Items): self.logMsg('Artist %s does not exist in emby database' % artistId, 1) artist = GetPlexMetadata(artistId) - if artist: + if artist is not None and artist != 401: self.add_updateArtist(artist[0], artisttype="AlbumArtist") emby_dbartist = emby_db.getItem_byId(artistId) artistid = emby_dbartist[0] @@ -2140,6 +2140,9 @@ class Music(Items): self.logMsg("Album database entry missing.", 1) emby_albumId = item.attrib.get('parentRatingKey') album = GetPlexMetadata(emby_albumId) + if album is None or album == 401: + self.logMsg('Could not download album, abort', -1) + return self.add_updateAlbum(album[0]) emby_dbalbum = emby_db.getItem_byId(emby_albumId) try: @@ -2231,7 +2234,11 @@ class Music(Items): except TypeError: # Artist is missing from emby database, add it. artist_full = emby.getItem(artist_eid) - self.add_updateArtist(GetPlexMetadata(artist_eid)[0]) + artistXml = GetPlexMetadata(artist_eid) + if artistXml is None or artistXml == 401: + self.logMsg('Error getting artist, abort', -1) + return + self.add_updateArtist(artistXml[0]) artist_edb = emby_db.getItem_byId(artist_eid) artistid = artist_edb[0] finally: diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index d8d104a8..a8573bf0 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -81,6 +81,22 @@ class ThreadedGetMetadata(Thread): processMetadataCount += 1 queue.task_done() continue + elif plexXML == 401: + self.logMsg('HTTP 401 returned by PMS. Too much strain? ' + 'Cancelling sync for now', -1) + utils.window('plex_scancrashed', value='401') + # Kill remaining items in queue (for main thread to cont.) + queue.task_done() + while not queue.empty(): + # Still try because remaining item might have been taken + try: + queue.get(block=False) + except Queue.Empty: + xbmc.sleep(100) + continue + else: + queue.task_done() + break updateItem['XML'] = plexXML # place item into out queue @@ -346,7 +362,7 @@ class LibrarySync(Thread): # Get the Plex item's metadata xml = PF.GetPlexMetadata(plexId) - if xml is None: + if xml is None or xml == 401: self.logMsg("Could not download metadata, aborting time sync", -1) return libraryId = xml[0].attrib['librarySectionID'] @@ -457,10 +473,15 @@ class LibrarySync(Thread): utils.window('emby_initialScan', clear=True) xbmc.executebuiltin('InhibitIdleShutdown(false)') utils.setScreensaver(value=screensaver) - # Show warning if itemtypes.py crashed at some point if utils.window('plex_scancrashed') == 'true': + # Show warning if itemtypes.py crashed at some point self.dialog.ok(self.addonName, self.__language__(39408)) utils.window('plex_scancrashed', clear=True) + elif utils.window('plex_scancrashed') == '401': + utils.window('plex_scancrashed', clear=True) + if utils.window('emby_serverStatus') not in ('401', 'Auth'): + # Plex server had too much and returned ERROR + self.dialog.ok(self.addonName, self.__language__(39409)) # Path hack, so Kodis Information screen works with kodidb.GetKodiDB('video') as kodi_db: @@ -1079,6 +1100,9 @@ class LibrarySync(Thread): with itemtypes.TVShows() as TVshow: for tvShowId in allPlexTvShowsId: XMLtvshow = PF.GetPlexMetadata(tvShowId) + if XMLtvshow is None or XMLtvshow == 401: + self.logMsg('Could not download XMLtvshow', -1) + continue TVshow.refreshSeasonEntry(XMLtvshow, tvShowId) self.logMsg("Season info refreshed", 1) @@ -1275,7 +1299,7 @@ class LibrarySync(Thread): def process_newitems(self, item): ratingKey = item['ratingKey'] xml = PF.GetPlexMetadata(ratingKey) - if xml is None: + if xml is None or xml == 401: self.logMsg('Could not download metadata for %s, skipping' % ratingKey, -1) return False @@ -1399,7 +1423,7 @@ class LibrarySync(Thread): # viewCount if currSess.get('duration') is None: xml = PF.GetPlexMetadata(ratingKey) - if xml is None: + if xml is None or xml == 401: self.logMsg('Could not get up-to-date xml for item %s' % ratingKey, -1) continue diff --git a/resources/lib/playlist.py b/resources/lib/playlist.py index 2b3ef2bd..b3f9c154 100644 --- a/resources/lib/playlist.py +++ b/resources/lib/playlist.py @@ -58,7 +58,10 @@ class Playlist(): # Item is not found in our database, add item manually log("Item was not found in the database, manually adding item.", 1) item = PlexFunctions.GetPlexMetadata(itemid) - self.addtoPlaylist_xbmc(playlist, item) + if item is None or item == 401: + log('Could not download itemid %s' % itemid, -1) + else: + self.addtoPlaylist_xbmc(playlist, item) else: # Add to playlist self.addtoPlaylist(dbid, mediatype)