+ requested_format = self._downloader.params.get('format', None)
+
+ if requested_format in ["43", "45"]: # webm formats
+ # Join the HTML5 beta
+ html5form = { "enable_html5": "true" }
+ request = urllib2.Request('http://www.youtube.com/html5', urllib.urlencode(html5form), std_headers)
+ try:
+ self._downloader.to_stdout(u'[youtube] Joining the HTML5 Beta')
+ urllib2.urlopen(request).read()
+ except (urllib2.URLError, httplib.HTTPException, socket.error), err:
+ self._downloader.trouble(u'ERROR: unable to join the HTML5 Beta: %s' % str(err))
+ return
+
+ # Request the video webpage with webm enabled
+ request = urllib2.Request('http://www.youtube.com/watch?v=%s&webm=1' % video_id, None, std_headers)
+ try:
+ self._downloader.to_stdout(u'[youtube] Requesting HTML5 video webpage')
+ video_webpage = urllib2.urlopen(request).read()
+ except (urllib2.URLError, httplib.HTTPException, socket.error), err:
+ self._downloader.trouble(u'ERROR: unable to get the HTML5 video webpage: %s' % str(err))
+ return
+
+ # Find the URL for the requested format
+ mobj = re.search(ur'setAvailableFormat\("(.*?)".*?"%s"\);' % requested_format, video_webpage)
+ if mobj is None:
+ self._downloader.trouble(u'ERROR: format not available for video')
+ return
+ video_url_list = [(requested_format, mobj.group(1))]
+
+ elif 'fmt_url_map' in video_info: