Adding text from custom script to Kodi Home page via XML

1.3k views Asked by At

I'm guessing this is fairly easy for someone who knows what they are doing. Unfortunately I don't and as much as I would like to spend the next three days googling stuff my 4 year old got a lot of new presents for Christmas and I really should play with him so maybe someone can help me out.

I want to add my external IP address and Geo location to the Kodi home page.

I've taken a copy of the default skin and located the Home.xml file that is used to generate the home page. I have added a label but I don't know how to get this label to display the results of a script.

For example I have a bash getmyip.sh script that is located in /storage/downloads/ and runs the simple bit of code below.

curl -s http://whatismijnip.nl |cut -d " " -f 5

This gives me my external IP.

I've added a label to the home.xml file as shown below. This was written by someone else and gives me my internal IP.

The question is how can I modify it by running my script (or heck some other method) to get my external IP and Geo location when connected to my VPN? Any suggestions gratefully received. I just don't really know any XML.

Thank you!

    <control type="label">
            <description>IP Address</description>
            <left>200</left>
            <top>5</top>
            <height>49</height>
            <width min="200" max="300">auto</width>
            <label>IP: $INFO[Network.IPAddress]</label>
            <align>left</align>
            <aligny>center</aligny>
            <font>font12</font>
            <textcolor>white</textcolor>
            <shadowcolor>black</shadowcolor>
    </control> 
1

There are 1 answers

0
Spezi94 On BEST ANSWER

You have to adjust your getmyip.sh to the following code:

#!/bin/sh
python getmyexternalip.py

Then create the python file called getmyexternalip.py and add following code:

import subprocess
import xbmcgui

output = subprocess.check_output("curl -s http://whatismijnip.nl |cut -d ' ' -f 5", shell=True)
output = output.rstrip('\n')

xbmcgui.Window(10000).getControl(32000).setLabel("IP: " + str(output))

Also you have to adjust the XML to have an id on this control:

<control type="label" id="32000">

Please consider that the id has to be the same as in the parameter in the xbmcgui.Window(10000).getControl function.

The ID 10000 in the python script for the window is the default Window ID for the Home.xml