Skip to content

Instantly share code, notes, and snippets.

@vikki
Created July 30, 2012 13:21
Show Gist options
  • Save vikki/3206868 to your computer and use it in GitHub Desktop.
Save vikki/3206868 to your computer and use it in GitHub Desktop.
YouTube HTML5 Video Proxy
ytVideoUrlMatcher = r'url_encoded_fmt_stream_map=url=([^&]*)&'
ytVideoInfoUrlBase = 'http://www.youtube.com/get_video_info?html5=1&video_id='
def getHTML5VideoFileFromYouTube(videoId):
videoInfoUrl = ytVideoInfoUrlBase + videoId
videoInfoFile = urllib2.urlopen(videoInfoUrl)
videoInfo = urllib2.unquote(videoInfoFile.read())
vidMatch = re.search(ytVideoUrlMatcher, videoInfo)
videoUrl = vidMatch.groups(0)[0]
videoUrl = urllib2.unquote(videoUrl)
return urllib2.urlopen(vidUrl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment