def add_item_to_kodi_playlist(playlist, pos, kodi_id=None, kodi_type=None, file=None): """ Adds an item to the KODI playlist only. WILL ALSO UPDATE OUR PLAYLISTS Returns False if unsuccessful file: str! """ log.debug('Adding new item kodi_id: %s, kodi_type: %s, file: %s to Kodi ' 'only at position %s for %s' % (kodi_id, kodi_type, file, pos, playlist)) params = {'playlistid': playlist.playlistid, 'position': pos} if kodi_id is not None: params['item'] = {'%sid' % kodi_type: int(kodi_id)} else: params['item'] = {'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 add_item_to_kodi_playlist(playlist, pos, kodi_id=None, kodi_type=None, file=None): """ Adds an item to the KODI playlist only. WILL ALSO UPDATE OUR PLAYLISTS Returns False if unsuccessful file: str! """ log.debug('Adding new item kodi_id: %s, kodi_type: %s, file: %s to Kodi ' 'only at position %s for %s' % (kodi_id, kodi_type, file, pos, playlist)) params = { 'playlistid': playlist.playlistid, 'position': pos } if kodi_id is not None: params['item'] = {'%sid' % kodi_type: int(kodi_id)} else: params['item'] = {'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 remove_from_Kodi_playlist(playlist, pos): """ Removes the item at position pos from the Kodi playlist using JSON. WILL NOT UPDATE THE PLEX SIDE, BUT WILL UPDATE OUR PLAYLISTS """ log.debug('Removing position %s from Kodi only from %s' % (pos, playlist)) reply = JSONRPC('Playlist.Remove').execute({ 'playlistid': playlist.playlistid, '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] except IndexError: log.error('Cannot delete position %s for %s' % (pos, playlist))
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). Pass in the PMS xml's video element (one level underneath MediaContainer). Returns a Playlist_Item or None if it did not work """ item = playlist_item_from_xml(playlist, xml_video_element) params = {'playlistid': playlist.playlistid} if item.kodi_id: params['item'] = {'%sid' % item.kodi_type: item.kodi_id} else: params['item'] = {'file': item.file} 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
def remove_from_Kodi_playlist(playlist, pos): """ Removes the item at position pos from the Kodi playlist using JSON. WILL NOT UPDATE THE PLEX SIDE, BUT WILL UPDATE OUR PLAYLISTS """ log.debug('Removing position %s from Kodi only from %s' % (pos, playlist)) reply = JSONRPC('Playlist.Remove').execute({ 'playlistid': playlist.playlistid, '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] except IndexError: log.error('Cannot delete position %s for %s' % (pos, playlist))
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). Pass in the PMS xml's video element (one level underneath MediaContainer). Returns a Playlist_Item or None if it did not work """ item = playlist_item_from_xml(playlist, xml_video_element) params = { 'playlistid': playlist.playlistid } if item.kodi_id: params['item'] = {'%sid' % item.kodi_type: item.kodi_id} else: params['item'] = {'file': item.file} 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