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,
|
plex_lib_UUID,
|
||||||
mediatype=api.getType(),
|
mediatype=api.getType(),
|
||||||
trailers=trailers)
|
trailers=trailers)
|
||||||
get_playlist_details_from_xml(playqueue, xml=xml)
|
try:
|
||||||
|
get_playlist_details_from_xml(playqueue, xml=xml)
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
|
||||||
if (not homeScreen and not seektime and sizePlaylist < 2 and
|
if (not homeScreen and not seektime and sizePlaylist < 2 and
|
||||||
window('plex_customplaylist') != "true" 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:
|
if xml is None:
|
||||||
xml = get_PMS_playlist(playlist, playlist_id)
|
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
|
# Clear our existing playlist and the associated Kodi playlist
|
||||||
playlist.clear()
|
playlist.clear()
|
||||||
# Set new values
|
# Set new values
|
||||||
get_playlist_details_from_xml(playlist, xml)
|
try:
|
||||||
|
get_playlist_details_from_xml(playlist, xml)
|
||||||
|
except KeyError:
|
||||||
|
log.error('Could not update playlist from PMS')
|
||||||
|
return
|
||||||
for plex_item in xml:
|
for plex_item in xml:
|
||||||
playlist_item = add_to_Kodi_playlist(playlist, plex_item)
|
playlist_item = add_to_Kodi_playlist(playlist, plex_item)
|
||||||
if playlist_item is not None:
|
if playlist_item is not None:
|
||||||
|
@ -231,19 +230,23 @@ def init_Plex_playlist(playlist, plex_id=None, kodi_item=None):
|
||||||
WILL ALSO UPDATE OUR PLAYLISTS
|
WILL ALSO UPDATE OUR PLAYLISTS
|
||||||
"""
|
"""
|
||||||
log.debug('Initializing the playlist %s on the Plex side' % playlist)
|
log.debug('Initializing the playlist %s on the Plex side' % playlist)
|
||||||
if plex_id:
|
try:
|
||||||
item = playlist_item_from_plex(plex_id)
|
if plex_id:
|
||||||
else:
|
item = playlist_item_from_plex(plex_id)
|
||||||
item = playlist_item_from_kodi(kodi_item)
|
else:
|
||||||
params = {
|
item = playlist_item_from_kodi(kodi_item)
|
||||||
'next': 0,
|
params = {
|
||||||
'type': playlist.type,
|
'next': 0,
|
||||||
'uri': item.uri
|
'type': playlist.type,
|
||||||
}
|
'uri': item.uri
|
||||||
xml = DU().downloadUrl(url="{server}/%ss" % playlist.kind,
|
}
|
||||||
action_type="POST",
|
xml = DU().downloadUrl(url="{server}/%ss" % playlist.kind,
|
||||||
parameters=params)
|
action_type="POST",
|
||||||
get_playlist_details_from_xml(playlist, xml)
|
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]
|
item.ID = xml[-1].attrib['%sItemID' % playlist.kind]
|
||||||
playlist.items.append(item)
|
playlist.items.append(item)
|
||||||
log.debug('Initialized the playlist on the Plex side: %s' % playlist)
|
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 '
|
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))
|
'position %s for %s' % (plex_id, kodi_item, pos, playlist))
|
||||||
if plex_id:
|
if plex_id:
|
||||||
item = playlist_item_from_plex(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:
|
else:
|
||||||
item = playlist_item_from_kodi(kodi_item)
|
item = playlist_item_from_kodi(kodi_item)
|
||||||
url = "{server}/%ss/%s?uri=%s" % (playlist.kind, playlist.ID, item.uri)
|
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)
|
xml = get_PMS_playlist(playlist)
|
||||||
try:
|
try:
|
||||||
xml.attrib['%sVersion' % playlist.kind]
|
get_playlist_details_from_xml(playlist, xml)
|
||||||
except:
|
except KeyError:
|
||||||
log.error('Could not download Plex playlist.')
|
log.error('Could not refresh playlist from PMS')
|
||||||
return
|
|
||||||
get_playlist_details_from_xml(playlist, xml)
|
|
||||||
|
|
||||||
|
|
||||||
def delete_playlist_item_from_PMS(playlist, pos):
|
def delete_playlist_item_from_PMS(playlist, pos):
|
||||||
|
@ -469,8 +474,9 @@ def get_kodi_playqueues():
|
||||||
try:
|
try:
|
||||||
queues = queues['result']
|
queues = queues['result']
|
||||||
except KeyError:
|
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)
|
||||||
|
queues = []
|
||||||
return queues
|
return queues
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -85,11 +85,12 @@ class Playqueue(Thread):
|
||||||
'%s, repeat %s' % (playqueue_id, offset, repeat))
|
'%s, repeat %s' % (playqueue_id, offset, repeat))
|
||||||
with lock:
|
with lock:
|
||||||
xml = PL.get_PMS_playlist(playqueue, playqueue_id)
|
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)
|
log.error('Could not get playqueue ID %s' % playqueue_id)
|
||||||
return
|
return
|
||||||
playqueue.clear()
|
|
||||||
PL.get_playlist_details_from_xml(playqueue, xml)
|
|
||||||
PlaybackUtils(xml, playqueue).play_all()
|
PlaybackUtils(xml, playqueue).play_all()
|
||||||
playqueue.repeat = 0 if not repeat else int(repeat)
|
playqueue.repeat = 0 if not repeat else int(repeat)
|
||||||
window('plex_customplaylist', value="true")
|
window('plex_customplaylist', value="true")
|
||||||
|
|
Loading…
Reference in a new issue