def _compare_playqueues(self, playqueue, new): """ Used to poll the Kodi playqueue and update the Plex playqueue if needed """ old = list(playqueue.items) index = list(range(0, len(old))) log.debug('Comparing new Kodi playqueue %s with our play queue %s' % (new, old)) if self.thread_stopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return for i, new_item in enumerate(new): if (new_item['file'].startswith('plugin://') and not new_item['file'].startswith(PLUGIN)): # Ignore new media added by other addons continue for j, old_item in enumerate(old): try: if (old_item.file.startswith('plugin://') and not old_item['file'].startswith(PLUGIN)): # Ignore media by other addons continue except (TypeError, AttributeError): # were not passed a filename; ignore pass if new_item.get('id') is None: identical = old_item.file == new_item['file'] else: identical = (old_item.kodi_id == new_item['id'] and old_item.kodi_type == new_item['type']) if j == 0 and identical: del old[j], index[j] break elif identical: log.debug( 'Detected playqueue item %s moved to position %s' % (i + j, i)) PL.move_playlist_item(playqueue, i + j, i) del old[j], index[j] break else: log.debug('Detected new Kodi element at position %s: %s ' % (i, new_item)) if playqueue.ID is None: PL.init_Plex_playlist(playqueue, kodi_item=new_item) else: PL.add_item_to_PMS_playlist(playqueue, i, kodi_item=new_item) for j in range(i, len(index)): index[j] += 1 for i in reversed(index): log.debug('Detected deletion of playqueue element at pos %s' % i) PL.delete_playlist_item_from_PMS(playqueue, i) log.debug('Done comparing playqueues')
def _compare_playqueues(self, playqueue, new): """ Used to poll the Kodi playqueue and update the Plex playqueue if needed """ old = list(playqueue.items) index = list(range(0, len(old))) log.debug('Comparing new Kodi playqueue %s with our play queue %s' % (new, old)) for i, new_item in enumerate(new): for j, old_item in enumerate(old): if self.threadStopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return if new_item.get('id') is None: identical = old_item.file == new_item['file'] else: identical = (old_item.kodi_id == new_item['id'] and old_item.kodi_type == new_item['type']) if j == 0 and identical: del old[j], index[j] break elif identical: log.debug('Detected playqueue item %s moved to position %s' % (i+j, i)) PL.move_playlist_item(playqueue, i + j, i) del old[j], index[j] break else: log.debug('Detected new Kodi element at position %s: %s ' % (i, new_item)) if playqueue.ID is None: PL.init_Plex_playlist(playqueue, kodi_item=new_item) else: PL.add_item_to_PMS_playlist(playqueue, i, kodi_item=new_item) for j in range(i, len(index)): index[j] += 1 for i in reversed(index): log.debug('Detected deletion of playqueue element at pos %s' % i) PL.delete_playlist_item_from_PMS(playqueue, i) log.debug('Done comparing playqueues')
def _compare_playqueues(self, playqueue, new): """ Used to poll the Kodi playqueue and update the Plex playqueue if needed """ old = list(playqueue.items) index = list(range(0, len(old))) log.debug('Comparing new Kodi playqueue %s with our play queue %s' % (new, old)) for i, new_item in enumerate(new): for j, old_item in enumerate(old): if self.threadStopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return if new_item.get('id') is None: identical = old_item.file == new_item['file'] else: identical = (old_item.kodi_id == new_item['id'] and old_item.kodi_type == new_item['type']) if j == 0 and identical: del old[j], index[j] break elif identical: log.debug( 'Detected playqueue item %s moved to position %s' % (i + j, i)) PL.move_playlist_item(playqueue, i + j, i) del old[j], index[j] break else: log.debug('Detected new Kodi element at position %s: %s ' % (i, new_item)) if playqueue.ID is None: PL.init_Plex_playlist(playqueue, kodi_item=new_item) else: PL.add_item_to_PMS_playlist(playqueue, i, kodi_item=new_item) for j in range(i, len(index)): index[j] += 1 for i in reversed(index): log.debug('Detected deletion of playqueue element at pos %s' % i) PL.delete_playlist_item_from_PMS(playqueue, i) log.debug('Done comparing playqueues')
def _compare_playqueues(self, playqueue, new): """ Used to poll the Kodi playqueue and update the Plex playqueue if needed """ old = list(playqueue.items) index = list(range(0, len(old))) LOG.debug('Comparing new Kodi playqueue %s with our play queue %s', new, old) for i, new_item in enumerate(new): if (new_item['file'].startswith('plugin://') and not new_item['file'].startswith(PLUGIN)): # Ignore new media added by other addons continue for j, old_item in enumerate(old): if self.stopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return try: if (old_item.file.startswith('plugin://') and not old_item.file.startswith(PLUGIN)): # Ignore media by other addons continue except AttributeError: # were not passed a filename; ignore pass if 'id' in new_item: identical = (old_item.kodi_id == new_item['id'] and old_item.kodi_type == new_item['type']) else: try: plex_id = REGEX.findall(new_item['file'])[0] except IndexError: LOG.debug('Comparing paths directly as a fallback') identical = old_item.file == new_item['file'] else: identical = plex_id == old_item.plex_id if j == 0 and identical: del old[j], index[j] break elif identical: LOG.debug('Detected playqueue item %s moved to position %s', i + j, i) PL.move_playlist_item(playqueue, i + j, i) del old[j], index[j] break else: LOG.debug('Detected new Kodi element at position %s: %s ', i, new_item) try: if playqueue.id is None: PL.init_Plex_playlist(playqueue, kodi_item=new_item) else: PL.add_item_to_PMS_playlist(playqueue, i, kodi_item=new_item) except PL.PlaylistError: # Could not add the element pass except IndexError: # This is really a hack - happens when using Addon Paths # and repeatedly starting the same element. Kodi will then # not pass kodi id nor file path AND will also not # start-up playback. Hence kodimonitor kicks off playback. # Also see kodimonitor.py - _playlist_onadd() pass else: for j in range(i, len(index)): index[j] += 1 for i in reversed(index): if self.stopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return LOG.debug('Detected deletion of playqueue element at pos %s', i) PL.delete_playlist_item_from_PMS(playqueue, i) LOG.debug('Done comparing playqueues')