Get URLResolver to resolve link only when ListItem clicked?
#1
Hello all,

I have been using the following code below to play a few video links via URLResolver. The code works and when the listItem is clicked the video link is played.

One thing I noticed though is when I added links which require pairing, such as "thevideo.me", or "openload". When I click the folder that contains listitems, the pairing notice is displayed before I have even clicked the listitem to play.

My code is below:

Code:
def fg():
   video10 = media_url = urlresolver.resolve('http://www.dailymotion.com/video/x2uhtzd_it-s-peanut-butter-jelly-time-10-minutes-family-guy-brian-griffin_shortfilms')
   addDir('', '', video10, 'Peanut Butter Jelly Time', icon5, icon5)
   video11 = media_url = urlresolver.resolve('https://cloud.mail.ru/public/Fpoi/uNmXT**xB')
   addDir('', '', video11, 'Surfin Bird', icon5, icon5)

By looking at my code I think the issue is that the video link is being resolved before the (addDir) listitem code is called. So the code is doing what it is meant to.

What I was wondering is, is it possible to have the link resolve only when the listitem is clicked? As I believe using this method if I add a few extra links that require pairing the user is going to be shown many pairing dialog windows before they even get to see listitems.

I had a look at the URL Resolver documentation and I seen this code:

Code:
sources = [HostedMediaFile(url='http://youtu.be/VIDEOID', title='Youtube [verified] (20 views)'),
           HostedMediaFile(url='http://putlocker.com/file/VIDEOID', title='Putlocker (3 views)')]
        source = urlresolver.choose_source(sources)
        if source:
                stream_url = source.resolve()
                addon.resolve_url(stream_url)
        else:
                addon.resolve_url(False)

I tried this code but I got a "global HostedMediaFile not defined"? Is there anything else I need to add to the import section of my addon to get HostedMediaFile to be defined?


I really appreciate if anyone has any ideas on how I could implement this method, or point me in the right direction.

Many Thanks
Reply
#2
it possible to have the link resolve when the listitem is clicked.

this is a very rough sketch of the steps.
The answer is not in the URLResolver docs. It is on kodi addon structure. (this is very common, almost all addons do this)

what you do is point the link to your plugin instead of the url of the playable media:
Code:
video10 = 'plugin://plugin.video.yourplugin/?mode=play&url_to_resolve='+urllib.quote_plus(url)
delve into that addDir() code and read more about xbmcplugin.addDirectoryItem and how listitem(s) are used to populate them.

Then your addon has to handle parsing the "mode=Play" and 'url_to_resolve=xxx" (or whatever you want to call it) that calls a function that will resolve and play the link in one go.

Code:
def playURLRVideo(url_to_resolve):        
    media_url = urlresolver.resolve(url_to_resolve)
    if media_url:
        listitem = xbmcgui.ListItem(path=media_url)  
        xbmcplugin.setResolvedUrl(pluginhandle, True, listitem)
Reply

Logout Mark Read Team Forum Stats Members Help
Get URLResolver to resolve link only when ListItem clicked?0