Fix resume of playqueue initiated by companion

This commit is contained in:
tomkat83 2016-12-28 15:21:29 +01:00
parent 5b020910d3
commit 49b5131dbb
3 changed files with 49 additions and 5 deletions

View file

@ -86,10 +86,13 @@ class PlexCompanion(Thread):
playqueue = self.mgr.playqueue.get_playqueue_from_type( playqueue = self.mgr.playqueue.get_playqueue_from_type(
data['type']) data['type'])
if ID != playqueue.ID: if ID != playqueue.ID:
# playqueue changed somehow
self.mgr.playqueue.update_playqueue_from_PMS( self.mgr.playqueue.update_playqueue_from_PMS(
playqueue, ID, int(query['repeat']), data['offset']) playqueue, ID, int(query['repeat']), data['offset'])
else: else:
log.error('This has never happened before!') # No change to the playqueue
self.mgr.playqueue.start_playqueue_initiated_by_companion(
playqueue, int(query['repeat']), data['offset'])
def run(self): def run(self):
httpd = False httpd = False

View file

@ -375,7 +375,21 @@ def get_PMS_playlist(playlist, playlist_id=None):
return xml return xml
def update_playlist_from_PMS(playlist, playlist_id=None, repeat=None): def refresh_playlist_from_PMS(playlist):
"""
Only updates the selected item from the PMS side (e.g.
playQueueSelectedItemID). Will NOT check whether items still make sense.
"""
xml = get_PMS_playlist(playlist)
try:
xml.attrib['%sVersion' % playlist.kind]
except:
log.error('Could not download Plex playlist.')
return
_get_playlist_details_from_xml(playlist, xml)
def update_playlist_from_PMS(playlist, playlist_id=None):
""" """
Updates Kodi playlist using a new PMS playlist. Pass in playlist_id if we Updates Kodi playlist using a new PMS playlist. Pass in playlist_id if we
need to fetch a new playqueue need to fetch a new playqueue
@ -390,8 +404,6 @@ def update_playlist_from_PMS(playlist, playlist_id=None, repeat=None):
playlist.clear() playlist.clear()
# Set new values # Set new values
_get_playlist_details_from_xml(playlist, xml) _get_playlist_details_from_xml(playlist, xml)
if repeat:
playlist.repeat = repeat
for plex_item in xml: for plex_item in xml:
playlist.items.append(add_to_Kodi_playlist(playlist, plex_item)) playlist.items.append(add_to_Kodi_playlist(playlist, plex_item))

View file

@ -93,7 +93,8 @@ class Playqueue(Thread):
offset = time offset in Plextime offset = time offset in Plextime
""" """
log.info('New playqueue received from the PMS, updating!') log.info('New playqueue received from the PMS, updating!')
PL.update_playlist_from_PMS(playqueue, playqueue_id, repeat) PL.update_playlist_from_PMS(playqueue, playqueue_id)
playqueue.repeat = repeat
log.debug('Updated playqueue: %s' % playqueue) log.debug('Updated playqueue: %s' % playqueue)
window('plex_customplaylist', value="true") window('plex_customplaylist', value="true")
@ -112,6 +113,34 @@ class Playqueue(Thread):
self.player.play(playqueue.kodi_pl) self.player.play(playqueue.kodi_pl)
playqueue.log_Kodi_playlist() playqueue.log_Kodi_playlist()
@lockmethod.lockthis
def start_playqueue_initiated_by_companion(self,
playqueue,
playqueue_id=None,
repeat=None,
offset=None):
log.info('Plex companion wants to restart playback of playqueue %s'
% playqueue)
# Still need to get new playQueue from the server - don't know what has
# been selected
PL.refresh_playlist_from_PMS(playqueue)
playqueue.repeat = 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 = None
# Start playback
if startpos:
self.player.play(playqueue.kodi_pl, startpos=startpos)
else:
self.player.play(playqueue.kodi_pl)
playqueue.log_Kodi_playlist()
@lockmethod.lockthis @lockmethod.lockthis
def kodi_onadd(self, data): def kodi_onadd(self, data):
""" """