diff options
author | Ricardo Garcia <sarbalap+freshmeat@gmail.com> | 2010-07-24 09:47:01 +0200 |
---|---|---|
committer | Ricardo Garcia <sarbalap+freshmeat@gmail.com> | 2010-10-31 11:28:32 +0100 |
commit | 2e3a32e4acd55d79845464432f49227d6a3b3ade (patch) | |
tree | c5fc23941cd6e37106256d0c37012c82d4c2bd42 | |
parent | 8190e3631ba5f1734e5b45a7e0a0e5999ab70d26 (diff) |
Restore proper support for webm formats (fixes issue #166)
-rwxr-xr-x | youtube-dl | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/youtube-dl b/youtube-dl index 5fd331e79..00d9696d6 100755 --- a/youtube-dl +++ b/youtube-dl @@ -879,7 +879,36 @@ class YoutubeIE(InfoExtractor): video_description = mobj.group(1) # Decide which formats to download - if 'fmt_url_map' in video_info: + 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: url_map = dict(tuple(pair.split('|')) for pair in video_info['fmt_url_map'][0].split(',')) format_limit = self._downloader.params.get('format_limit', None) if format_limit is not None and format_limit in self._available_formats: @@ -890,7 +919,6 @@ class YoutubeIE(InfoExtractor): if len(existing_formats) == 0: self._downloader.trouble(u'ERROR: no known formats available for video') return - requested_format = self._downloader.params.get('format', None) if requested_format is None: video_url_list = [(existing_formats[0], url_map[existing_formats[0]])] # Best quality elif requested_format == '-1': @@ -900,9 +928,11 @@ class YoutubeIE(InfoExtractor): self._downloader.trouble(u'ERROR: format not available for video') return video_url_list = [(requested_format, url_map[requested_format])] # Specific format + elif 'conn' in video_info and video_info['conn'][0].startswith('rtmp'): self.report_rtmp_download() video_url_list = [(None, video_info['conn'][0])] + else: self._downloader.trouble(u'ERROR: no fmt_url_map or conn information found in video info') return |