Check for adding playQueue item via JSON API

This commit is contained in:
tomkat83 2017-01-21 14:47:37 +01:00
parent b16055eef6
commit 48da925324
2 changed files with 22 additions and 17 deletions

View file

@ -295,18 +295,18 @@ class PlaybackUtils():
else:
with Get_Plex_DB() as plex_db:
db_item = plex_db.getItem_byId(api.getRatingKey())
try:
add_item_to_kodi_playlist(self.playqueue,
self.currentPosition,
kodi_id=db_item[0],
kodi_type=db_item[4])
self.currentPosition += 1
if len(item[0]) > 1:
self.add_part(item,
api,
db_item[0],
db_item[4])
except TypeError:
if db_item is not None:
if add_item_to_kodi_playlist(self.playqueue,
self.currentPosition,
kodi_id=db_item[0],
kodi_type=db_item[4]) is True:
self.currentPosition += 1
if len(item[0]) > 1:
self.add_part(item,
api,
db_item[0],
db_item[4])
else:
# Item not in Kodi DB
self.add_trailer(item)
self.playqueue.items[self.currentPosition - 1].ID = item.get(

View file

@ -337,9 +337,9 @@ def add_item_to_PMS_playlist(playlist, pos, plex_id=None, kodi_item=None):
def add_item_to_kodi_playlist(playlist, pos, kodi_id=None, kodi_type=None,
file=None):
"""
Adds an item to the KODI playlist only
Adds an item to the KODI playlist only. WILL ALSO UPDATE OUR PLAYLISTS
WILL ALSO UPDATE OUR PLAYLISTS
Returns False if unsuccessful
"""
log.debug('Adding new item kodi_id: %s, kodi_type: %s, file: %s to Kodi '
'only at position %s for %s'
@ -352,9 +352,14 @@ def add_item_to_kodi_playlist(playlist, pos, kodi_id=None, kodi_type=None,
params['item'] = {'%sid' % kodi_type: int(kodi_id)}
else:
params['item'] = {'file': file}
log.debug(JSONRPC('Playlist.Insert').execute(params))
playlist.items.insert(pos, playlist_item_from_kodi(
{'id': kodi_id, 'type': kodi_type, 'file': file}))
reply = JSONRPC('Playlist.Insert').execute(params)
if reply.get('error') is not None:
log.error('Could not add item to playlist. Kodi reply. %s' % reply)
return False
else:
playlist.items.insert(pos, playlist_item_from_kodi(
{'id': kodi_id, 'type': kodi_type, 'file': file}))
return True
def move_playlist_item(playlist, before_pos, after_pos):