def update_playqueue_from_PMS(playqueue, playqueue_id=None, repeat=None, offset=None, transient_token=None): """ Completely updates the Kodi playqueue with the new Plex playqueue. Pass in playqueue_id if we need to fetch a new playqueue repeat = 0, 1, 2 offset = time offset in Plextime (milliseconds) """ LOG.info('New playqueue %s received from Plex companion with offset ' '%s, repeat %s', playqueue_id, offset, repeat) # Safe transient token from being deleted if transient_token is None: transient_token = playqueue.plex_transient_token with LOCK: xml = PL.get_PMS_playlist(playqueue, playqueue_id) playqueue.clear() try: PL.get_playlist_details_from_xml(playqueue, xml) except PL.PlaylistError: LOG.error('Could not get playqueue ID %s', playqueue_id) return playqueue.repeat = 0 if not repeat else int(repeat) playqueue.plex_transient_token = transient_token play_xml(playqueue, xml, offset)
def update_playqueue_from_PMS(self, playqueue, playqueue_id=None, repeat=None, offset=None): """ Completely updates the Kodi playqueue with the new Plex playqueue. Pass in playqueue_id if we need to fetch a new playqueue repeat = 0, 1, 2 offset = time offset in Plextime (milliseconds) """ log.info('New playqueue %s received from Plex companion with offset ' '%s, repeat %s' % (playqueue_id, offset, repeat)) with lock: xml = PL.get_PMS_playlist(playqueue, playqueue_id) playqueue.clear() try: PL.get_playlist_details_from_xml(playqueue, xml) except KeyError: log.error('Could not get playqueue ID %s' % playqueue_id) return PlaybackUtils(xml, playqueue).play_all() playqueue.repeat = 0 if not repeat else int(repeat) window('plex_customplaylist', value="true") if offset not in (None, "0"): window('plex_customplaylist.seektime', str(ConvertPlexToKodiTime(offset))) for startpos, item in enumerate(playqueue.items): if item.ID == playqueue.selectedItemID: break else: startpos = 0 # Start playback. Player does not return in time log.debug('Playqueues after Plex Companion update are now: %s' % self.playqueues) thread = Thread(target=Player().play, args=(playqueue.kodi_pl, None, False, startpos)) thread.setDaemon(True) thread.start()