Is it possible to execute builtin function from a listitem in a plugin?
#1
Hi everybody,
No luck with my previous question, so I try again with this new one.
I need to execute a builtinfunction clicking on a listitem in my virtual folder.
Is there any way to do this?
I've been able to do this via a context menu, but the solution is not comfortable for the user.
Please a little help.
I'm also very confused about how to prevent a playable item to play....
Thank in advance.
Reply
#2
No answers till now... hmmmm
Reply
#3
Well you should post your code so people are able to help. I am doing the same in extendedinfo script at some places and do not have any problems with launching builtins.
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#4
Thank phil65,
I've been able to solve by myself the problem of preventing a playable item to play. The solution has been found by setting correctly the folder param and the isPlayable property.

I've took a look at your script, it's fantastic.

Now I try to extract the piece of code to put here to explain my problem.
Thank again
Reply
#5
This is the pseudo code of what I would like to obtain in my plugin (not a script).
Keep in mind the listitem of the 'A' param MUST be isFolder=False
Code:
param = sys.argv[2]
                ....
                if param == 'A':
                    li = xbmcgui.ListItem(label=item.title, label2=item.title)
                    url = "plugin://.....&param = 'B'"
                    xbmcplugin.addDirectoryItem(config.get_handle(), url=url, listitem=li, isFolder=False, totalItems=0)
                    xbmcplugin.endOfDirectory(config.get_handle(), True, False)
                elif param == 'B':
                    url = "plugin://.....&param = 'C'"
                    xbmc.executebuiltin('XBMC.RunPlugin(%s)' % url)
                elif param == 'C'
                    title = "whatever you want"
                    li = xbmcgui.ListItem(label=item.title, label2=item.title)
                    url = "plugin://.....&param = 'xxx'"
                    xbmcplugin.addDirectoryItem(config.get_handle(), url=url, listitem=li, isFolder=False, totalItems=0)
                    ... repeat  previous 4 lines x times
                    xbmcplugin.endOfDirectory(config.get_handle(), True, False)

the config.get_handle() return the plugin handle (getted from sys.argv[1]), but when the plugin url has been called by an item with isFolder=False, it is -1.
So, when I reach the param == 'C' code part, nothing append and the xbmc.log says:

Code:
16:14:43 T:139816284976896 WARNING: Attempt to use invalid handle -1

Can you help me?
Reply
#6
I set the path for the listitem to 'plugin://script.extendedinfo/?info=launchbuiltin&builtin=some_builtin'
and then I just do
elif info == 'launchbuiltin':
xbmc.executebuiltin(params.get("builtin", ""))

that´s already enough.
I am not 100% sure if this also works exactly this way for "real" plugins though since I only use the plugin extension point for skin integration.
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#7
Thanks again phil,
The problem is not in ececuting the builtin function, but constructing a new listitem from that call.
As you can see from my pseudo-code the problem is that when the point B "call" (through the RunPlugin) the point "C" the point "C" will receive no handle (-1).
The only workaround that I've found is instead of calling RunPlugin(url), I call Container.Update(url). It works like a charm, but I'm not sure this is the right way to do this.
Hope this thread can help someone else.
Reply
#8
This makes no sense.. If you want to open a plugin url when clicking an item, just provide that url when adding the item.. That's how it works.
Reply
#9
You need to appreciate exactly what the isFolder parameter does.

It basically tells Kodi that when that list item is selected a new folder (ie list of items) is going to be created via calls to xbmcplugin.addDirectoryItem (the call to endOfDirectory tells Kodi that the list is complete and it can be displayed)

So according to your pseudocode the list items that led to param == A and param == C should have isFolder == True, whilst the other (ie B) should be False because that one doesn't create a new list)

At no point in the code you have posted though do you need to make use of the executebuiltin function.

What it looks like you need is in your param == A section, set the URL to param=C and set isFolder=True and get rid of the B stuff.

