Better error handling for Plex Companion playqueues
- Partially solves #236
This commit is contained in:
parent
5136424b37
commit
0b5c138709
3 changed files with 41 additions and 31 deletions
|
@ -138,7 +138,10 @@ class PlaybackUtils():
|
|||
plex_lib_UUID,
|
||||
mediatype=api.getType(),
|
||||
trailers=trailers)
|
||||
try:
|
||||
get_playlist_details_from_xml(playqueue, xml=xml)
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
if (not homeScreen and not seektime and sizePlaylist < 2 and
|
||||
window('plex_customplaylist') != "true" and
|
||||
|
|
|
@ -209,15 +209,14 @@ def update_playlist_from_PMS(playlist, playlist_id=None, xml=None):
|
|||
"""
|
||||
if xml is None:
|
||||
xml = get_PMS_playlist(playlist, playlist_id)
|
||||
try:
|
||||
xml.attrib['%sVersion' % playlist.kind]
|
||||
except:
|
||||
log.error('Could not process Plex playlist')
|
||||
return
|
||||
# Clear our existing playlist and the associated Kodi playlist
|
||||
playlist.clear()
|
||||
# Set new values
|
||||
try:
|
||||
get_playlist_details_from_xml(playlist, xml)
|
||||
except KeyError:
|
||||
log.error('Could not update playlist from PMS')
|
||||
return
|
||||
for plex_item in xml:
|
||||
playlist_item = add_to_Kodi_playlist(playlist, plex_item)
|
||||
if playlist_item is not None:
|
||||
|
@ -231,6 +230,7 @@ def init_Plex_playlist(playlist, plex_id=None, kodi_item=None):
|
|||
WILL ALSO UPDATE OUR PLAYLISTS
|
||||
"""
|
||||
log.debug('Initializing the playlist %s on the Plex side' % playlist)
|
||||
try:
|
||||
if plex_id:
|
||||
item = playlist_item_from_plex(plex_id)
|
||||
else:
|
||||
|
@ -244,6 +244,9 @@ def init_Plex_playlist(playlist, plex_id=None, kodi_item=None):
|
|||
action_type="POST",
|
||||
parameters=params)
|
||||
get_playlist_details_from_xml(playlist, xml)
|
||||
except KeyError:
|
||||
log.error('Could not init Plex playlist')
|
||||
return
|
||||
item.ID = xml[-1].attrib['%sItemID' % playlist.kind]
|
||||
playlist.items.append(item)
|
||||
log.debug('Initialized the playlist on the Plex side: %s' % playlist)
|
||||
|
@ -305,7 +308,11 @@ def add_item_to_PMS_playlist(playlist, pos, plex_id=None, kodi_item=None):
|
|||
log.debug('Adding new item plex_id: %s, kodi_item: %s on the Plex side at '
|
||||
'position %s for %s' % (plex_id, kodi_item, pos, playlist))
|
||||
if plex_id:
|
||||
try:
|
||||
item = playlist_item_from_plex(plex_id)
|
||||
except KeyError:
|
||||
log.error('Could not add new item to the PMS playlist')
|
||||
return
|
||||
else:
|
||||
item = playlist_item_from_kodi(kodi_item)
|
||||
url = "{server}/%ss/%s?uri=%s" % (playlist.kind, playlist.ID, item.uri)
|
||||
|
@ -418,11 +425,9 @@ def refresh_playlist_from_PMS(playlist):
|
|||
"""
|
||||
xml = get_PMS_playlist(playlist)
|
||||
try:
|
||||
xml.attrib['%sVersion' % playlist.kind]
|
||||
except:
|
||||
log.error('Could not download Plex playlist.')
|
||||
return
|
||||
get_playlist_details_from_xml(playlist, xml)
|
||||
except KeyError:
|
||||
log.error('Could not refresh playlist from PMS')
|
||||
|
||||
|
||||
def delete_playlist_item_from_PMS(playlist, pos):
|
||||
|
@ -469,8 +474,9 @@ def get_kodi_playqueues():
|
|||
try:
|
||||
queues = queues['result']
|
||||
except KeyError:
|
||||
raise KeyError('Could not get Kodi playqueues. JSON Result was: %s'
|
||||
log.error('Could not get Kodi playqueues. JSON Result was: %s'
|
||||
% queues)
|
||||
queues = []
|
||||
return queues
|
||||
|
||||
|
||||
|
|
|
@ -85,11 +85,12 @@ class Playqueue(Thread):
|
|||
'%s, repeat %s' % (playqueue_id, offset, repeat))
|
||||
with lock:
|
||||
xml = PL.get_PMS_playlist(playqueue, playqueue_id)
|
||||
if xml is None:
|
||||
playqueue.clear()
|
||||
try:
|
||||
PL.get_playlist_details_from_xml(playqueue, xml)
|
||||
except KeyError:
|
||||
log.error('Could not get playqueue ID %s' % playqueue_id)
|
||||
return
|
||||
playqueue.clear()
|
||||
PL.get_playlist_details_from_xml(playqueue, xml)
|
||||
PlaybackUtils(xml, playqueue).play_all()
|
||||
playqueue.repeat = 0 if not repeat else int(repeat)
|
||||
window('plex_customplaylist', value="true")
|
||||
|
|
Loading…
Reference in a new issue