Plugin Add-on API Clarification / Optimization
#1
Hi!

I've spent a couple of days tinkering with the Plugin API (specifically, Video Plugin), looked at examples and wrote my own one that's already very functional and useful to me. Thanks to everyone who is and was involved in building Kodi and documenting the APIs!

But there are just some things I cannot make sense of and hope that you can help me with that.

Right now, for all the list items that are supposed to behave like folders (like a tvshow entry in a list of tvshows and a season entry in a list of tvshow seasons) I use
python:

item = xbmcgui.ListItem(...)
...
item.setIsFolder(true)
item.setProperty('isPlayable',false)
item.setInfo('video',{
    ...
    'mediatype': mediatype
    ...
})

where mediatype is `tvshow` for a directory of seasons and `season` for a directory of episodes. Is this right? I noticed that when I select such an entry in Kodi and hit the info butten, I get presented with what I expect to see: A dialog with a lot of meta information about a show/season. I also see a "browse" button at the bottom. But klicking this "browse" button somehow tries to "play" the directory instead of just "openening" it. I can see in kodi.log that a Video player is trying to play the directory 5 times before it gives up. Am I doing something wrong here or is this a known bug? The Youtube plugin seems to have the same problem.

Then, I'm also trying to optimize things. I have a list that is kind of large (around 250 entries but with a lot of meta information like cast, studio, art etc) and it takes the Raspberry PI 3 with Kodi 18.4 a couple of seconds to load it. Is there a way to speed this up? I'm almost sure most of the time is spent transforming the JSON data and feeding it to kodi. Is it possible feed Kodi with the data in multiple passes? Like first pass = only the labels, 2nd pass = the remainder of the metadata? I also tried to feed Kodi with multiple chunks by calling addDirectoryItems more than once with a correctly set totalItems parameter. I kind of expected this to make Kodi show the first couple of entries to the user immediately before endOfDirectory is invoked. But this does not seem to happen and I still see the turning wheels for a couple of seconds. Any other ideas? Is this perhaps related to the "resume:false" argument that my plugin always receives? What's the meaning of that? In what situations could it be 'resume:true'? How do I control that? I did not find the documentation for a plugin's arguments.

Also, I don't really understand caching. endDirectory accepts a cacheToDisc parameter. In the documentation it says "[opt] bool - True=Folder will cache if extended time(default)/False=this folder will never cache to disc." What does "if extended time" mean? Does the Kodi Python Plugin API support something like the HTTP if-modified-since header with which Kodi could ask the Plugin whether the old list is still valid or it should expect to receive a new one?

Thank you in advance!
Reply
#2
You might want to try the ListItem offscreen=True option and the reuselanguageinvoker option in addon.xml
Minimize the amount of Listitem.set**() calls as these are slow, minimise the amount of addDirectoryItem calls, they are also slow.
The directory cache is generally pretty wonky and has many issues, and is only relevant in some cases like when navigating up "..", you can disable it if your addon in fast enough for you.
For caching fetched web data use sqlite or json file.
Reply
#3
Holy sh!t

Thank you very much for your suggestions. It seems like offscreen=True helped reduce the directory listing time a great deal. The languageinvoker setting maybe helped a little, too. I didn't do exact timings. I would estimate it's like 10 times faster now! :-)

Thanks again.
Reply
#4
(2019-12-11, 22:32)sellibitze Wrote: Holy sh!t

Thank you very much for your suggestions. It seems like offscreen=True helped reduce the directory listing time a great deal. The languageinvoker setting maybe helped a little, too. I didn't do exact timings. I would estimate it's like 10 times faster now! :-)

Thanks again.

The two are contradictory settings ... Meaning offscreen=true is meant to reduce UI overhead for listitems not seen onscreen meaning background/offscreen lists. Not your traditional video plugin.

Whereas languageinvoker is a process call that limits/changes how the plugin is initialized to reduce unwanted callbacks. Ie. Possibly enhances a standard plugin not a script or background process.

You rarely need both and since they are not defaults enabling them without understand them may cause unforseen issues. Making debugging a pain.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#5
Thanks for your input!

(2019-12-12, 00:18)Lunatixz Wrote: offscreen=true is meant to reduce UI overhead for listitems not seen onscreen meaning background/offscreen lists.
OK. Well, it could have been OK to use in this context. They are created offscreen and only passed to xbmc/filesystem/PluginDirectory.cpp which would then make it available to the GUI somehow. Seems like PluginDirectory.cpp would be a good place to take care of this since it's in C++ land where you can do things a little more quickly?

I certainly wouldn't want to provoke any kind of data race (I understand offscreen=True will omit some kind of synchronization). Do you know where the slowness with offscreen=False is coming from? It kind of boggles my mind that it makes such a huge difference. I tried to check but I couldn't find any reference to offscreen in xbmc/FileItem.cpp.

(2019-12-12, 00:18)Lunatixz Wrote: Whereas languageinvoker is a process call that limits/changes how the plugin is initialized to reduce unwanted callbacks. Ie. Possibly enhances a standard plugin not a script or background process.
Could you go into a little more detail here? I thought this was about reusing the Python interpreter instance across plugin invocations. But I wouldn't know how because it would still need to process everything from the plugin (including imports) each time because it's run "as a script" and not imported like a module with an invocation of some entry function, right?

Are there any documents I should look at to make more sense of how things are structed and how things work, apart from the source code I mean?
Reply
#6
Old thread about offscreen=True
https://forum.kodi.tv/showthread.php?tid=307394
Reply

Logout Mark Read Team Forum Stats Members Help
Plugin Add-on API Clarification / Optimization0