Skip to content

Commit

Permalink
Further updates to multiple busy dialog workaround
Browse files Browse the repository at this point in the history
- May fix anxdpanic#649
  • Loading branch information
MoojMidge committed Mar 28, 2024
1 parent 7534910 commit 343cd3c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_playlistid(cls):

try:
playlistid = int(result['result']['playlistid'])
except KeyError:
except (KeyError, TypeError, ValueError):
playlistid = cls._PLAYER_PLAYLIST['video']

cls._CACHE['playlistid'] = playlistid
Expand All @@ -128,7 +128,7 @@ def get_items(self, properties=None, dumps=False):
try:
result = response['result']['items']
return json.dumps(result, ensure_ascii=False) if dumps else result
except KeyError:
except (KeyError, TypeError, ValueError):
error = response.get('error', {})
self._context.log_error('XbmcPlaylist.get_items error - |{0}: {1}|'
.format(error.get('code', 'unknown'),
Expand All @@ -153,6 +153,8 @@ def add_items(self, items, loads=False):
# },
# no_response=True)

return len(items)

def play_playlist_item(self, position, resume=False):
"""
Function to play item in playlist from a specified position, where the
Expand Down
35 changes: 27 additions & 8 deletions resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,49 @@ def run(self, provider, context):
if ui.get_property('busy').lower() == 'true':
ui.clear_property('busy')
if ui.busy_dialog_active():
ui.show_notification('Multiple busy dialogs active - Kodi may crash')
playlist = XbmcPlaylist('auto', context)
playlist.clear()
xbmcplugin.endOfDirectory(self.handle, succeeded=False)

context.log_warning('Multiple busy dialogs active - '
'playlist cleared to avoid Kodi crash')
ui.show_notification('Multiple busy dialogs active - '
'Kodi may crash')

num_items = 0
items = ui.get_property('playlist')
position = ui.get_property('position')

if position and items:
position = int(position)
ui.clear_property('playlist')
playlist.add_items(items, loads=True)
context.log_warning('Multiple busy dialogs active - '
'playlist reloaded to avoid Kodi crash')

max_wait_time = 5
max_wait_time = 30
while ui.busy_dialog_active():
max_wait_time -= 1
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'extended busy period')
break
context.sleep(1)

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')
num_items = playlist.add_items(items, loads=True)

if position and num_items:
position += 1
max_wait_time = min(position, num_items)
while ui.busy_dialog_active() or playlist.size() < position:
max_wait_time -= 1
if max_wait_time <= 0:
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'unable to restart playback')
break
context.sleep(1)
else:
playlist.play_playlist_item(int(position) + 1)
playlist.play_playlist_item(position)

xbmcplugin.endOfDirectory(self.handle, succeeded=False)
return False

if settings.is_setup_wizard_enabled():
Expand Down

0 comments on commit 343cd3c

Please sign in to comment.