Kodi Community Forum
How to access ListItem Properties from a plugin? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: How to access ListItem Properties from a plugin? (/showthread.php?tid=354817)



How to access ListItem Properties from a plugin? - drinfernoo - 2020-05-29

I'm in the midst of working on AutoWidget, and have found something that, in my opinion, is missing from Kodi's APIs. It doesn't appear to be possible in any reasonable way to access ListItem "Properties" from a Python plugin.

According to the documentation, someone can use ListItem.setProperty(...) to set a property on that item, with that property being later accessible via ListItem.getProperty(...), or by reading the ListItem.Property(your_property) InfoLabel, possibly prefixed with a combination of Container(container_id) and/or ListItem(index), depending on where in Kodi it needs to be retrieved from.

In my opinion, the "easiest" way to get a listing of items from a Kodi path (library or plugin) is to use JSON-RPC. In particular, we can make a call to Files.GetDirectory, in order to receive a response containing any of the InfoLabels specified in the query, as long as they are part of the available ones defined in List.Fields.Files. However... this method does not return ListItem Properties. They are absent from the response, and cannot be appended to the query by the calling script, as they aren't available as valid fields.

If I try to go the route of retrieving them via InfoLabels, I can populate a list control in a custom window with items from a certain path (by setting the <content> tag) will allow me to focus the items in the list, and read their InfoLabels and Properties. Unfortunately, by doing so, my custom window "steals" focus away from the normal skin windows, blocking any UI interaction until the window is closed... and that becomes even more of an issue when multiples of this process try to run at the same time, like in the instance of multiple widgets being pointed to endpoints which perform it. I had also thought it might be possible to use ControlList.getSelectedItem(), combined with some sort of list traversal, in order to find the actual ListItem underneath, but it appears that solution has already been ruled out, or at least for controls created in XML... which is the only way to populate a list control dynamically, a s far as I can tell. To do so in code, would mean I would still need to create all the ListItems from somewhere, which is the whole issue I'm facing in the first place.

None of these are valid solutions, as not one provides a way to reliably access the underlying ListItem, or their Properties, by a different (or the same!) plugin, after the fact. Even if the "mock window" method was to work reliably to retrieve ListItem Properties, there is still no general solution for gathering "all" of the assigned Properties... instead, you need to already know the name(s) or the Property(ies) you want the value of. What bothers me most is that the Properties are assigned no matter what. Both of the principal methods I outlined above run the code for the path in question, allowing the plugin to create and modify its ListItems as it pleases, output to the log, make API calls, etc... and ListItem Properties can still be grabbed, by the plugin, at this phase, even before xbmcplugin.endOfDirectory(...) has been called. Could these Properties not be simply added to the JSON response, to be passed along with the items? I suppose not  Rofl

I've created a very simple plugin to demonstrate that Properties are indeed attached before xbmcplugin.endOfDirectory(...) is called, and to simply show the code that I have tried regarding both of these methods. In my own plugin, the code is quite a bit more intensive, but even with this "test" plugin, I was able to completely freeze my Kodi by allowing multiple widgets to point at "Test Mock Window" Big Grin

You can grab the plugin (no funny business, I swear Smile) from the Releases page on GitHub, or check out the source code. The bulk of the work is done in plugin.py, with main.py being a two-liner "entry point", and mock_window.xml being a super barebones dialog with empty controls. Make sure to turn on debug logging to confirm that properties are being set and are retrievable before the end of the directory.

Please tell me, am I missing something? Is this deliberate, or an oversight?


RE: How to access ListItem Properties from a plugin? - drinfernoo - 2020-06-05

Can anyone offer any insight into this? I have a handful of add-ons in mind that attach properties to their items, and it seems a shame for them to basically only be accessible to the skin.

EDIT: Including legitimate add-ons like the Netflix, Disney+, YouTube, and Twitch add-ons, among others. These add-ons all use ListItem properties, and those properties are obviously not able to be accessed in any reasonable way by a Python script.


RE: How to access ListItem Properties from a plugin? - drinfernoo - 2020-06-07

I've also become aware of the Files.GetFileDetails method, which is supposedly fixed in Matrix, but even that appears to only be about to turn things from List.Fields.Files... unless I'm mistaken Big Grin