Get items from plugins in Python
I have a list of paths to plug-in directories with movies and episodes (example below), and I'm trying access all of the ListItems in those paths.  I don't want to actually open the plugin windows because this script will be running in a background service.  How do I access these items from a Python script?

example_list = ['plugin://', 'plugin://']

I've tried all of the built-in functions I can think of... GetDirectory, RunAddon, RunPlugin, RunScript, ActivateWindow... None of them do what I need.  I think skins are able to access ListItems from plugins, but I don't have enough experience with them to figure out how.

I do know how to access all of the ListItems in the current container, so would it be possible to load the plugin items into a "hidden" container?  Then, I could run a script similar to this one.

    # example: loop through all items in current container and get paths
    item_paths = []
    ref_path = xbmc.getInfoLabel('ListItem.FileNameAndPath')
    path = xbmc.getInfoLabel('ListItem.FileNameAndPath')
    offset = 0
    while True:
        offset += 1
        path = xbmc.getInfoLabel('Container.ListItem(%s).FileNameAndPath' % offset)
        # returned ListItems will wrap back to beginning, so just check for the original item path
        if path == ref_path:

Since I only want the path of the items, is there an easier way to do this?  Maybe a JSON-RPC call?

Any help is much appreciated
AFAIK I fear that's not possible since plugins create the list items when they are called so those list items don't exist when the plugin isn't active. So you need to call them definitely but since xbmcgui.window is missing a getallcontrols you will only be able to get something you know the Id of. Agreed interfaces for a modular design pattern of add-on would help so that certain functionalities are always called with the same method name and are contained in scripts following a naming scheme but it will be tough to convince all add on devs to that.
(2018-01-14, 20:27)104084485 Wrote: Since I only want the path of the items, is there an easier way to do this?  Maybe a JSON-RPC call?
Yup, exactly.
Since xbmcplugin provides virtual directories you can use JSON-RPC's Files.GetDirectory method to retrieve any and all items in any of those virtual directories.
For the first item in your example_list that would be something like:
items = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory":"plugin://"}, "id": 1}')
@Takezo36 I think you're right, trying to load listitems like I was probably isn't possible

@Quihico This is exactly what I needed!  Thank you
strictly speaking there is no need to do through jsonrpc, you could just use the xbmcvfs python module.
Just out of curiosity ... will the getdirectories trigger the plugin to run or are those paths somehow cached?
It will execute the plugins.
(2018-01-15, 20:26)spiff Wrote: It will execute the plugins.
Sorry to revive an old thread, but I'm also looking to do something like this.

The issue I'm having is that using getDirectory(...), you get a list (or JSON dictionary) of the files themselves, which often don't contain enough information to garner the extra metadata/InfoLabels like plot, media info, or artwork.

An alternative I wondered if was possible would be to somehow execute the desired plugin in a background container (as expressed in the OP), but loop through the items and grab the actual InfoLabels?
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
Get items from plugins in Python00