From 076d7217956baa80eb25543c51cfcc914997b34a Mon Sep 17 00:00:00 2001
From: MoojMidge <56883549+MoojMidge@users.noreply.github.com>
Date: Mon, 16 Sep 2024 06:09:23 +1000
Subject: [PATCH] Move IP location lookup to script and add to settings dialog
---
.../lib/youtube_plugin/kodion/script_actions.py | 11 ++++++++++-
.../youtube/helper/yt_setup_wizard.py | 16 ++++++++--------
resources/settings.xml | 10 ++++++++++
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/resources/lib/youtube_plugin/kodion/script_actions.py b/resources/lib/youtube_plugin/kodion/script_actions.py
index 62dbaad47..37cb391dc 100644
--- a/resources/lib/youtube_plugin/kodion/script_actions.py
+++ b/resources/lib/youtube_plugin/kodion/script_actions.py
@@ -20,7 +20,7 @@
WAIT_END_FLAG,
)
from .context import XbmcContext
-from .network import get_client_ip_address, httpd_status
+from .network import Locator, get_client_ip_address, httpd_status
from .utils import current_system_version, rm_dir, validate_ip_address
@@ -126,6 +126,15 @@ def _config_actions(context, action, *_args):
else:
ui.show_notification(context.localize('httpd.not.running'))
+ elif action == 'geo_location':
+ locator = Locator(context)
+ locator.locate_requester()
+ coords = locator.coordinates()
+ if coords:
+ context.get_settings().set_location(
+ '{0[lat]},{0[lon]}'.format(coords)
+ )
+
def _maintenance_actions(context, action, params):
target = params.get('target')
diff --git a/resources/lib/youtube_plugin/youtube/helper/yt_setup_wizard.py b/resources/lib/youtube_plugin/youtube/helper/yt_setup_wizard.py
index ea6ccabc4..ac7a03239 100644
--- a/resources/lib/youtube_plugin/youtube/helper/yt_setup_wizard.py
+++ b/resources/lib/youtube_plugin/youtube/helper/yt_setup_wizard.py
@@ -14,7 +14,7 @@
from ...kodion.compatibility import urlencode, xbmcvfs
from ...kodion.constants import ADDON_ID, DATA_PATH, WAIT_END_FLAG
-from ...kodion.network import Locator, httpd_status
+from ...kodion.network import httpd_status
from ...kodion.sql_store import PlaybackHistory, SearchHistory
from ...kodion.utils import current_system_version, to_unicode
from ...kodion.utils.datetime_parser import strptime
@@ -296,13 +296,13 @@ def process_geo_location(context, step, steps, **_kwargs):
(localize('setup_wizard.prompt')
% localize('setup_wizard.prompt.my_location'))
):
- locator = Locator(context)
- locator.locate_requester()
- coords = locator.coordinates()
- if coords:
- context.get_settings().set_location(
- '{0[lat]},{0[lon]}'.format(coords)
- )
+ context.execute(
+ 'RunScript({addon_id},config/geo_location)'.format(
+ addon_id=ADDON_ID,
+ ),
+ wait_for=WAIT_END_FLAG,
+ )
+ context.get_settings(refresh=True)
return step
diff --git a/resources/settings.xml b/resources/settings.xml
index d9c846891..140b5503f 100644
--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -874,6 +874,16 @@
30550
+
+ 0
+
+ true
+
+ RunScript($ID,config/geo_location)
+
+ true
+
+
0