Better detect if PKC playback init is still ongoing

This commit is contained in:
tomkat83 2018-01-02 15:11:49 +01:00
parent 93b878ad78
commit f4e83f6be5

View file

@ -119,7 +119,6 @@ class SubscriptionMgr(object):
self.protocol = "http" self.protocol = "http"
self.port = "" self.port = ""
self.isplaying = False self.isplaying = False
self.last_timelines = {}
# In order to be able to signal a stop at the end # In order to be able to signal a stop at the end
self.last_params = {} self.last_params = {}
self.lastplayers = {} self.lastplayers = {}
@ -154,29 +153,17 @@ class SubscriptionMgr(object):
} }
for typus in timelines: for typus in timelines:
if players.get(v.KODI_PLAYLIST_TYPE_FROM_PLEX_PLAYLIST_TYPE[typus]) is None: if players.get(v.KODI_PLAYLIST_TYPE_FROM_PLEX_PLAYLIST_TYPE[typus]) is None:
timeline = self._dict_to_xml({ timeline = {
'controllable': CONTROLLABLE[typus], 'controllable': CONTROLLABLE[typus],
'type': typus, 'type': typus,
'state': 'stopped' 'state': 'stopped'
}) }
else: else:
try: timeline = self._timeline_dict(players[
timeline = self._dict_to_xml(self._timeline_dict(players[
v.KODI_PLAYLIST_TYPE_FROM_PLEX_PLAYLIST_TYPE[typus]], v.KODI_PLAYLIST_TYPE_FROM_PLEX_PLAYLIST_TYPE[typus]],
typus)) typus)
except RuntimeError: timelines[typus] = self._dict_to_xml(timeline)
try:
timeline = self.last_timelines[typus]
except KeyError:
# On startup
timeline = self._dict_to_xml({
'controllable': CONTROLLABLE[typus],
'type': typus,
'state': 'stopped'
})
timelines[typus] = timeline
location = 'fullScreenVideo' if self.isplaying else 'navigation' location = 'fullScreenVideo' if self.isplaying else 'navigation'
self.last_timelines = dict(timelines)
timelines.update({'command_id': '{command_id}', 'location': location}) timelines.update({'command_id': '{command_id}', 'location': location})
return answ.format(**timelines) return answ.format(**timelines)
@ -205,10 +192,6 @@ class SubscriptionMgr(object):
'state': 'stopped' 'state': 'stopped'
} }
self.isplaying = True self.isplaying = True
if item.plex_id != info['plex_id']:
# Kodi playqueue already progressed; need to wait until everything
# is loaded
raise RuntimeError
pbmc_server = window('pms_server') pbmc_server = window('pms_server')
if pbmc_server: if pbmc_server:
(self.protocol, self.server, self.port) = pbmc_server.split(':') (self.protocol, self.server, self.port) = pbmc_server.split(':')
@ -315,6 +298,28 @@ class SubscriptionMgr(object):
if command_id and self.subscribers.get(uuid): if command_id and self.subscribers.get(uuid):
self.subscribers[uuid].command_id = int(command_id) self.subscribers[uuid].command_id = int(command_id)
def _playqueue_init_done(self, players):
"""
update_player_info() can result in values BEFORE kodi monitor is called.
Hence we'd have a missmatch between the state.PLAYER_STATES and our
playqueues.
"""
for player in players.values():
info = state.PLAYER_STATES[player['playerid']]
playqueue = self.playqueue.playqueues[player['playerid']]
try:
item = playqueue.items[info['position']]
except IndexError:
# E.g. for direct path playback for single item
return False
LOG.debug('item: %s', item)
LOG.debug('playstate: %s', info)
if item.plex_id != info['plex_id']:
# Kodi playqueue already progressed; need to wait until
# everything is loaded
return False
return True
@LOCKER.lockthis @LOCKER.lockthis
def notify(self): def notify(self):
""" """
@ -327,6 +332,11 @@ class SubscriptionMgr(object):
# Update the PKC info with what's playing on the Kodi side # Update the PKC info with what's playing on the Kodi side
for player in players.values(): for player in players.values():
update_player_info(player['playerid']) update_player_info(player['playerid'])
# Check whether we can use the CURRENT info or whether PKC is still
# initializing
if self._playqueue_init_done(players) is False:
LOG.debug('PKC playqueue is still initializing - skipping update')
return
self._notify_server(players) self._notify_server(players)
if self.subscribers: if self.subscribers:
msg = self.msg(players) msg = self.msg(players)