Add some error checking for playlists

This commit is contained in:
tomkat83 2017-01-21 17:20:42 +01:00
parent 48da925324
commit 51719cfa50

View file

@ -219,7 +219,9 @@ def update_playlist_from_PMS(playlist, playlist_id=None, xml=None):
# Set new values # Set new values
get_playlist_details_from_xml(playlist, xml) get_playlist_details_from_xml(playlist, xml)
for plex_item in xml: for plex_item in xml:
playlist.items.append(add_to_Kodi_playlist(playlist, plex_item)) playlist_item = add_to_Kodi_playlist(playlist, plex_item)
if playlist_item is not None:
playlist.items.append(playlist_item)
def init_Plex_playlist(playlist, plex_id=None, kodi_item=None): def init_Plex_playlist(playlist, plex_id=None, kodi_item=None):
@ -477,7 +479,7 @@ def add_to_Kodi_playlist(playlist, xml_video_element):
Adds a new item to the Kodi playlist via JSON (at the end of the playlist). Adds a new item to the Kodi playlist via JSON (at the end of the playlist).
Pass in the PMS xml's video element (one level underneath MediaContainer). Pass in the PMS xml's video element (one level underneath MediaContainer).
Returns a Playlist_Item Returns a Playlist_Item or None if it did not work
""" """
item = playlist_item_from_xml(playlist, xml_video_element) item = playlist_item_from_xml(playlist, xml_video_element)
params = { params = {
@ -487,7 +489,12 @@ def add_to_Kodi_playlist(playlist, xml_video_element):
params['item'] = {'%sid' % item.kodi_type: item.kodi_id} params['item'] = {'%sid' % item.kodi_type: item.kodi_id}
else: else:
params['item'] = {'file': tryEncode(item.file)} params['item'] = {'file': tryEncode(item.file)}
log.debug(JSONRPC('Playlist.Add').execute(params)) reply = JSONRPC('Playlist.Add').execute(params)
if reply.get('error') is not None:
log.error('Could not add item %s to Kodi playlist. Error: %s'
% (xml_video_element, reply))
return None
else:
return item return item
@ -519,8 +526,16 @@ def remove_from_Kodi_playlist(playlist, pos):
WILL NOT UPDATE THE PLEX SIDE, BUT WILL UPDATE OUR PLAYLISTS WILL NOT UPDATE THE PLEX SIDE, BUT WILL UPDATE OUR PLAYLISTS
""" """
log.debug('Removing position %s from Kodi only from %s' % (pos, playlist)) log.debug('Removing position %s from Kodi only from %s' % (pos, playlist))
log.debug(JSONRPC('Playlist.Remove').execute({ reply = JSONRPC('Playlist.Remove').execute({
'playlistid': playlist.playlistid, 'playlistid': playlist.playlistid,
'position': pos 'position': pos
})) })
if reply.get('error') is not None:
log.error('Could not delete the item from the playlist. Error: %s'
% reply)
return
else:
try:
del playlist.items[pos] del playlist.items[pos]
except IndexError:
log.error('Cannot delete position %s for %s' % (pos, playlist))