Plugin authors: Make sure your URL options are URL encoded
#1
Hi there,

Quite a few plugins seem to have problems due to a change in XBMC's URL handling. The gist of it is that all URL options need to be URL encoded.

This is so that we can parse them reliably (it's also so that the URLs are valid).

i.e.

plugin://plugin.foo.bar/what/ever/you/like?url_option=<url encoded option>&url_option2=<url encoded option>

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#2
so how do I enter this and where?
Reply
#3
Not so much used in python add on I've seen, but parse_qs (urlparse) and urlencode (urllib) standard python functions do the job for you ...

A parse_qs(urlparse(url).query) return a dictionnary of the parameters already decoded if needed (%...), sure url may contain sys.argv[2] for a plugin (be careful, the dictionnary returned by parse_qs contain arrays of values as a http parameter may be a list of values) and in the other side, a urlencode(<python dictionnary>) return an encoded query part in the form field1=xxxx&field2=yyy%3F ...

This will save time and make more readable code.
Reply
#4
This is how I do it. I figure I might as well post it here:

parameters variable should be a dict:
Code:
parameters = {"mode" : "show", "link": "http://Test.link/video?id=1234", "subs": "http://test.link/to/some/subs?id=text&format=raw", "art": "http://test.link/to/some/fanart?id=image&format=large"}

Code:
url = sys.argv[0] + '?' + urllib.urlencode(parameters)

Code:
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li, isFolder=folder)

This would result in your url being sent back to you addon like so (sys.argv[2] contains your parameters):
Code:
?art=http%3a%2f%2ftest.link%2fto%2fsome%2ffanart%3fid%3dimage%26format%3dlarge&
link=http%3a%2f%2fTest.link%2fvideo%3fid%3d1234&mode=show&subs=http%3a%2f%2ftest.link%2fto%2fsome%2fsubs%3fid%3dtext%26format%3draw
Reply
#5
Yes, and you get back your parameters with a simple parameters = parse_qs(urlparse(sys.argv[2]).query) -> parameters ["mode"][0], parameters ["link"][0] ... with your example.

With two line of code, you can write your add on having "simple" dictionnaries and forget unreadable url scheme.
Reply

Logout Mark Read Team Forum Stats Members Help
Plugin authors: Make sure your URL options are URL encoded0