Detect playback from a Kodi playlist

This commit is contained in:
Croneter 2018-06-14 16:27:13 +02:00
parent 108c88114b
commit 7ccfb61a7c
3 changed files with 21 additions and 6 deletions

View file

@ -346,8 +346,14 @@ class KodiMonitor(xbmc.Monitor):
return return
playqueue = PQ.PLAYQUEUES[playerid] playqueue = PQ.PLAYQUEUES[playerid]
info = js.get_player_props(playerid) info = js.get_player_props(playerid)
pos = info['position'] if info['position'] != -1 else 0 if playqueue.kodi_playlist_playback:
LOG.debug('Detected position %s for %s', pos, playqueue) # Kodi will tell us the wrong position - of the playlist, not the
# playqueue, when user starts playing from a playlist :-(
pos = 0
LOG.debug('Detected playback from a Kodi playlist')
else:
pos = info['position'] if info['position'] != -1 else 0
LOG.debug('Detected position %s for %s', pos, playqueue)
status = state.PLAYER_STATES[playerid] status = state.PLAYER_STATES[playerid]
kodi_id = data.get('id') kodi_id = data.get('id')
kodi_type = data.get('type') kodi_type = data.get('type')

View file

@ -66,7 +66,7 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
pos = js.get_position(playqueue.playlistid) pos = js.get_position(playqueue.playlistid)
except KeyError: except KeyError:
LOG.info('No position returned from Kodi player! Assuming playlist') LOG.info('No position returned from Kodi player! Assuming playlist')
_playlist_playback(plex_id, plex_type, playqueue) _playlist_playback(plex_id, plex_type)
else: else:
# Can return -1 (as in "no playlist") # Can return -1 (as in "no playlist")
pos = pos if pos != -1 else 0 pos = pos if pos != -1 else 0
@ -85,19 +85,25 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
_conclude_playback(playqueue, pos) _conclude_playback(playqueue, pos)
def _playlist_playback(plex_id, plex_type, playqueue): def _playlist_playback(plex_id, plex_type):
""" """
Really annoying Kodi behavior: Kodi will throw the ENTIRE playlist some- Really annoying Kodi behavior: Kodi will throw the ENTIRE playlist some-
where, causing Playlist.onAdd to fire for each item like this: where, causing Playlist.onAdd to fire for each item like this:
Playlist.OnAdd Data: {u'item': {u'type': u'episode', u'id': 164}, Playlist.OnAdd Data: {u'item': {u'type': u'episode', u'id': 164},
u'playlistid': 0, u'playlistid': 0,
u'position': 2} u'position': 2}
This does NOT work for Addon paths, type and id will be unknown This does NOT work for Addon paths, type and id will be unknown:
{u'item': {u'type': u'unknown'},
u'playlistid': 0,
u'position': 7}
At the end, only the element being played actually shows up in the Kodi At the end, only the element being played actually shows up in the Kodi
playqueue. playqueue.
Hence: if we fail the first addon paths call, Kodi will start playback Hence: if we fail the first addon paths call, Kodi will start playback
for the next item in line :-) for the next item in line :-)
(by the way: trying to get active Kodi player id will return [])
""" """
# Kodi bug: playqueue will ALWAYS be audio playqueue
playqueue = PQ.get_playqueue_from_type(v.KODI_PLAYLIST_TYPE_AUDIO)
playqueue.clear(kodi=False) playqueue.clear(kodi=False)
xml = GetPlexMetadata(plex_id) xml = GetPlexMetadata(plex_id)
try: try:
@ -109,8 +115,8 @@ def _playlist_playback(plex_id, plex_type, playqueue):
_ensure_resolve(abort=True) _ensure_resolve(abort=True)
return return
playlist_item = PL.playlist_item_from_xml(xml[0]) playlist_item = PL.playlist_item_from_xml(xml[0])
playlist_item.part = 0
playqueue.items.append(playlist_item) playqueue.items.append(playlist_item)
playqueue.kodi_playlist_playback = True
_conclude_playback(playqueue, pos=0) _conclude_playback(playqueue, pos=0)

View file

@ -138,6 +138,9 @@ class Playqueue_Object(PlaylistObjectBaseclase):
self.pkc_edit = False self.pkc_edit = False
# Workaround to avoid endless loops of detecting PL clears # Workaround to avoid endless loops of detecting PL clears
self._clear_list = [] self._clear_list = []
# To keep track if Kodi playback was initiated from a Kodi playlist
# There are a couple of pitfalls, unfortunately...
self.kodi_playlist_playback = False
PlaylistObjectBaseclase.__init__(self) PlaylistObjectBaseclase.__init__(self)
def is_pkc_clear(self): def is_pkc_clear(self):