python: how to get youtube video to play in xbmc
#1
hi i am trying to develop this add-on.

but i am getting this error
Code:
17:49:46 T:2910841712 M:1695137792  NOTICE:
                                             s1.replace = "http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.1686BD967FB693511E3DC806B725B9F73AF0F86B"
17:49:46 T:2910841712 M:1695137792 WARNING: CreateLoader - Unsupported protocol("http) in "http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.tbn
17:49:46 T:2910841712 M:1695137792 WARNING: CreateLoader - Unsupported protocol("http) in "http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/movie.tbn
17:49:46 T:3061753744 M:1694502912  NOTICE: DVDPlayer: Opening: "http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.1686BD967FB693511E3DC806B725B9F73AF0F86B"
17:49:46 T:3061753744 M:1694502912 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
17:49:46 T:2900351856 M:1694248960  NOTICE: Creating InputStream
17:49:46 T:2900351856 M:1694248960 WARNING: CreateLoader - Unsupported protocol("http) in "http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.1686BD967FB693511E3DC806B725B9F73AF0F86B"
17:49:46 T:2900351856 M:1694248960   ERROR: CDVDPlayer::OpenInputStream - error opening ["http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.1686BD967FB693511E3DC806B725B9F73AF0F86B"]
17:49:46 T:2900351856 M:1694248960  NOTICE: CDVDPlayer::OnExit()
17:49:46 T:2900351856 M:1694248960  NOTICE: CDVDPlayer::OnExit() deleting input stream
17:49:46 T:3061753744 M:1694248960   ERROR: Playlist Player: skipping unplayable item: 0, path ["http://o-o---preferred---sn-jvhj5nu-ab5l---v2---lscache2.c.youtube.com/videoplayback?upn=ukdc318LNtI&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=920921%2C909920%2C902517%2C922401%2C920704%2C912806%2C927201%2C925003%2C913546%2C913556%2C920201%2C900816%2C911112%2C901451&ms=au&expire=1351829721&itag=43&ipbits=8&gcr=us&sver=3&ratebypass=yes&mt=1351806552&ip=68.81.77.196&mv=m&source=youtube&key=yt1&cp=U0hURlhNV19HS0NONF9QR0FIOlJ5XzNYTkhBVW9W&id=bfabea59ab081dac&signature=5321987EA36D6C91145B02AF256015C274033EEA.1686BD967FB693511E3DC806B725B9F73AF0F86B"]
17:49:46 T:3061753744 M:1694248960  NOTICE: CDVDPlayer::CloseFile()
17:49:46 T:3061753744 M:1694248960 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
17:49:46 T:3061753744 M:1694248960  NOTICE: DVDPlayer: waiting for threads to exit
17:49:46 T:3061753744 M:1694248960  NOTICE: DVDPlayer: finished waiting
however the url plays fine on my fedora machine via mplayer on the command-line.
this is the function that i am having problems with:
Code:
def playvid(url):#  cause mode is empty in this one it will go back to first directory
        print "\n playvid(): url = " + url
        html = urllib2.urlopen(url).read()
        for v in re.finditer('youtube.com/v/(.+?)?autoplay=1', html):
          title = v.groups()
          if title:
            s2 = str(tuple(title))
            s2 = s2.replace("('","\"")
            s2 = s2.replace("',)","\"")
            s2 = s2.replace("?","")
            s2 = s2.replace('"','')
            print "\n  s2 = " + s2

        html = urllib2.urlopen('http://www.youtube.com/watch?v=' + s2).read()
        for v2 in re.finditer('url_encoded_fmt_stream_map.+?url=(http.+?)u0026quality', html):
          vid = v2.groups()
          if vid:
            s1 = str(tuple(vid))
            print "\n ----- s1 = " + s1
            s1 = s1.replace("%3A",":")
            s1 = s1.replace("%2F","/")
            s1 = s1.replace("%3F","?")
            s1 = s1.replace("%3D","=")
            s1 = s1.replace("%252C","%2C")
            s1 = s1.replace("%26","&")
            s1 = s1.replace("%253A",":")
            s1 = s1.replace("('","\"")
            s1 = s1.replace("',)","\"")
            s1 = re.sub("\\\\\\\u0026type.+?sig", "&signature", s1)
            s1 = s1.replace("\\\\","")
            print "\n s1.replace = " + s1
        xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(s1)
Reply
#2
the quotes were messing with the url so i added
Code:
s1 = s1.replace('"','')
above the last line.

thanks,
Reply
#3
You don't need to extract the playback parameters yourself - just require the youtube plugin in your addon.xml and send youtube-plugin's filled plugin url to xbmc.

Code:
video_id = 'youtube_video_id'
playback_url = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % video_id
xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(playback_url)

or better use setResolvedUrl instead calling the player explicit:
Code:
video_id = 'youtube_video_id'
playback_url = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % video_id
item = xbmcgui.ListItem(path=playback_url)
xbmcplugin.setResolvedUrl(plugin_handle, True, item)
My GitHub. My Add-ons:
Image
Reply
#4
thanks for the advice sphere. i wish i thought of that before cranking out all this code. oh well, this academic earth addon is complete although it is kinda' buggy so i am open to suggestions. the source is located here:
http://hyper.homeftp.net/xbmc/
Reply
#5
And regarding academic earth, there is already a good one in the official repo: http://wiki.xbmc.org/index.php?title=Add...emic_Earth *g*
My GitHub. My Add-ons:
Image
Reply
#6
yes thanx, this was more of a learning experience.
Reply

Logout Mark Read Team Forum Stats Members Help
python: how to get youtube video to play in xbmc0