diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 47dc50a50..71acf1b8e 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1572,3 +1572,11 @@ msgstr "" msgctxt "#30816" msgid "List is empty.[CR][CR]Refresh from context menu or try again later." msgstr "" + +msgctxt "#30817" +msgid "Refresh settings.xml" +msgstr "" + +msgctxt "#30818" +msgid "Are you sure you want to refresh settings.xml?" +msgstr "" diff --git a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py index f43c5f3b2..21a69b45e 100644 --- a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py +++ b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py @@ -159,6 +159,7 @@ class XbmcContext(AbstractContext): 'purchases': 30622, 'recommendations': 30551, 'refresh': 30543, + 'refresh.settings.confirm': 30818, 'related_videos': 30514, 'remove': 30108, 'removed': 30666, diff --git a/resources/lib/youtube_plugin/kodion/script_actions.py b/resources/lib/youtube_plugin/kodion/script_actions.py index f3234bd50..88c85a3f3 100644 --- a/resources/lib/youtube_plugin/kodion/script_actions.py +++ b/resources/lib/youtube_plugin/kodion/script_actions.py @@ -21,7 +21,7 @@ ) from .context import XbmcContext from .network import get_client_ip_address, httpd_status -from .utils import rm_dir, validate_ip_address +from .utils import current_system_version, rm_dir, validate_ip_address def _config_actions(context, action, *_args): @@ -150,6 +150,48 @@ def _maintenance_actions(context, action, params): targets[target]().clear() ui.show_notification(localize('succeeded')) + elif action == 'refresh': + targets = { + 'settings_xml': 'settings.xml', + } + path = targets.get(target) + if not path: + return + + if target == 'settings_xml' and ui.on_yes_no_input( + context.get_name(), localize('refresh.settings.confirm') + ): + if not current_system_version.compatible(20, 0): + ui.show_notification(localize('failed')) + return + + import xml.etree.ElementTree as ET + + path = xbmcvfs.translatePath(os.path.join(DATA_PATH, path)) + xml = ET.parse(path) + settings = xml.getroot() + + marker = settings.find('setting[@id="|end_settings_marker|"]') + if marker is None: + ui.show_notification(localize('failed')) + return + + removed = 0 + for setting in reversed(settings.findall('setting')): + if setting == marker: + break + settings.remove(setting) + removed += 1 + else: + ui.show_notification(localize('failed')) + return + + if removed: + xml.write(path) + ui.show_notification(localize('succeeded')) + else: + return + elif action == 'delete': path = params.get('path') targets = { diff --git a/resources/settings.xml b/resources/settings.xml index cb6b23b2b..d01bd58dc 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1125,7 +1125,6 @@ - 0 @@ -1137,6 +1136,16 @@ true + + 0 + + true + + RunScript($ID,maintenance/refresh?target=settings_xml) + + true + +