Merge pull request #967 from croneter/fix-racing

Fix playback report not working after having played a non-Plex video file
This commit is contained in:
croneter 2019-08-10 13:28:34 +02:00 committed by GitHub
commit 0541d38b3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View file

@ -398,7 +398,11 @@ class KodiMonitor(xbmc.Monitor):
LOG.debug('No Plex id obtained - aborting playback report')
app.PLAYSTATE.player_states[playerid] = copy.deepcopy(app.PLAYSTATE.template)
return
try:
item = PL.init_plex_playqueue(playqueue, plex_id=plex_id)
except PL.PlaylistError:
LOG.info('Could not initialize the Plex playlist')
return
item.file = path
# Set the Plex container key (e.g. using the Plex playqueue)
container_key = None

View file

@ -312,7 +312,8 @@ def verify_kodi_item(plex_id, kodi_item):
set to None if unsuccessful.
Will raise a PlaylistError if plex_id is None and kodi_item['file'] starts
with either 'plugin' or 'http'
with either 'plugin' or 'http'.
Will raise KeyError if neither plex_id nor kodi_id are found
"""
if plex_id is not None or kodi_item.get('id') is not None:
# Got all the info we need
@ -342,6 +343,8 @@ def verify_kodi_item(plex_id, kodi_item):
db_type='music')
kodi_item['id'] = kodi_id
kodi_item['type'] = None if kodi_id is None else kodi_type
if plex_id is None and kodi_id is None:
raise KeyError('Neither Plex nor Kodi id found for %s' % kodi_item)
LOG.debug('Research results for kodi_item: %s', kodi_item)
return kodi_item
@ -462,8 +465,8 @@ def init_plex_playqueue(playlist, plex_id=None, kodi_item=None):
Returns the first PKC playlist item or raises PlaylistError
"""
LOG.debug('Initializing the playqueue on the Plex side: %s', playlist)
playlist.clear(kodi=False)
verify_kodi_item(plex_id, kodi_item)
playlist.clear(kodi=False)
try:
if plex_id:
item = playlist_item_from_plex(plex_id)

View file

@ -86,7 +86,11 @@ def init_playqueue_from_plex_children(plex_id, transient_token=None):
playqueue.clear()
for i, child in enumerate(xml):
api = API(child)
try:
PL.add_item_to_playlist(playqueue, i, plex_id=api.plex_id)
except PL.PlaylistError:
LOG.error('Could not add Plex item to our playlist: %s, %s',
child.tag, child.attrib)
playqueue.plex_transient_token = transient_token
LOG.debug('Firing up Kodi player')
app.APP.player.play(playqueue.kodi_pl, None, False, 0)
@ -166,6 +170,14 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
except PL.PlaylistError:
# Could not add the element
pass
except KeyError:
# Catches KeyError from PL.verify_kodi_item()
# Hack: Kodi already started playback of a new item and we
# started playback already using kodimonitors
# PlayBackStart(), but the Kodi playlist STILL only shows
# the old element. Hence ignore playlist difference here
LOG.debug('Detected an outdated Kodi playlist - ignoring')
return
except IndexError:
# This is really a hack - happens when using Addon Paths
# and repeatedly starting the same element. Kodi will then