From c03b7c52c4b2dd53aa429e2ecaf2b23b9f20a18c Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 14 Jun 2018 21:01:54 +0200 Subject: [PATCH] Detect playback from playlist more reliable for add-on paths --- resources/lib/kodimonitor.py | 12 ------------ resources/lib/playback.py | 35 +++++++++++++++++++++++++---------- resources/lib/state.py | 2 -- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 17014f18..0123cded 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -216,18 +216,6 @@ class KodiMonitor(xbmc.Monitor): } Will NOT be called if playback initiated by Kodi widgets """ - if data['item'] == {'type': 'unknown'}: - # Kodi will return something like this if user started a PLAYLIST - # from add-on paths: - # {u'item': {u'type': u'unknown'}, - # u'playlistid': 0, - # u'position': 4} - if not state.PLAYLIST_PLAY: - LOG.debug('Detected playback from a playlist') - state.PLAYLIST_PLAY = True - return - else: - state.PLAYLIST_PLAY = False if 'id' not in data['item']: return old = state.OLD_PLAYER_STATES[data['playlistid']] diff --git a/resources/lib/playback.py b/resources/lib/playback.py index 8c41abc4..87d0e1ec 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -60,21 +60,36 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True): dialog('notification', lang(29999), lang(30017)) _ensure_resolve(abort=True) return - if state.PLAYLIST_PLAY: - LOG.debug('Kodi playlist play detected') - state.PLAYLIST_PLAY = False - _playlist_playback(plex_id, plex_type) - return playqueue = PQ.get_playqueue_from_type( v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type]) try: pos = js.get_position(playqueue.playlistid) except KeyError: - LOG.error('No position returned from Kodi player!') - # "Play error" - dialog('notification', lang(29999), lang(30128), icon='{error}') - _ensure_resolve(abort=True) - return + # Kodi bug - Playlist plays (not Playqueue) will ALWAYS be audio for + # add-on paths + LOG.info('No position returned from Kodi player! Assuming playlist') + playqueue = PQ.get_playqueue_from_type(v.KODI_PLAYLIST_TYPE_AUDIO) + try: + pos = js.get_position(playqueue.playlistid) + except KeyError: + LOG.error('Still no position - abort') + # "Play error" + dialog('notification', lang(29999), lang(30128), icon='{error}') + _ensure_resolve(abort=True) + return + # HACK to detect playback of playlists for add-on paths + items = js.playlist_get_items(playqueue.playlistid) + try: + item = items[pos] + except IndexError: + LOG.info('Could not apply playlist hack! Probably Widget playback') + else: + if ('id' not in item and + item.get('type') == 'unknown' and item.get('title') == ''): + LOG.info('Kodi playlist play detected') + _playlist_playback(plex_id, plex_type) + return + # Can return -1 (as in "no playlist") pos = pos if pos != -1 else 0 LOG.debug('playQueue position %s for %s', pos, playqueue) diff --git a/resources/lib/state.py b/resources/lib/state.py index 73e21c2e..ce27325f 100644 --- a/resources/lib/state.py +++ b/resources/lib/state.py @@ -160,8 +160,6 @@ RESUME_PLAYBACK = False CONTEXT_MENU_PLAY = False # Set by context menu - shall we force-transcode the next playing item? FORCE_TRANSCODE = False -# Flag if user started playback of a PLAYLIST (not playqueue) for add-on paths -PLAYLIST_PLAY = False # Kodi webserver details WEBSERVER_PORT = 8080