from __future__ import absolute_import, unicode_literals
import collections
+import datetime
import errno
import io
import json
if template_dict.get('width') and template_dict.get('height'):
template_dict['resolution'] = '%dx%d' % (template_dict['width'], template_dict['height'])
elif template_dict.get('height'):
- res = '%sp' % template_dict['height']
+ template_dict['resolution'] = '%sp' % template_dict['height']
elif template_dict.get('width'):
- res = '?x%d' % template_dict['width']
+ template_dict['resolution'] = '?x%d' % template_dict['width']
sanitize = lambda k, v: sanitize_filename(
compat_str(v),
if 'display_id' not in info_dict and 'id' in info_dict:
info_dict['display_id'] = info_dict['id']
+ if info_dict.get('upload_date') is None and info_dict.get('timestamp') is not None:
+ upload_date = datetime.datetime.utcfromtimestamp(
+ info_dict['timestamp'])
+ info_dict['upload_date'] = upload_date.strftime('%Y%m%d')
+
# This extractors handle format selection themselves
if info_dict['extractor'] in ['Youku']:
if download:
else:
formats = info_dict['formats']
+ if not formats:
+ raise ExtractorError('No video formats found!')
+
# We check that all the formats have the format and format_id fields
- for (i, format) in enumerate(formats):
+ for i, format in enumerate(formats):
if format.get('format_id') is None:
format['format_id'] = compat_str(i)
if format.get('format') is None:
def urlopen(self, req):
""" Start an HTTP download """
- return self._opener.open(req)
+ return self._opener.open(req, timeout=self._socket_timeout)
def print_debug_header(self):
if not self.params.get('verbose'):
def _setup_opener(self):
timeout_val = self.params.get('socket_timeout')
- timeout = 600 if timeout_val is None else float(timeout_val)
+ self._socket_timeout = 600 if timeout_val is None else float(timeout_val)
opts_cookiefile = self.params.get('cookiefile')
opts_proxy = self.params.get('proxy')
# (See https://github.com/rg3/youtube-dl/issues/1309 for details)
opener.addheaders = []
self._opener = opener
-
- # TODO remove this global modification
- compat_urllib_request.install_opener(opener)
- socket.setdefaulttimeout(timeout)