From 75a2faecc041293d309d9db756564bfa447d19e0 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:25:34 +1000 Subject: [PATCH] Further fixes for busy dialog crash workaround --- .../kodion/constants/__init__.py | 2 ++ .../kodion/plugin/xbmc/xbmc_plugin.py | 34 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/resources/lib/youtube_plugin/kodion/constants/__init__.py b/resources/lib/youtube_plugin/kodion/constants/__init__.py index 9dd42ad9c..58bdc8a5f 100644 --- a/resources/lib/youtube_plugin/kodion/constants/__init__.py +++ b/resources/lib/youtube_plugin/kodion/constants/__init__.py @@ -35,6 +35,7 @@ ABORT_FLAG = 'abort_requested' BUSY_FLAG = 'busy' CHECK_SETTINGS = 'check_settings' +PLAYLIST_PATH = 'playlist_path' PLAYLIST_POSITION = 'playlist_position' REROUTE = 'reroute' SLEEPING = 'sleeping' @@ -50,6 +51,7 @@ 'CHECK_SETTINGS', 'DATA_PATH', 'MEDIA_PATH', + 'PLAYLIST_PATH', 'PLAYLIST_POSITION', 'RESOURCE_PATH', 'REROUTE', diff --git a/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py b/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py index 6a525a85e..715c89ce8 100644 --- a/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py +++ b/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py @@ -14,7 +14,13 @@ from ..abstract_plugin import AbstractPlugin from ...compatibility import xbmcplugin -from ...constants import BUSY_FLAG, PLAYLIST_POSITION, REROUTE, SLEEPING +from ...constants import ( + BUSY_FLAG, + PLAYLIST_PATH, + PLAYLIST_POSITION, + REROUTE, + SLEEPING, +) from ...exceptions import KodionException from ...items import ( DirectoryItem, @@ -66,12 +72,23 @@ def run(self, provider, context): playlist = XbmcPlaylist('auto', context, retry=3) position, remaining = playlist.get_position() - items = playlist.get_items() if remaining else None + items = playlist.get_items() playlist.clear() context.log_warning('Multiple busy dialogs active - ' 'playlist cleared to avoid Kodi crash') + if items: + path = items[position - 1]['file'] + old_path = ui.get_property(PLAYLIST_PATH) + old_position = ui.get_property(PLAYLIST_POSITION) + if (old_position and position == int(old_position) + and old_path and path == old_path): + if remaining: + position += 1 + else: + items = None + if items: max_wait_time = 30 while ui.busy_dialog_active(): @@ -84,12 +101,8 @@ def run(self, provider, context): context.log_warning('Multiple busy dialogs active - ' 'reloading playlist') - num_items = playlist.add_items(items) - - old_position = ui.get_property(PLAYLIST_POSITION) - if old_position and position == int(old_position): - position += 1 + num_items = playlist.add_items(items) max_wait_time = min(position, num_items) while ui.busy_dialog_active() or playlist.size() < position: max_wait_time -= 1 @@ -102,10 +115,12 @@ def run(self, provider, context): playlist.play_playlist_item(position) ui.clear_property(BUSY_FLAG) + ui.clear_property(PLAYLIST_PATH) ui.clear_property(PLAYLIST_POSITION) return False ui.clear_property(BUSY_FLAG) + ui.clear_property(PLAYLIST_PATH) ui.clear_property(PLAYLIST_POSITION) if ui.get_property(SLEEPING): @@ -188,7 +203,10 @@ def _set_resolved_url(self, context, base_item): ui.set_property(BUSY_FLAG, 'true') playlist = XbmcPlaylist('auto', context) position, _ = playlist.get_position() - ui.set_property(PLAYLIST_POSITION, str(position)) + items = playlist.get_items() + if items: + ui.set_property(PLAYLIST_PATH, items[position - 1]['file']) + ui.set_property(PLAYLIST_POSITION, str(position)) item = self._PLAY_ITEM_MAP[base_item.__class__.__name__]( context,