Rewire detection of add-on paths playlists playback

- Pain to fix Kodi bugs
This commit is contained in:
Croneter 2018-06-14 19:43:21 +02:00
parent e09cfa8cb3
commit 0a55e7fee8
3 changed files with 45 additions and 21 deletions

View file

@ -216,6 +216,18 @@ class KodiMonitor(xbmc.Monitor):
} }
Will NOT be called if playback initiated by Kodi widgets 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']: if 'id' not in data['item']:
return return
old = state.OLD_PLAYER_STATES[data['playlistid']] old = state.OLD_PLAYER_STATES[data['playlistid']]

View file

@ -60,14 +60,21 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
dialog('notification', lang(29999), lang(30017)) dialog('notification', lang(29999), lang(30017))
_ensure_resolve(abort=True) _ensure_resolve(abort=True)
return 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( playqueue = PQ.get_playqueue_from_type(
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type]) v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type])
try: try:
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.error('No position returned from Kodi player!')
_playlist_playback(plex_id, plex_type) # "Play error"
else: dialog('notification', lang(29999), lang(30128), icon='{error}')
_ensure_resolve(abort=True)
return
# 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
LOG.debug('playQueue position %s for %s', pos, playqueue) LOG.debug('playQueue position %s for %s', pos, playqueue)
@ -102,9 +109,6 @@ def _playlist_playback(plex_id, plex_type):
for the next item in line :-) for the next item in line :-)
(by the way: trying to get active Kodi player id will return []) (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)
xml = GetPlexMetadata(plex_id) xml = GetPlexMetadata(plex_id)
try: try:
xml[0].attrib xml[0].attrib
@ -114,9 +118,15 @@ def _playlist_playback(plex_id, plex_type):
dialog('notification', lang(29999), lang(30128), icon='{error}') dialog('notification', lang(29999), lang(30128), icon='{error}')
_ensure_resolve(abort=True) _ensure_resolve(abort=True)
return return
# Kodi bug: playqueue will ALWAYS be audio playqueue UNTIL playback
# has actually started. Need to tell Kodimonitor
playqueue = PQ.get_playqueue_from_type(v.KODI_PLAYLIST_TYPE_AUDIO)
playqueue.clear(kodi=False)
# Set the flag for the potentially WRONG audio playlist so Kodimonitor
# can pick up on it
playqueue.kodi_playlist_playback = True
playlist_item = PL.playlist_item_from_xml(xml[0]) playlist_item = PL.playlist_item_from_xml(xml[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

@ -160,6 +160,8 @@ RESUME_PLAYBACK = False
CONTEXT_MENU_PLAY = False CONTEXT_MENU_PLAY = False
# Set by context menu - shall we force-transcode the next playing item? # Set by context menu - shall we force-transcode the next playing item?
FORCE_TRANSCODE = False FORCE_TRANSCODE = False
# Flag if user started playback of a PLAYLIST (not playqueue) for add-on paths
PLAYLIST_PLAY = False
# Kodi webserver details # Kodi webserver details
WEBSERVER_PORT = 8080 WEBSERVER_PORT = 8080