youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

commit 2e3a32e4acd55d79845464432f49227d6a3b3ade
parent 8190e3631ba5f1734e5b45a7e0a0e5999ab70d26
Author: Ricardo Garcia <sarbalap+freshmeat@gmail.com>
Date:   Sat, 24 Jul 2010 09:47:01 +0200

Restore proper support for webm formats (fixes issue #166)

Diffstat:
Myoutube-dl | 34++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)

diff --git 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