Also you ask about preventing playing a playable item, that makes no sense, if it is playable them you shouldn't be trying to prevent it from playing!

Look in my Super Favourites addon for examples of virtually every possible way of creating list items, playable items, triggering other addons, using executebuiltin, etc

(The answer to the question raised in the title of this thread is yes, but it doesn't look like you need to)
Reply
#10
Post deleted
Reply
#11
Hi spoyser
(2015-03-19, 22:03)spoyser Wrote: So according to your pseudocode the list items that led to param == A and param == C should have isFolder == True, whilst the other (ie B) should be False because that one doesn't create a new list)
I need to set isFolder to False because the when users press 'I' on an item, the skin shows different informations according to the isFolder status. Maybe ther's a way to force skin to behave like the isFolder is true...

(2015-03-19, 22:03)spoyser Wrote: Also you ask about preventing playing a playable item, that makes no sense, if it is playable them you shouldn't be trying to prevent it from playing!
I need to prevent playing because when I set the isPlayable status I don't yet know if the item will be playable. So I choose not to set isPlayable (I've found that setting isPlayable to False is the same that setting it to True), and manage the play manually, checking the existance of the url when it's choosed by the user.

(2015-03-19, 22:03)spoyser Wrote: Look in my Super Favourites addon for examples of virtually every possible way of creating list items, playable items, triggering other addons, using executebuiltin, etc
Thank a lot, I'll certainly take a look at it to get usefull techniques.
Reply
#12
(2015-03-20, 19:34)sMystero Wrote: Hi spoyser
(2015-03-19, 22:03)spoyser Wrote: So according to your pseudocode the list items that led to param == A and param == C should have isFolder == True, whilst the other (ie B) should be False because that one doesn't create a new list)
I need to set isFolder to False because the when users press 'I' on an item, the skin shows different informations according to the isFolder status. Maybe ther's a way to force skin to behave like the isFolder is true...

(2015-03-19, 22:03)spoyser Wrote: Also you ask about preventing playing a playable item, that makes no sense, if it is playable them you shouldn't be trying to prevent it from playing!
I need to prevent playing because when I set the isPlayable status I don't yet know if the item will be playable. So I choose not to set isPlayable (I've found that setting isPlayable to False is the same that setting it to True), and manage the play manually, checking the existance of the url when it's choosed by the user.

(2015-03-19, 22:03)spoyser Wrote: Look in my Super Favourites addon for examples of virtually every possible way of creating list items, playable items, triggering other addons, using executebuiltin, etc
Thank a lot, I'll certainly take a look at it to get usefull techniques.

It might be easier to grasp what you are doing if you post the actual code (pastebin) rather than pseudocode.

What you have at the moment though (ie the B stuff), is definitely wrong (even if it works LOL)

With regards playback, if you are going to manage the playback yourself (presumably by calling xbmc.Player().play() at some stage) then you should always set isPlayable to False, this is because setting it to True only means Kodi expects xbmcplugin.setResolvedUrl to be called (by your addon) when the listitem is clicked.

This appears to be a common area of confusion with many addon developers, isPlayable doesn't really mean the item is a playable, it only means Kodi will wait for a call to xbmcplugin.setResolvedUrl and when this is called it will play the item. If you are going to play the item using xbmc.Player().play() then as far as Kodi is concerned it isn't playable.

(Super Favourites has code specifically to deal with addons erroneously coded in this way)
Reply
#13
(2015-03-21, 00:50)spoyser Wrote:
(2015-03-20, 19:34)sMystero Wrote: Hi spoyser
(2015-03-19, 22:03)spoyser Wrote: So according to your pseudocode the list items that led to param == A and param == C should have isFolder == True, whilst the other (ie B) should be False because that one doesn't create a new list)
I need to set isFolder to False because the when users press 'I' on an item, the skin shows different informations according to the isFolder status. Maybe ther's a way to force skin to behave like the isFolder is true...

(2015-03-19, 22:03)spoyser Wrote: Also you ask about preventing playing a playable item, that makes no sense, if it is playable them you shouldn't be trying to prevent it from playing!
I need to prevent playing because when I set the isPlayable status I don't yet know if the item will be playable. So I choose not to set isPlayable (I've found that setting isPlayable to False is the same that setting it to True), and manage the play manually, checking the existance of the url when it's choosed by the user.

(2015-03-19, 22:03)spoyser Wrote: Look in my Super Favourites addon for examples of virtually every possible way of creating list items, playable items, triggering other addons, using executebuiltin, etc
Thank a lot, I'll certainly take a look at it to get usefull techniques.

It might be easier to grasp what you are doing if you post the actual code (pastebin) rather than pseudocode.

What you have at the moment though (ie the B stuff), is definitely wrong (even if it works LOL)

With regards playback, if you are going to manage the playback yourself (presumably by calling xbmc.Player().play() at some stage) then you should always set isPlayable to False, this is because setting it to True only means Kodi expects xbmcplugin.setResolvedUrl to be called (by your addon) when the listitem is clicked.

This appears to be a common area of confusion with many addon developers, isPlayable doesn't really mean the item is a playable, it only means Kodi will wait for a call to xbmcplugin.setResolvedUrl and when this is called it will play the item. If you are going to play the item using xbmc.Player().play() then as far as Kodi is concerned it isn't playable.

(Super Favourites has code specifically to deal with addons erroneously coded in this way)

You're right. The B stuff has been replaced by
Code:
xbmc.executebuiltin('Container.Update(%s)' % url)

The previous code allow me to "route" the call, so I can choose whether or not to create the item folder.
pseudocode:
Code:
param = sys.argv[2]
                ....
                if param == 'A':
                    li = xbmcgui.ListItem(label=item.title, label2=item.title)
                    url = "plugin://.....&param = 'B'"
                    xbmcplugin.addDirectoryItem(config.get_handle(), url=url, listitem=li, isFolder=False, totalItems=0)
                    xbmcplugin.endOfDirectory(config.get_handle(), True, False)
                elif param == 'B':
                    if chekIt() == True:  #do some complex and time consuming checks to be done only if the end-user click on the item
                        url = "plugin://.....&param = 'C'"
                        xbmc.executebuiltin('Container.Update(%s)' % url)  #The history is well updated and everything works like a charm
                    else:
                        show_dialog_error("there's an error with the server")
                        # nothing else to do and no error on the xbmc.log like cguiwinodw::......
                elif param == 'C'
                    title = "whatever you want"
                    li = xbmcgui.ListItem(label=item.title, label2=item.title)
                    url = "plugin://.....&param = 'xxx'"
                    xbmcplugin.addDirectoryItem(config.get_handle(), url=url, listitem=li, isFolder=False, totalItems=0)
                    ... repeat  previous 4 lines x times
                    xbmcplugin.endOfDirectory(config.get_handle(), True, False)
                    #this list REPLACES the previous list build on A section. If end users goes back from this list, than the A list reconstructs perfectly
It's hard to post all the code because it's wrapped in some classes.

(2015-03-21, 00:50)spoyser Wrote: With regards playback, if you are going to manage the playback yourself (presumably by calling xbmc.Player().play() at some stage) then you should always set isPlayable to False, this is because setting it to True only means Kodi expects xbmcplugin.setResolvedUrl to be called (by your addon) when the listitem is clicked.

For the isPlayable issue I've noted that you shouldn't never set it to "false" otherwise it behaves like it has been set to true. To behave as "a non playable item" you should not set the property at all.

For the setResolvedUrl now (and only now, after spending hours and hours.... Angry SadSadSad ) it's very clear for me how it works but at the moment I prefere to call xbmc.Player().play() instead of using setResolvedUrl mechanism.

Again thank you very much.
Reply

Logout Mark Read Team Forum Stats Members Help
Is it possible to execute builtin function from a listitem in a plugin?0