Save transient token earlier to PKC playqueue

This commit is contained in:
tomkat83 2017-12-28 16:56:48 +01:00
parent 11df634c91
commit 771520cd96
2 changed files with 19 additions and 17 deletions

View file

@ -116,10 +116,10 @@ class PlexCompanion(Thread):
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.getType()]) v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.getType()])
self.mgr.playqueue.update_playqueue_from_PMS( self.mgr.playqueue.update_playqueue_from_PMS(
playqueue, playqueue,
plex_id, playqueue_id=plex_id,
repeat=query.get('repeat'), repeat=query.get('repeat'),
offset=data.get('offset')) offset=data.get('offset'),
playqueue.plex_transient_token = data.get('key') transient_token=data.get('key'))
@LOCKER.lockthis @LOCKER.lockthis
def _process_streams(self, data): def _process_streams(self, data):

View file

@ -61,7 +61,7 @@ class Playqueue(Thread):
# sort the list by their playlistid, just in case # sort the list by their playlistid, just in case
self.playqueues = sorted( self.playqueues = sorted(
self.playqueues, key=lambda i: i.playlistid) self.playqueues, key=lambda i: i.playlistid)
LOG.debug('Initialized the Kodi play queues: %s' % self.playqueues) LOG.debug('Initialized the Kodi play queues: %s', self.playqueues)
Thread.__init__(self) Thread.__init__(self)
def get_playqueue_from_type(self, typus): def get_playqueue_from_type(self, typus):
@ -87,7 +87,7 @@ class Playqueue(Thread):
try: try:
xml[0].attrib xml[0].attrib
except (TypeError, IndexError, AttributeError): except (TypeError, IndexError, AttributeError):
LOG.error('Could not download the PMS xml for %s' % plex_id) LOG.error('Could not download the PMS xml for %s', plex_id)
return return
playqueue = self.get_playqueue_from_type( playqueue = self.get_playqueue_from_type(
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[xml[0].attrib['type']]) v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[xml[0].attrib['type']])
@ -103,7 +103,8 @@ class Playqueue(Thread):
playqueue, playqueue,
playqueue_id=None, playqueue_id=None,
repeat=None, repeat=None,
offset=None): offset=None,
transient_token=None):
""" """
Completely updates the Kodi playqueue with the new Plex playqueue. Pass Completely updates the Kodi playqueue with the new Plex playqueue. Pass
in playqueue_id if we need to fetch a new playqueue in playqueue_id if we need to fetch a new playqueue
@ -112,17 +113,18 @@ class Playqueue(Thread):
offset = time offset in Plextime (milliseconds) offset = time offset in Plextime (milliseconds)
""" """
LOG.info('New playqueue %s received from Plex companion with offset ' LOG.info('New playqueue %s received from Plex companion with offset '
'%s, repeat %s' % (playqueue_id, offset, repeat)) '%s, repeat %s', playqueue_id, offset, repeat)
with LOCK: with LOCK:
xml = PL.get_PMS_playlist(playqueue, playqueue_id) xml = PL.get_PMS_playlist(playqueue, playqueue_id)
playqueue.clear() playqueue.clear()
try: try:
PL.get_playlist_details_from_xml(playqueue, xml) PL.get_playlist_details_from_xml(playqueue, xml)
except KeyError: except KeyError:
LOG.error('Could not get playqueue ID %s' % playqueue_id) LOG.error('Could not get playqueue ID %s', playqueue_id)
return return
PlaybackUtils(xml, playqueue).play_all() PlaybackUtils(xml, playqueue).play_all()
playqueue.repeat = 0 if not repeat else int(repeat) playqueue.repeat = 0 if not repeat else int(repeat)
playqueue.token = transient_token
window('plex_customplaylist', value="true") window('plex_customplaylist', value="true")
if offset not in (None, "0"): if offset not in (None, "0"):
window('plex_customplaylist.seektime', window('plex_customplaylist.seektime',
@ -133,8 +135,8 @@ class Playqueue(Thread):
else: else:
startpos = 0 startpos = 0
# Start playback. Player does not return in time # Start playback. Player does not return in time
LOG.debug('Playqueues after Plex Companion update are now: %s' LOG.debug('Playqueues after Plex Companion update are now: %s',
% self.playqueues) self.playqueues)
thread = Thread(target=Player().play, thread = Thread(target=Player().play,
args=(playqueue.kodi_pl, args=(playqueue.kodi_pl,
None, None,
@ -149,8 +151,8 @@ class Playqueue(Thread):
""" """
old = list(playqueue.items) old = list(playqueue.items)
index = list(range(0, len(old))) index = list(range(0, len(old)))
LOG.debug('Comparing new Kodi playqueue %s with our play queue %s' LOG.debug('Comparing new Kodi playqueue %s with our play queue %s',
% (new, old)) new, old)
if self.thread_stopped(): if self.thread_stopped():
# Chances are that we got an empty Kodi playlist due to # Chances are that we got an empty Kodi playlist due to
# Kodi exit # Kodi exit
@ -178,14 +180,14 @@ class Playqueue(Thread):
del old[j], index[j] del old[j], index[j]
break break
elif identical: elif identical:
LOG.debug('Detected playqueue item %s moved to position %s' LOG.debug('Detected playqueue item %s moved to position %s',
% (i+j, i)) i+j, i)
PL.move_playlist_item(playqueue, i + j, i) PL.move_playlist_item(playqueue, i + j, i)
del old[j], index[j] del old[j], index[j]
break break
else: else:
LOG.debug('Detected new Kodi element at position %s: %s ' LOG.debug('Detected new Kodi element at position %s: %s ',
% (i, new_item)) i, new_item)
if playqueue.id is None: if playqueue.id is None:
PL.init_Plex_playlist(playqueue, PL.init_Plex_playlist(playqueue,
kodi_item=new_item) kodi_item=new_item)
@ -196,7 +198,7 @@ class Playqueue(Thread):
for j in range(i, len(index)): for j in range(i, len(index)):
index[j] += 1 index[j] += 1
for i in reversed(index): for i in reversed(index):
LOG.debug('Detected deletion of playqueue element at pos %s' % i) LOG.debug('Detected deletion of playqueue element at pos %s', i)
PL.delete_playlist_item_from_PMS(playqueue, i) PL.delete_playlist_item_from_PMS(playqueue, i)
LOG.debug('Done comparing playqueues') LOG.debug('Done comparing playqueues')