Correctly tell PMS when we stopped playing
This commit is contained in:
parent
0315773009
commit
5be7d835f8
1 changed files with 38 additions and 20 deletions
|
@ -16,6 +16,12 @@ class SubscriptionManager:
|
||||||
self.lastkey = ""
|
self.lastkey = ""
|
||||||
self.containerKey = ""
|
self.containerKey = ""
|
||||||
self.ratingkey = ""
|
self.ratingkey = ""
|
||||||
|
self.lastplayers = {}
|
||||||
|
self.lastinfo = {
|
||||||
|
'video': {},
|
||||||
|
'audio': {},
|
||||||
|
'picture': {}
|
||||||
|
}
|
||||||
self.volume = 0
|
self.volume = 0
|
||||||
self.mute = '0'
|
self.mute = '0'
|
||||||
self.server = ""
|
self.server = ""
|
||||||
|
@ -147,31 +153,43 @@ class SubscriptionManager:
|
||||||
for sub in self.subscribers.values():
|
for sub in self.subscribers.values():
|
||||||
sub.send_update(msg, len(players) == 0)
|
sub.send_update(msg, len(players) == 0)
|
||||||
self.notifyServer(players)
|
self.notifyServer(players)
|
||||||
|
self.lastplayers = players
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def notifyServer(self, players):
|
def notifyServer(self, players):
|
||||||
for p in players.values():
|
for typus, p in players.iteritems():
|
||||||
info = self.playerprops[p.get('playerid')]
|
info = self.playerprops[p.get('playerid')]
|
||||||
params = {'state': 'stopped'}
|
self._sendNotification(info)
|
||||||
params['containerKey'] = (self.containerKey or "/library/metadata/900000")
|
self.lastinfo[typus] = info
|
||||||
|
# Cross the one of the list
|
||||||
|
try:
|
||||||
|
del self.lastplayers[typus]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
# Process the players we have left (to signal a stop)
|
||||||
|
for typus, p in self.lastplayers.iteritems():
|
||||||
|
self._sendNotification(self.lastinfo[typus])
|
||||||
|
|
||||||
|
def _sendNotification(self, info):
|
||||||
|
params = {
|
||||||
|
'containerKey': self.containerKey or "/library/metadata/900000",
|
||||||
|
'key': self.lastkey or "/library/metadata/900000",
|
||||||
|
'ratingKey': self.ratingkey or "900000",
|
||||||
|
'state': info['state'],
|
||||||
|
'time': info['time'],
|
||||||
|
'duration': info['duration']
|
||||||
|
}
|
||||||
if info.get('playQueueID'):
|
if info.get('playQueueID'):
|
||||||
params['containerKey'] = '/playQueues/' + info['playQueueID']
|
params['containerKey'] = '/playQueues/%s' % info['playQueueID']
|
||||||
params['playQueueVersion'] = info['playQueueVersion']
|
params['playQueueVersion'] = info['playQueueVersion']
|
||||||
params['playQueueItemID'] = info['playQueueItemID']
|
params['playQueueItemID'] = info['playQueueItemID']
|
||||||
params['key'] = (self.lastkey or "/library/metadata/900000")
|
|
||||||
params['ratingKey'] = (self.ratingkey or "900000")
|
|
||||||
params['state'] = info['state']
|
|
||||||
params['time'] = info['time']
|
|
||||||
params['duration'] = info['duration']
|
|
||||||
|
|
||||||
serv = self.getServerByHost(self.server)
|
serv = self.getServerByHost(self.server)
|
||||||
url = serv.get('protocol', 'http') + '://' \
|
url = '%s://%s:%s/:/timeline' % (serv.get('protocol', 'http'),
|
||||||
+ serv.get('server', 'localhost') + ':' \
|
serv.get('server', 'localhost'),
|
||||||
+ serv.get('port', '32400') + "/:/timeline"
|
serv.get('port', '32400'))
|
||||||
self.doUtils(url, parameters=params)
|
self.doUtils(url, parameters=params)
|
||||||
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
|
self.logMsg("Sent server notification with parameters: %s to %s"
|
||||||
self.logMsg("sent server notification with parameters: %s"
|
% (params, url), 2)
|
||||||
% params, 2)
|
|
||||||
|
|
||||||
def controllable(self):
|
def controllable(self):
|
||||||
return "volume,shuffle,repeat,audioStream,videoStream,subtitleStream,skipPrevious,skipNext,seekTo,stepBack,stepForward,stop,playPause"
|
return "volume,shuffle,repeat,audioStream,videoStream,subtitleStream,skipPrevious,skipNext,seekTo,stepBack,stepForward,stop,playPause"
|
||||||
|
|
Loading…
Reference in a new issue