X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=youtube-dl;h=81dd4b83bfcca01d5c502856db47a015ae487530;hb=1293ce58acc898cf8b423c93b45f227c26ee9f96;hp=27ae816e0cd3fc57c7c874da9109a36b7b7c5936;hpb=c31b124d7a2c754f3ca5c6f8de8c501cfbad895a;p=youtube-dl diff --git a/youtube-dl b/youtube-dl index 27ae816e0..81dd4b83b 100755 --- a/youtube-dl +++ b/youtube-dl @@ -9,12 +9,8 @@ # Author: Gergely Imreh # Author: Philipp Hagemeister # License: Public domain code -from __future__ import with_statement -import contextlib import cookielib -import ctypes import datetime -import email.utils import gzip import htmlentitydefs import httplib @@ -34,6 +30,13 @@ import urllib2 import warnings import zlib +if os.name == 'nt': + import ctypes + +try: + import email.utils +except ImportError: # Python 2.4 + import email.Utils try: import cStringIO as StringIO except ImportError: @@ -707,8 +710,11 @@ class FileDownloader(object): try: descfn = filename + '.description' self.report_writedescription(descfn) - with contextlib.closing(open(descfn, 'wb')) as descfile: + descfile = open(descfn, 'wb') + try: descfile.write(info_dict['description'].encode('utf-8')) + finally: + descfile.close() except (OSError, IOError): self.trouble(u'ERROR: Cannot write description file: %s' % str(descfn)) return @@ -722,8 +728,11 @@ class FileDownloader(object): self.trouble(u'ERROR: No JSON encoder found. Update to Python 2.6+, setup a json module, or leave out --write-info-json.') return try: - with contextlib.closing(open(infofn, 'wb')) as infof: + infof = open(infofn, 'wb') + try: json.dump(info_dict, infof) + finally: + infof.close() except (OSError, IOError): self.trouble(u'ERROR: Cannot write metadata to JSON file: %s' % str(infofn)) return @@ -1248,14 +1257,15 @@ class YoutubeIE(InfoExtractor): # Decide which formats to download req_format = self._downloader.params.get('format', None) - raw_map = None - if 'fmt_url_map' in video_info and len(video_info['fmt_url_map']) >= 1: - raw_map = video_info['fmt_url_map'][0] - elif 'fmt_stream_map' in video_info and len(video_info['fmt_stream_map']) >= 1: - raw_map = video_info['fmt_stream_map'][0] - - if raw_map is not None: - url_map = dict(tuple(pair.split('|')[:2]) for pair in raw_map.split(',')) + if 'conn' in video_info and video_info['conn'][0].startswith('rtmp'): + self.report_rtmp_download() + video_url_list = [(None, video_info['conn'][0])] + elif 'url_encoded_fmt_stream_map' in video_info and len(video_info['url_encoded_fmt_stream_map']) >= 1: + url_data_strs = video_info['url_encoded_fmt_stream_map'][0].split(',') + url_data = [dict(pairStr.split('=') for pairStr in uds.split('&')) for uds in url_data_strs] + url_data = filter(lambda ud: 'itag' in ud and 'url' in ud, url_data) + url_map = dict((ud['itag'], urllib.unquote(ud['url'])) for ud in url_data) + format_limit = self._downloader.params.get('format_limit', None) if format_limit is not None and format_limit in self._available_formats: format_list = self._available_formats[self._available_formats.index(format_limit):] @@ -1275,11 +1285,6 @@ class YoutubeIE(InfoExtractor): self._downloader.trouble(u'ERROR: requested format not available') return video_url_list = [(req_format, url_map[req_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 @@ -2760,7 +2765,11 @@ class BlipTVIE(InfoExtractor): self._downloader.trouble(u'ERROR: invalid URL: %s' % url) return - json_url = url + ('&' if '?' in url else '?') + 'skin=json&version=2&no_wrap=1' + if '?' in url: + cchar = '&' + else: + cchar = '?' + json_url = url + cchar + 'skin=json&version=2&no_wrap=1' request = urllib2.Request(json_url) self.report_extraction(mobj.group(1)) try: @@ -2770,7 +2779,10 @@ class BlipTVIE(InfoExtractor): return try: json_data = json.loads(json_code) - data = json_data['Post'] if 'Post' in json_data else json_data + if 'Post' in json_data: + data = json_data['Post'] + else: + data = json_data upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d') video_url = data['media']['url']