How to xbmcgui.ListItem / addDirectoryItem open function instead of url ?
#1
Hey Guys.

I'm new at python and i'm trying to built my first addon.
Source: http://kodi.wiki/view/audio-video_add-on_tutorial

So far so good...

My code:

python:
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin

base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'movies')

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

mode = args.get('mode', None)

if mode is None:
    url = build_url({'mode': 'folder', 'foldername': 'Folder One'})
    li = xbmcgui.ListItem('Folder One', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'folder':
    foldername = args['foldername'][0]
   
    url = 'http://localhost/some_video.mkv'
    li = xbmcgui.ListItem(foldername + ' Video', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    url = 'http://localhost/some_audio.mp3'
    li = xbmcgui.ListItem(foldername + ' Song', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
   
    xbmcplugin.endOfDirectory(addon_handle)

This code is working. But how to add a xbmcgui.ListItem / addDirectoryItem that opens a function instead of url ?

Simple function example:

python:
def test:
    xbmcgui.Dialog().ok('Test', 'Text.')

test()

I hope there is someone who can explain it. Thanks.
Reply
#2
if you had looked merely 5 threads below the one you started, i answered this thoroughly! https://forum.kodi.tv/showthread.php?tid=324921 topic title is even almost the same dude.
Reply
#3
(2017-12-13, 15:02)spiff Wrote: if you had looked merely 5 threads below the one you started, i answered this thoroughly! https://forum.kodi.tv/showthread.php?tid=324921 topic title is even almost the same dude.
 Thanks. But i did not understand it.
I have to use setResolvedUrl. Ok, but how to put it into my code?
Can you show me an example, please @spiff ?
Reply
#4
i'm not sure what more i can do. i have explained how it worked, the thread has a verbatim example of how such an url should look, you have 500 plugins in the repo using this, and you have all the keywords you need to grep for.
Reply
#5
I don't really know what you mean by "open a function" but there can be 3 types of plugin calls:
1) A virtual folder. For that you need to provide isFolder=True to addDirectoryItem().
2) A playable item that ends with setResolvedUrl(). For that you need to set listitem.setProperty('isPlayablle', 'true') and isFolder=False.
3) A generic call that can do any operations except for 1 and 2. For that you only need to set isFolder=False. For example, you can use a generic call to perform a login to some site.
Reply
#6
(2017-12-15, 21:00)Roman_V_M Wrote: I don't really know what you mean by "open a function" but there can be 3 types of plugin calls:
1) A virtual folder. For that you need to provide isFolder=True to addDirectoryItem().
2) A playable item that ends with setResolvedUrl(). For that you need to set listitem.setProperty('isPlayablle', 'true') and isFolder=False.
3) A generic call that can do any operations except for 1 and 2. For that you only need to set isFolder=False. For example, you can use a generic call to perform a login to some site.
 Hey @Roman_V_M .

I wanna have a simple list.

1st listitem opens a video.
2nd listitem opens a mp3.
3rd listitem opens a script or a function.

Here my code:
python:
    url = 'http://link.to.video'
    li = xbmcgui.ListItem(foldername + ' Video', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
   
    url = 'http://link.to.audio'
    li = xbmcgui.ListItem(foldername + ' Audio', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    url = 'XBMC.runScript(special://home/addons/plugin.video.test/test.py)'
    li = xbmcgui.ListItem(foldername + 'Test', iconImage='DefaultVideo.png')
    li.setProperty('IsPlayable', 'True')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
       
    xbmcplugin.endOfDirectory(addon_handle)

1st and 2nd listitems are working, but how to get the 3rd working?

test.py
python:

import xbmcgui
xbmcgui.Dialog().ok('Test', 'Text.')
Reply
#7
@Publish3r As I said, you need variant 3 from my list. And note that plugins have some rough similarity to good old CGI scripts: Kodi launches a plugin and pass it call parameters via a URL query string. So your URLs must be proper plugin calls. Technically you can use direct links to media for your playable items, but it's not a best practice. And for a generic call just pass right parameters and do whatever you want except for calling xbmcplugin API.
Reply
#8
I got it.
Reply

Logout Mark Read Team Forum Stats Members Help
How to xbmcgui.ListItem / addDirectoryItem open function instead of url ?0