Skip to content

Commit

Permalink
Move IP location lookup to script and add to settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Sep 15, 2024
1 parent 7ce4f89 commit 076d721
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
11 changes: 10 additions & 1 deletion resources/lib/youtube_plugin/kodion/script_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')
Expand Down
16 changes: 8 additions & 8 deletions resources/lib/youtube_plugin/youtube/helper/yt_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
10 changes: 10 additions & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,16 @@
<heading>30550</heading>
</control>
</setting>
<setting id="youtube.location.configure" type="action" label="30653" help="">
<level>0</level>
<constraints>
<allowempty>true</allowempty>
</constraints>
<data>RunScript($ID,config/geo_location)</data>
<control format="action" type="button">
<close>true</close>
</control>
</setting>
<setting id="youtube.location" type="string" label="30651" help="">
<level>0</level>
<default/>
Expand Down

0 comments on commit 076d721

Please sign in to comment.