Deal with PMS reply 401 under too much strain

- Sync should now abort pretty much instantly
This commit is contained in:
tomkat83 2016-04-07 18:29:23 +02:00
parent 1db371e9f1
commit 5289619792
8 changed files with 50 additions and 10 deletions

View File

@ -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])

View File

@ -443,6 +443,8 @@
<string id="39406">Plex playlists/nodes refresh failed</string>
<string id="39407">Full library sync finished</string>
<string id="39408">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.</string>
<string id="39409">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.</string>
<!-- Plex videonodes.py -->
<string id="39500">On Deck</string>

View File

@ -379,6 +379,7 @@
<string id="39406">Plex Playlisten/Nodes Aktualisierung fehlgeschlagen</string>
<string id="39407">Plex Bibliotheken aktualisiert</string>
<string id="39408">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.</string>
<string id="39409">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.</string>
<!-- Plex videonodes.py -->
<string id="39500">Aktuell</string>

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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)