XBMC Community Forum
[Trick] Faster listing of items - Printable Version

+- XBMC Community Forum (http://forum.xbmc.org)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Python Add-on Development (/forumdisplay.php?fid=26)
+--- Thread: [Trick] Faster listing of items (/showthread.php?tid=118083)

[Trick] Faster listing of items - TobiasTheCommie - 2011-12-29 18:20

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:

And then a playback function like this.
PHP Code:
def playVideo(selfparams={}):
get params.get
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:
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.

- Popeye - 2012-01-03 02:15

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.

- paddycarey - 2012-02-20 01:05

Thanks! This just reduced the time to load for my MMAFighting.com plugin from about 5 min to 10 seconds Big Grin

RE: [Trick] Faster listing of items - sphere - 2012-04-10 07:38

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:
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.


RE: [Trick] Faster listing of items - lexandstuff - 2012-08-08 11:05

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:

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

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