简体   繁体   中英

Execute a python script on the internet from another python script

Basically I have a python script which is an addon for Kodi. I would like to create some sort of IPTV and update channels accordingly but the addon won't get updated.

I've thought of a method where I have the python script hosted on the internet which includes several channels like this, then I call that script from the addon python script itself. Therefore when I want to add new channels, I only edit the script hosted on the internet. The internet script will look something like this:

url = 'link of channel'
li = xbmcgui.ListItem('Name of channel', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

Is this possible? Can I call this script hosted on the internet through another local python script and so it gets executed inside that script itself?

Thanks

You can download your script:

from urllib2 import urlopen
script = urlopen('url of your script')

Store somewhere where your plugin has access (ie resources/lib inside your addon folder):

import xbmcaddon
addon = xbmcaddon.Addon()
addonPath = addon.getAddonInfo('path')
script_data = script.read()
import xbmc
import os
script_file_path = os.path.join(xbmc.translatePath(addonPath), 'resources', 'lib', 'your_plugin.py')
script_file = open(scrip_file_path, 'w')
script_file.write(script_data)
script_file.close()

Then import it, and then call some functions you need from it.

from resources.lib.your_plugin import your_func
your_func()

Another way is not to host script itself on the server, but the list of channels, for example in JSON format, and then download it from plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM