Kodi Community Forum
Problem using setResolvedUrl - 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: Problem using setResolvedUrl (/showthread.php?tid=377481)

Pages: 1 2


Problem using setResolvedUrl - iceman20k - 2024-05-11

Hi all. When i use setResolvedUrl Kodi just won't play the URL. The URL plays with "xbmc.executebuiltin("PlayMedia("+play_url+")")", but then i can't set title.
I guess my problem is the Handle, when i log it, its "-1". This is my code:

Code:
HANDLE = int(sys.argv[1])

def play(url):
    ...
    play_url = video_infos.get("url")
    title = video_infos.get("title")
    list_item = xbmcgui.ListItem(label=title, path=play_url)
    xbmcplugin.setResolvedUrl(HANDLE, True, listitem=list_item)

Just nothing happens, even when i use Debug Log no useful info. Shouldn't my Plugin's Handle be something other than -1? Its my first Kodi addon, if anyone has a hint for me it would be great.


RE: Problem using setResolvedUrl - iceman20k - 2024-05-11

Found out i can use:
Code:
xbmc.Player().play(play_url,listitem=list_item)

This works and also sets the Title. Still, how can i get my valid plugin handle?


RE: Problem using setResolvedUrl - Lunatixz - 2024-05-11

(2024-05-11, 10:47)iceman20k Wrote: Found out i can use:
Code:
xbmc.Player().play(play_url,listitem=list_item)

This works and also sets the Title. Still, how can i get my valid plugin handle?

This method of playback is reserved for scripts and not recommend for plugin; I strongly suggest you resolve whatever issues you had with setresolved before proceeding with your project.


RE: Problem using setResolvedUrl - iceman20k - 2024-05-11

(2024-05-11, 18:11)Lunatixz Wrote:
(2024-05-11, 10:47)iceman20k Wrote: Found out i can use:
Code:
xbmc.Player().play(play_url,listitem=list_item)

This works and also sets the Title. Still, how can i get my valid plugin handle?

This method of playback is reserved for scripts and not recommend for plugin; I strongly suggest you resolve whatever issues you had with setresolved before proceeding with your project.

Thank You, i am trying. First of all i should find out if its normal that int(sys.argv[1]) is -1 (thats my HANDLE var, copied from plugin.video.example from the kodi.wiki)


RE: Problem using setResolvedUrl - jbinkley60 - 2024-05-11

(2024-05-11, 18:50)iceman20k Wrote: Thank You, i am trying. First of all i should find out if its normal that int(sys.argv[1]) is -1 (thats my HANDLE var, copied from plugin.video.example from the kodi.wiki)

Can we see your addon.xml file which denotes how your addon is being called and the handle is set ?  I think that may be the cause here.  Specifically we need to see any extension point lines in the addon.xml file.


Thanks,

Jeff


RE: Problem using setResolvedUrl - iceman20k - 2024-05-11

(2024-05-11, 21:43)jbinkley60 Wrote:
(2024-05-11, 18:50)iceman20k Wrote: Thank You, i am trying. First of all i should find out if its normal that int(sys.argv[1]) is -1 (thats my HANDLE var, copied from plugin.video.example from the kodi.wiki)

Can we see your addon.xml file which denotes how your addon is being called and the handle is set ?  I think that may be the cause here.  Specifically we need to see any extension point lines in the addon.xml file.


Thanks,

Jeff
Hi and thanks for your help. This is my addon.xml (which i adapted from plugin.video.example):

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.fxy" name="FXY Plugin" version="1.0.0" provider-name="FXY">
    <requires>
        <import addon="xbmc.python" version="3.0.0" />
        <import addon="script.module.requests" version="2.3.0" />
    </requires>
    <extension point="xbmc.python.pluginsource" library="main.py" />
    <provides>video</provides>
    <extension point="xbmc.service" library="fxysvc.py" />
    <extension point="xbmc.addon.metadata">
        <summary lang="en">Service for FXY</summary>
        <description lang="en">FXY Service that keeps the data up to date.</description>
        <platform>all</platform>
        <license>GPL-2.0-only</license>
        <assets>
            <icon>resources/icon.png</icon>
        </assets>
    </extension>
</addon>

main.py:

Code:

import ...
# Get the plugin url in plugin:// notation.
URL = sys.argv[0]
# Get a plugin handle as an integer number.
HANDLE = int(sys.argv[1])

 def router(paramstring):
  ...works great

if __name__ == '__main__':
    # Call the router
    router(sys.argv[2][1:])

The call for the plugin comes from a panel which i managed to include as "menu point" (similar if you have "Favourites" enabled, on the left side is the menu entry "Favourites" and on the right side are the items from favourites.xml)
The item's onclick values look like that:
Code:
<onclick>$INFO[Window(10000).Property($PARAM[fxyselect].7.url)]</onclick>
which resolves to:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"

But that .xml file, that is filled with this dynamic content, actually belongs to my other addon "skin.fxy", but that shouldnt be the problem, or? (As said, both, xbmc.Player() and xbmc.executebuiltin("PlayMedia.. play the video, so i guess its a problem with the handle.

Again, thanks a lot for the help!


RE: Problem using setResolvedUrl - kereltje - 2024-05-13

Guided by Jeff's remarks I noticed that in your addon.xml the tag <provides> is not a child of <extension>:
xml:

<extension point="xbmc.python.pluginsource" library="main.py" />
<provides>video</provides>

Try this:
xml:

<extension point="xbmc.python.pluginsource" library="main.py">
     <provides>video</provides>
</extension>



RE: Problem using setResolvedUrl - iceman20k - 2024-05-13

(2024-05-13, 14:46)kereltje Wrote: Guided by Jeff's remarks I noticed that in your addon.xml the tag <provides> is not a child of <extension>:
xml:

<extension point="xbmc.python.pluginsource" library="main.py" />
<provides>video</provides>

Try this:
xml:

<extension point="xbmc.python.pluginsource" library="main.py">
     <provides>video</provides>
</extension>

Wow, thanks for that hint! Good eye...XML can be...
Still "log_msg('HANDLE: '+ str(HANDLE), xbmc.LOGINFO)" gives me "-1" for HANDLE which is "HANDLE = int(sys.argv[1])"... ;(


RE: Problem using setResolvedUrl - iceman20k - 2024-05-13

Can it be a problem to also add the service extensions point in the same addon.xml, maybe the order, add the service before the main.py?
Or mixing up short syntax <extension point ... /> (for service) and normal XML syntax <extension point ... "> for main.py?


RE: Problem using setResolvedUrl - jbinkley60 - 2024-05-13

(2024-05-11, 22:49)iceman20k Wrote:
(2024-05-11, 21:43)jbinkley60 Wrote:
(2024-05-11, 18:50)iceman20k Wrote: Thank You, i am trying. First of all i should find out if its normal that int(sys.argv[1]) is -1 (thats my HANDLE var, copied from plugin.video.example from the kodi.wiki)

Can we see your addon.xml file which denotes how your addon is being called and the handle is set ?  I think that may be the cause here.  Specifically we need to see any extension point lines in the addon.xml file.


Thanks,

Jeff
Hi and thanks for your help. This is my addon.xml (which i adapted from plugin.video.example):

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.fxy" name="FXY Plugin" version="1.0.0" provider-name="FXY">
    <requires>
        <import addon="xbmc.python" version="3.0.0" />
        <import addon="script.module.requests" version="2.3.0" />
    </requires>
    <extension point="xbmc.python.pluginsource" library="main.py" />
    <provides>video</provides>
    <extension point="xbmc.service" library="fxysvc.py" />
    <extension point="xbmc.addon.metadata">
        <summary lang="en">Service for FXY</summary>
        <description lang="en">FXY Service that keeps the data up to date.</description>
        <platform>all</platform>
        <license>GPL-2.0-only</license>
        <assets>
            <icon>resources/icon.png</icon>
        </assets>
    </extension>
</addon>

main.py:

Code:

import ...
# Get the plugin url in plugin:// notation.
URL = sys.argv[0]
# Get a plugin handle as an integer number.
HANDLE = int(sys.argv[1])

 def router(paramstring):
  ...works great

if __name__ == '__main__':
    # Call the router
    router(sys.argv[2][1:])

The call for the plugin comes from a panel which i managed to include as "menu point" (similar if you have "Favourites" enabled, on the left side is the menu entry "Favourites" and on the right side are the items from favourites.xml)
The item's onclick values look like that:
Code:
<onclick>$INFO[Window(10000).Property($PARAM[fxyselect].7.url)]</onclick>
which resolves to:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"

But that .xml file, that is filled with this dynamic content, actually belongs to my other addon "skin.fxy", but that shouldnt be the problem, or? (As said, both, xbmc.Player() and xbmc.executebuiltin("PlayMedia.. play the video, so i guess its a problem with the handle.

Again, thanks a lot for the help!

Try adding:

import xbmcaddon

at the top of your main.py file if it isn't there already.  The same for:  fxysvc.py . 

If that doesn't fix it then we'll need to see what is being passed to your main.py file. You can add this near the top of your main.py file:

xbmc.log('Number of arguments: ' + str(len(sys.argv)), xbmc.LOGINFO)
xbmc.log('The arguments are: ' + str(sys.argv), xbmc.LOGINFO)

Lastly, when passing a URL you could run into a parsing / encoding issue which we may need to deal with.  You can see how I handle this here in one of my addons.


Thanks,

Jeff


RE: Problem using setResolvedUrl - kereltje - 2024-05-13

Quote:Can it be a problem to also add the service extensions point in the same addon.xml, maybe the order, add the service before the main.py?
Or mixing up short syntax <extension point ... /> (for service) and normal XML syntax <extension point ... "> for main.py?
No, that should not be a problem. However, if you run into problems the usual procedure is to try to isolate the problem. So yes, for the sake of testing I would remove that, and all other code that's not absolutely necessary to play the stream.
Quote:The call for the plugin comes from a panel which i managed to include as "menu point" (similar if you have "Favourites" enabled, on the left side is the menu entry "Favourites" and on the right side are the items from favourites.xml)
The item's onclick values look like that:
Code:
<onclick>$INFO[Window(10000).Property($PARAM[fxyselect].7.url)]</onclick>
[...]
But that .xml file, that is filled with this dynamic content, actually belongs to my other addon "skin.fxy", but that shouldnt be the problem, or? (As said, both, xbmc.Player() and xbmc.executebuiltin("PlayMedia.. play the video, so i guess its a problem with the handle.
So, correct me if I'm wrong, you have skin addon that provides dynamic content and you want to call another plugin to play the content?
I don't know what exactly you are doing and for what reason, but I very much wonder if you're on the right track. A skin should in general not concern itself with content. Even more so, the whole point of a plugin is that is a very easy way to provide dynamic listings, i.e. a "menu point", and let Kodi (and the skin) deal with how it's being displayed and user interaction.

Anyway,
Quote:which resolves to:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"
Calling the plugin this way it will not play the stream (and the handle will indeed be -1).
If you want to play a stream by letting a plugin resolve the final url you'll need to call 
Code:
PlayMedia(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive)
BTW, I hope this double quote before the closing brace is a typo in your post, rather than in your code ;-)


RE: Problem using setResolvedUrl - iceman20k - 2024-05-13

(2024-05-13, 16:57)jbinkley60 Wrote:
(2024-05-11, 22:49)iceman20k Wrote:
(2024-05-11, 21:43)jbinkley60 Wrote: Can we see your addon.xml file which denotes how your addon is being called and the handle is set ?  I think that may be the cause here.  Specifically we need to see any extension point lines in the addon.xml file.


Thanks,

Jeff
Hi and thanks for your help. This is my addon.xml (which i adapted from plugin.video.example):

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.fxy" name="FXY Plugin" version="1.0.0" provider-name="FXY">
    <requires>
        <import addon="xbmc.python" version="3.0.0" />
        <import addon="script.module.requests" version="2.3.0" />
    </requires>
    <extension point="xbmc.python.pluginsource" library="main.py" />
    <provides>video</provides>
    <extension point="xbmc.service" library="fxysvc.py" />
    <extension point="xbmc.addon.metadata">
        <summary lang="en">Service for FXY</summary>
        <description lang="en">FXY Service that keeps the data up to date.</description>
        <platform>all</platform>
        <license>GPL-2.0-only</license>
        <assets>
            <icon>resources/icon.png</icon>
        </assets>
    </extension>
</addon>

main.py:

Code:

import ...
# Get the plugin url in plugin:// notation.
URL = sys.argv[0]
# Get a plugin handle as an integer number.
HANDLE = int(sys.argv[1])

 def router(paramstring):
  ...works great

if __name__ == '__main__':
    # Call the router
    router(sys.argv[2][1:])

The call for the plugin comes from a panel which i managed to include as "menu point" (similar if you have "Favourites" enabled, on the left side is the menu entry "Favourites" and on the right side are the items from favourites.xml)
The item's onclick values look like that:
Code:
<onclick>$INFO[Window(10000).Property($PARAM[fxyselect].7.url)]</onclick>
which resolves to:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"

But that .xml file, that is filled with this dynamic content, actually belongs to my other addon "skin.fxy", but that shouldnt be the problem, or? (As said, both, xbmc.Player() and xbmc.executebuiltin("PlayMedia.. play the video, so i guess its a problem with the handle.

Again, thanks a lot for the help!

Try adding:

import xbmcaddon

at the top of your main.py file if it isn't there already.  The same for:  fxysvc.py . 

If that doesn't fix it then we'll need to see what is being passed to your main.py file. You can add this near the top of your main.py file:

xbmc.log('Number of arguments: ' + str(len(sys.argv)), xbmc.LOGINFO)
xbmc.log('The arguments are: ' + str(sys.argv), xbmc.LOGINFO)

Lastly, when passing a URL you could run into a parsing / encoding issue which we may need to deal with.  You can see how I handle this here in one of my addons.


Thanks,

Jeff
Thanks again for your help! I've added them, but unfortunately it doesn't help. (Also tried with adding some more... import xbmc, os, xbmcgui)
Thats the Output:
Code:
info <general>: Number of arguments: 4
info <general>: The arguments are: ['plugin://plugin.video.fxy/', '-1', '?sqlitedbid=112274705999884298', 'resume:false']

I've tried with an other call which is not an URL, just an integer (but casted to str())
It's defined as that in Python and is put so in the item's <onclick>:
Code:
sdbid = "RunPlugin(plugin://plugin.video.fxy/?sqlitedbid=" + str(complete['dbid']) +")"

Strange that is...I notice that arg[0] and arg[2] are my "RunPlugin(..." splitted, and in between there is a Handle variable expected to be "auto-generated" by Kodi as arg[1]?

Again thanks for your effort.


RE: Problem using setResolvedUrl - iceman20k - 2024-05-13

(2024-05-13, 20:28)kereltje Wrote:
Quote:Can it be a problem to also add the service extensions point in the same addon.xml, maybe the order, add the service before the main.py?
Or mixing up short syntax <extension point ... /> (for service) and normal XML syntax <extension point ... "> for main.py?
No, that should not be a problem. However, if you run into problems the usual procedure is to try to isolate the problem. So yes, for the sake of testing I would remove that, and all other code that's not absolutely necessary to play the stream.
Quote:The call for the plugin comes from a panel which i managed to include as "menu point" (similar if you have "Favourites" enabled, on the left side is the menu entry "Favourites" and on the right side are the items from favourites.xml)
The item's onclick values look like that:
Code:
<onclick>$INFO[Window(10000).Property($PARAM[fxyselect].7.url)]</onclick>
[...]
But that .xml file, that is filled with this dynamic content, actually belongs to my other addon "skin.fxy", but that shouldnt be the problem, or? (As said, both, xbmc.Player() and xbmc.executebuiltin("PlayMedia.. play the video, so i guess its a problem with the handle.
So, correct me if I'm wrong, you have skin addon that provides dynamic content and you want to call another plugin to play the content?
I don't know what exactly you are doing and for what reason, but I very much wonder if you're on the right track. A skin should in general not concern itself with content. Even more so, the whole point of a plugin is that is a very easy way to provide dynamic listings, i.e. a "menu point", and let Kodi (and the skin) deal with how it's being displayed and user interaction.

Anyway,
Quote:which resolves to:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"
Calling the plugin this way it will not play the stream (and the handle will indeed be -1).
If you want to play a stream by letting a plugin resolve the final url you'll need to call 
Code:
PlayMedia(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive)
BTW, I hope this double quote before the closing brace is a typo in your post, rather than in your code ;-)
Hi kereltje and thanks for your help. Yes, i have coded two addons: First "skin.fxy" and second "plugin.video.fxy". I read through the wiki pages (again thanks to anyone contributing to it!), especially Skinning Manual and the Add-on Dev Pages and thought thats the right way to do it. The reason i've created an "skin.fxy" is that i want a new menu entry in home.xml, or better said, an addiotional to those who are already there (Movies, TV, Favourites...). And my understanding from reading the wiki was an Addon can have its own .XML files for extra windows and so on, but i can't add a new menu point to home.xml (in detail to: <control type="fixedlist" id="9000"> in home.xml) where the menu "lives" Wink Also, of course i had to map the new entry point to a Control-Group (like <control type="group" id="15000"> is for weather i've added <control type="group" id="25000"> for my Group). Thats why i did a copy of skin.estuary, just like the wiki pages suggest, and edited the home.xml and added my own .xml files. All in all, i started coding for Kodi in March, not sure if i am on the right track too Tongue Its kinda a struggle to get in for me, but i think the system, especially that often there are many ways to realize things, is pretty cool and very flexible. Only thing bugging me is that Handle, i'll try with PlayMedia, hopefully that solves the issue. The "skin.fxy" itself does not hold any data, it just holds the "container XML Files" which are filled by the "plugin.video.fxy". There is almost no coding the skin (except some <visible> and other conditions that came in very handy)
Quote:Calling the plugin this way it will not play the stream (and the handle will indeed be -1).
Thats sounds great, i'll try that out right now, thanks a lot!
Quote:
Code:
"RunPlugin(plugin://plugin.video.fxy/?play=https://twitch.tv/userLive")"
Yes, thats a typo, but again, good eye Wink


RE: Problem using setResolvedUrl - iceman20k - 2024-05-13

Wow kereltje, that really did the trick, i was slowly losing hope Wink
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=list_item) now plays the URL without problems!

HANDLE is now "1", is that normal?

Honestly, i've read through the wiki, even more than once or twice, but i have no clue what is the difference between RunPlugin and PlayMedia, i did miss it somehow or didn't really progressed it: Is there an explanation somewhere about the differnce between these commands? I have read List_of_built-in_functions of course, but that with RunPlugin you can't "access" SetResolvedUrl or that some in-builts dont "set" a handle like RunPlugin and why i must have missed.
Thanks a lot, working perfect now with PlayMedia.


RE: Problem using setResolvedUrl - kereltje - 2024-05-14

Quote:HANDLE is now "1", is that normal?
Yeah, pretty much so. It will increase if you run it more often.
 
Quote:i have no clue what is the difference between RunPlugin and PlayMedia
Yes, It does require some perseverance to get your first add-on running. My (somewhat simplified) understanding is like this:
With PlayMedia(url) Kodi expects an url it can play and opens the player if it is. Kodi supports many access protocols, like http, local and remote file systems and also plugin://. An url like plugin://plugin.video.xyz?play=myfile is as valid an url as https://my.server.net/video.mp4. With https:// PlayMedia(...) makes an HTTP request and expects to find a web stream. With plugin:// on the other hand, PlayMedia(...) runs the specified plugin and expects it to provide a 'real' playable url by calling xbmcplugin.setResolvedUrl(...)

With RunPlugin(...) Kodi just runs the plugin with the provided url. The plugin can do whatever it has to do, like changing settings, logging in to remote servers, wiping your hard drive, but Kodi does not expect any interaction of the plugin by calls like xbmcplugin.addDirectoryItem(...) or xbmcplugin.setResolvedUrl(...). In fact, a plugin handle of -1 suggest that it's simply impossible to interact like that.
Quote:The reason i've created an "skin.fxy" is that i want a new menu entry in home.xml, or better said, an addiotional to those who are already there (Movies, TV, Favourites...)
Well, there is an entry named 'Add-ons' in the main menu from where you can open your add-on by clicking on its icon. If you insist on having a dedicated entry in the main menu, yours is probably the way to go, but I know absolutely nothing about skinning, so I can't help you there.
Quote:The "skin.fxy" itself does not hold any data, it just holds the "container XML Files" which are filled by the "plugin.video.fxy"
That sounds good. Still, you do call PlayMedia(...) somewhere. Despite my lack of skinning knowledge, I strongly feel there should be no need to do so. If your plugin provides the right info in the ListItems it produces and passes them to Kodi correctly, I would expect Kodi to be able to figure out what to do. Perhaps it's wise to first try to get your plugin working the 'normal' way; by opening it from the Add-ons menu and show its listings there, before you try to apply your custom skin.