Kodi Community Forum

Full Version: Detect Plugin use
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Is is possible to run an external script when a plugin is loaded and unloaded?

I basically want to bring up a VPN connection when I access certian video plugins to get around geo-blocking. However I also want the vpn to be disconnected when the plugin is exited. What is the best way to do this?

Any help would be appriciated.

Thanks

James
brownjl99 Wrote:Is is possible to run an external script when a plugin is loaded and unloaded?

No.

brownjl99 Wrote:I basically want to bring up a VPN connection when I access certian video plugins to get around geo-blocking. However I also want the vpn to be disconnected when the plugin is exited. What is the best way to do this?

I would write a Python script to connect the VPN, launch the plugin then disconnect the VPN. It would be something like (caution hurtriedly hacked together code follows!):

Code:
import sys
import subprocess
import xbmc

child = subprocess.Popen("ConnectVPN.bat")
rc = child.wait()

# run the add-on

child = subprocess.Popen("DisconnectVPN.bat")

I don't think I've ever used Python to launch an add-on, but I'd guess you'd use the RunAddon or RunPlugin builtins (see http://wiki.xbmc.org/?title=List_of_Built_In_Functions) and use xbmc.executebuiltin to run the builting function i.e.

Code:
xbmc.executebuiltin('RunAddon(addonid)')

JR
Ok I will give that ago Smile

Thanks veyr much for the hints and the python code - supose its time to learn python!

James
Had a little play with this. It would appear that the runaddon command instantly returns to the script after loading the addon. So I am executting the disconnect command whilst the addon is still running.

Is there a method to wait for the addon to close?

Thanks again,

James
Ah, now I think about it the RunAddon would have to return immediately. The add-on runs as part of XBMC so you can't suspend XBMC while you wait for the add-on to complete.

You could write a second script to disable the VPN, but you'd need to run this manually after you'd finished with the add-on.

Actually, add-ons are just Python scripts. You could probably edit the add-on to make it connect and disconnect the VPNs as appropriate. If you go down this path you probably want to change the add-on version info to stop it being automatically updated.

JR