Playing a Playlist of setResolvedUrl Entries
#1
I've been using a video plugin for a while that makes use of the setResolvedUrl functionality to deal with a time-limited URL token. In this case, one video consists of multiple clips, where each clip uses setResolvedUrl. Rather than forcing the user to click on each clip to play it, I construct and populate a playlist (in script), where each entry would use the setResolvedUrl functionality. I then proceed to play that playlist automatically from my script. Here's a snippet:

Code:
        # enumerate thru the item list and gather info
        i = 1
        for item in items:
            clipItem = self.ParseClipItem(item)
            #clipURL = self.ClipItemToFinalClipURL(clipItem['ClipId'])
            
            
            linkDesc = CTVEnumerator.SelfLinkDesc(self)
            linkDesc.Name = self.unescape(clipItem['Title'])
            linkDesc.ClipId = clipItem['ClipId']
            linkDesc.Mode = 'PlayClip'
            linkDesc.IconImage = self.unescape(clipItem['Thumbnail'])
            linkDesc.Plot = self.unescape(clipItem['Description'])
            linkDesc.nOrder = i
            
            #episodeStrmFile.write(linkDesc.ToURLString() + "\n")
            #print linkDesc.ToURLString()
            liz = self.addCTVRedirectorLink(linkDesc)
            objPL.add(url=linkDesc.ToURLString(),listitem=liz)
            i=i+1
        
        #episodeStrmFile.close()
        ##liz=xbmcgui.ListItem("Full Episode", iconImage="DefaultVideo.png", path=episodeStrmFileName)
        ##liz.setProperty("IsPlayable", "true")
        ##xbmc.Player().play(item=episodeStrmFileName,listitem=liz)
        xbmc.executebuiltin('playlist.playoffset(video,0)')
        #print ("Episode stream file: %s"%episodeStrmFileName)

The problem I have is that attempting to play a playlist (containing python plugin entries) means that a python script is calling xbmc which is then calling that same python script. This causes problems for the python interpreter which has a mutex to keep it from re-entering itself in this manner. Because I settled on using the xbmc.executebuiltin('playlist.playoffset(video,0)') function, it will sometimes work, sometimes not, depending on how quickly the playlist starts playing and how quickly my plugin shuts down.

I'm hoping a dev has a suggestion for a way to make this work. As you can see from the many commented out lines of code above, I tried to create a STRM file and play that, but it wasn't successful.
Reply
#2
I know this is a super-old thread, but for the sake of people searching for solutions for this question, I'm posting code for my script. It acts as both a script, with a full custom gui when invoked from XBMC by the user. It also acts as a plugin, launching another instance of the script that only runs small portion of code that gets a dynamically generated, time limited playback URL for the player and then exits. So far it has worked out great. I struggled for many hours to understand that this was even possible, and then how to properly implement it.

Calling the script as a plugin to get the url can be done inside the main gui of the script, or from XBMC, because it is called by making the content URL of the list item point to the script with a few extra arguments. It is called like this:
Code:
plugin://script.audio.rhapsody/?track=ABC&token=XYZ

The key to making this work is just an if/else block that checks whether extra arguments exist when the script is invoked. In the code below, the 'if' is the part that launches the full gui for the script. The 'else' is the isolated function that resolves the URL for the player.

Code:
if len(sys.argv) < 2:
    skincheck.skinfix()

    app = main.Application()

    loadwin = xbmcgui.WindowXML("loading.xml", app.__addon_path__, 'Default', '720p')
    loadwin.show()
    print "Do we have network?"  #+str(app.api.get_new_releases())
    if app.api.get_artist_genre("Art.954"):
        loadwin.getControl(10).setLabel('Installing fonts...')
        app.init_fonts()
        loadwin.getControl(10).setLabel('Getting things ready...')
        app.cache.load_cached_data()
        time.sleep(1)
    else:
        loadwin.getControl(10).setLabel('Can\'t reach Rhapsody servers. \nMust be online to use Rhapsody.\nExiting...')
        time.sleep(2)
        app.set_var('running', False)


    while app.get_var('running'):
        if not app.get_var('logged_in'):
            if not app.mem.has_saved_creds():
                logwin = view.LoginWin("login.xml", app.__addon_path__, 'Default', '720p', app=app)
                logwin.doModal()
                loadwin.getControl(10).setLabel('Logging you in...')
                del logwin
                time.sleep(1)
            else:
                loadwin.getControl(10).setLabel('Logging you in...')
                app.set_var('logged_in', True)
                time.sleep(1)
            app.api.token = app.mem.access_token
            #app.player.get_session()
            #app.player.validate_session(app.player.session)
        app.win.doModal()
        if app.get_var('logged_in') == False:
            loadwin.getControl(10).setLabel('Logging you out...')
        else:
            loadwin.getControl(10).setLabel('Finishing up...')
        app.cache.save_album_data()
        app.cache.save_artist_data()
    del app.win
    time.sleep(1)
    loadwin.close()
    del loadwin
    del app
    print "Rhapsody addon has exited"
else:
    print "script is being called as a plugin to resolve a playable URL"
    plugin.get_it(sys.argv)

-Jerimiah
Reply

Logout Mark Read Team Forum Stats Members Help
Playing a Playlist of setResolvedUrl Entries0