Companion: send transient token

This commit is contained in:
tomkat83 2017-05-17 20:22:16 +02:00
parent befee05043
commit 20cf51432f
4 changed files with 24 additions and 7 deletions

View file

@ -14,6 +14,7 @@ from PlexFunctions import ParseContainerKey, GetPlexMetadata
from PlexAPI import API from PlexAPI import API
import player import player
import variables as v import variables as v
import state
############################################################################### ###############################################################################
@ -76,6 +77,8 @@ class PlexCompanion(Thread):
log.debug('Processing: %s' % task) log.debug('Processing: %s' % task)
data = task['data'] data = task['data']
# Get the token of the user flinging media (might be different one)
state.PLEX_TRANSIENT_TOKEN = data.get('token')
if task['action'] == 'alexa': if task['action'] == 'alexa':
# e.g. Alexa # e.g. Alexa
xml = GetPlexMetadata(data['key']) xml = GetPlexMetadata(data['key'])

View file

@ -13,6 +13,7 @@ import downloadutils
import plexdb_functions as plexdb import plexdb_functions as plexdb
import kodidb_functions as kodidb import kodidb_functions as kodidb
import variables as v import variables as v
import state
############################################################################### ###############################################################################
@ -308,6 +309,9 @@ class Player(xbmc.Player):
'plex_playbackProps', 'plex_playbackProps',
'plex_forcetranscode'): 'plex_forcetranscode'):
window(item, clear=True) window(item, clear=True)
# We might have saved a transient token from a user flinging media via
# Companion
state.PLEX_TRANSIENT_TOKEN = None
log.debug("Cleared playlist properties.") log.debug("Cleared playlist properties.")
def onPlayBackEnded(self): def onPlayBackEnded(self):

View file

@ -5,6 +5,7 @@ import threading
import downloadutils import downloadutils
from utils import window from utils import window
import PlexFunctions as pf import PlexFunctions as pf
import state
from functions import * from functions import *
############################################################################### ###############################################################################
@ -68,12 +69,12 @@ class SubscriptionManager:
info = self.getPlayerProperties(playerid) info = self.getPlayerProperties(playerid)
# save this info off so the server update can use it too # save this info off so the server update can use it too
self.playerprops[playerid] = info; self.playerprops[playerid] = info;
state = info['state'] status = info['state']
time = info['time'] time = info['time']
else: else:
state = "stopped" status = "stopped"
time = 0 time = 0
ret = "\n"+' <Timeline state="%s" time="%s" type="%s"' % (state, time, ptype) ret = "\n"+' <Timeline state="%s" time="%s" type="%s"' % (status, time, ptype)
if playerid is None: if playerid is None:
ret += ' />' ret += ' />'
return ret return ret
@ -119,6 +120,8 @@ class SubscriptionManager:
ret += ' mute="%s"' % self.mute ret += ' mute="%s"' % self.mute
ret += ' repeat="%s"' % info['repeat'] ret += ' repeat="%s"' % info['repeat']
ret += ' itemType="%s"' % info['itemType'] ret += ' itemType="%s"' % info['itemType']
if state.PLEX_TRANSIENT_TOKEN:
ret += ' token="%s"' % state.PLEX_TRANSIENT_TOKEN
# Might need an update in the future # Might need an update in the future
if ptype == 'video': if ptype == 'video':
ret += ' subtitleStreamID="-1"' ret += ' subtitleStreamID="-1"'
@ -153,7 +156,7 @@ class SubscriptionManager:
def notifyServer(self, players): def notifyServer(self, players):
for typus, p in players.iteritems(): for typus, p in players.iteritems():
info = self.playerprops[p.get('playerid')] info = self.playerprops[p.get('playerid')]
self._sendNotification(info) # self._sendNotification(info)
self.lastinfo[typus] = info self.lastinfo[typus] = info
# Cross the one of the list # Cross the one of the list
try: try:
@ -163,7 +166,7 @@ class SubscriptionManager:
# Process the players we have left (to signal a stop) # Process the players we have left (to signal a stop)
for typus, p in self.lastplayers.iteritems(): for typus, p in self.lastplayers.iteritems():
self.lastinfo[typus]['state'] = 'stopped' self.lastinfo[typus]['state'] = 'stopped'
self._sendNotification(self.lastinfo[typus]) # self._sendNotification(self.lastinfo[typus])
def _sendNotification(self, info): def _sendNotification(self, info):
params = { params = {
@ -174,6 +177,8 @@ class SubscriptionManager:
'time': info['time'], 'time': info['time'],
'duration': info['duration'] 'duration': info['duration']
} }
if state.PLEX_TRANSIENT_TOKEN:
params['token'] = state.PLEX_TRANSIENT_TOKEN
if info.get('playQueueID'): if info.get('playQueueID'):
params['containerKey'] = '/playQueues/%s' % info['playQueueID'] params['containerKey'] = '/playQueues/%s' % info['playQueueID']
params['playQueueVersion'] = info['playQueueVersion'] params['playQueueVersion'] = info['playQueueVersion']

View file

@ -25,7 +25,12 @@ DIRECT_PATHS = False
# Along with window('plex_authenticated') # Along with window('plex_authenticated')
AUTHENTICATED = False AUTHENTICATED = False
PLEX_TOKEN = None # plex.tv username
# Plex ID of the current user (e.g. for plex.tv) as a STRING
PLEX_USERNAME = None PLEX_USERNAME = None
# Token for that user for plex.tv
PLEX_TOKEN = None
# Plex ID of that user (e.g. for plex.tv) as a STRING
PLEX_USER_ID = None PLEX_USER_ID = None
# Token passed along, e.g. if playback initiated by Plex Companion. Might be
# another user playing something! Token identifies user
PLEX_TRANSIENT_TOKEN = None