[Trick] Faster listing of items
#1
Many plugins (for instance Google Listen) provides XBMC with a fully functioning URL to play.

This is the obvious implementation, but also extremely slow. XBMC will try to get MIME data for all the links. Thus if you have a list of 50 mp3's, the user will have to wait for XBMC to connect to all 50 urls, and check that it is an mp3.

For a faster implementation you can make a "start playback" function in your plugin, and give XBMC an URL to your playback url.

In the YouTube plugin a video is always given the following url:
PHP Code:
plugin://plugin.video.youtube/?path=root/video&action=play_video&videoid=ID 

And then a playback function like this.
PHP Code:
def playVideo(selfparams={}):
                
get params.get
                video 
self.getVideoObject(params)
                
listitem xbmcgui.ListItem(label=video['Title'], iconImage=video['thumbnail'], thumbnailImage=video['thumbnail'], path=video['video_url'])
                
xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=Truelistitem=listitem

Unless the plugin is using some kind of cache to remember the playable URL, they source will have to be fetched again. But this will still be a lot faster than having XBMC check MIME type of every item.

It is, of course, also possible to use an URL like this.
PHP Code:
plugin://plugin.some.plugin/?path=root&action=play&url=urllib.quote(my_url) 
Instead of using a cache or doing a second lookup.


And added bonus of doing this is that the servers we are requesting from will be hammered less. So the webmasters should be happier with us.
Reply
#2
Great trick!
I was wondering why it took so long for my SverigesRadio addon to list the stations. This is the solution, thanks.
I'm learning lots from you.
Pneumatic | SABnzbd | XBMC that just works - openelec
Reply
#3
Thanks! This just reduced the time to load for my MMAFighting.com plugin from about 5 min to 10 seconds Big Grin
Reply
#4
Even if I also prefer the setResolvedUrl-Method, I just wanted to add another method:

To avoid xbmc scanning the mime-type you can also just set it:
Code:
listitem.setProperty('mimetype', 'video/x-msvideo')

And also, if you use setResolvedMethod, you don't have to set all if its data (title, thumbnail, etc.) again - just add the path. XBMC will use the remaining properties from the original listitem.

regards,
sphere
My GitHub. My Add-ons:
Image
Reply
#5
This is probably going to sound mental to a lot of you, but if you're banging your head against the wall wondering why you're getting this error in the logs:

Code:
18:59:54 T:2961911808   ERROR:  SetResolvedUrl - called with an invalid handle.

It's probably because you haven't set the 'isPlayable' property on your listitem before using it as an argument to the addDirectoryItem() method

Code:
listitem.setProperty('IsPlayable', true')
xbmcplugin.addDirectoryItem(pluginHandle, url, listitem, isFolder=False, totalItems=totalItems)

It may seem obvious, but that's probably because you're better at life than me. Smile
Reply

Logout Mark Read Team Forum Stats Members Help
[Trick] Faster listing of items0