Better way to sync progress to another account

- Partially fixes #297
This commit is contained in:
tomkat83 2017-05-25 14:21:27 +02:00
parent 74af562ada
commit cee2bfcc6c
5 changed files with 23 additions and 6 deletions

View File

@ -78,7 +78,7 @@ class PlexCompanion(Thread):
data = task['data']
# Get the token of the user flinging media (might be different one)
state.PLEX_TRANSIENT_TOKEN = data.get('token')
token = data.get('token')
if task['action'] == 'alexa':
# e.g. Alexa
xml = GetPlexMetadata(data['key'])
@ -90,9 +90,11 @@ class PlexCompanion(Thread):
api = API(xml[0])
if api.getType() == v.PLEX_TYPE_ALBUM:
log.debug('Plex music album detected')
self.mgr.playqueue.init_playqueue_from_plex_children(
queue = self.mgr.playqueue.init_playqueue_from_plex_children(
api.getRatingKey())
queue.plex_transient_token = token
else:
state.PLEX_TRANSIENT_TOKEN = token
params = {
'mode': 'plex_node',
'key': '{server}%s' % data.get('key'),
@ -106,6 +108,7 @@ class PlexCompanion(Thread):
elif (task['action'] == 'playlist' and
data.get('address') == 'node.plexapp.com'):
# E.g. watch later initiated by Companion
state.PLEX_TRANSIENT_TOKEN = token
params = {
'mode': 'plex_node',
'key': '{server}%s' % data.get('key'),
@ -144,6 +147,7 @@ class PlexCompanion(Thread):
ID,
repeat=query.get('repeat'),
offset=data.get('offset'))
playqueue.plex_transient_token = token
def run(self):
# Ensure that sockets will be closed no matter what

View File

@ -310,7 +310,7 @@ class Player(xbmc.Player):
'plex_forcetranscode'):
window(item, clear=True)
# We might have saved a transient token from a user flinging media via
# Companion
# Companion (if we could not use the playqueue to store the token)
state.PLEX_TRANSIENT_TOKEN = None
log.debug("Cleared playlist properties.")

View File

@ -29,6 +29,8 @@ class Playlist_Object_Baseclase(object):
selectedItemOffset = None
shuffled = 0 # [int], 0: not shuffled, 1: ??? 2: ???
repeat = 0 # [int], 0: not repeated, 1: ??? 2: ???
# If Companion playback is initiated by another user
plex_transient_token = None
def __repr__(self):
answ = "<%s: " % (self.__class__.__name__)
@ -58,6 +60,7 @@ class Playlist_Object_Baseclase(object):
self.selectedItemOffset = None
self.shuffled = 0
self.repeat = 0
self.plex_transient_token = None
log.debug('Playlist cleared: %s' % self)
def log_Kodi_playlist(self):

View File

@ -78,6 +78,8 @@ class Playqueue(Thread):
def init_playqueue_from_plex_children(self, plex_id):
"""
Init a new playqueue e.g. from an album. Alexa does this
Returns the Playlist_Object
"""
xml = GetAllPlexChildren(plex_id)
try:
@ -93,6 +95,7 @@ class Playqueue(Thread):
PL.add_item_to_playlist(playqueue, i, plex_id=api.getRatingKey())
log.debug('Firing up Kodi player')
Player().play(playqueue.kodi_pl, None, False, 0)
return playqueue
def update_playqueue_from_PMS(self,
playqueue,

View File

@ -123,6 +123,8 @@ class SubscriptionManager:
ret += ' itemType="%s"' % info['itemType']
if state.PLEX_TRANSIENT_TOKEN:
ret += ' token="%s"' % state.PLEX_TRANSIENT_TOKEN
elif info['plex_transient_token']:
ret += ' token="%s"' % info['plex_transient_token']
# Might need an update in the future
if ptype == 'video':
ret += ' subtitleStreamID="-1"'
@ -157,7 +159,7 @@ class SubscriptionManager:
def notifyServer(self, players):
for typus, p in players.iteritems():
info = self.playerprops[p.get('playerid')]
self._sendNotification(info)
self._sendNotification(info, int(p['playerid']))
self.lastinfo[typus] = info
# Cross the one of the list
try:
@ -167,9 +169,10 @@ class SubscriptionManager:
# Process the players we have left (to signal a stop)
for typus, p in self.lastplayers.iteritems():
self.lastinfo[typus]['state'] = 'stopped'
self._sendNotification(self.lastinfo[typus])
self._sendNotification(self.lastinfo[typus], int(p['playerid']))
def _sendNotification(self, info):
def _sendNotification(self, info, playerid):
playqueue = self.playqueue.playqueues[playerid]
xargs = getXArgsDeviceInfo()
params = {
'containerKey': self.containerKey or "/library/metadata/900000",
@ -181,6 +184,8 @@ class SubscriptionManager:
}
if state.PLEX_TRANSIENT_TOKEN:
xargs['X-Plex-Token'] = state.PLEX_TRANSIENT_TOKEN
elif playqueue.plex_transient_token:
xargs['X-Plex-Token'] = playqueue.plex_transient_token
if info.get('playQueueID'):
params['containerKey'] = '/playQueues/%s' % info['playQueueID']
params['playQueueVersion'] = info['playQueueVersion']
@ -272,6 +277,8 @@ class SubscriptionManager:
info['volume'] = self.volume
info['mute'] = self.mute
info['plex_transient_token'] = playqueue.plex_transient_token
return info