Check size before download
Add common.php with common functions
This commit is contained in:
parent
30cd0ba548
commit
f8d59cca32
8 changed files with 455 additions and 308 deletions
62
youtube-dl
62
youtube-dl
|
|
@ -15,6 +15,7 @@ __authors__ = (
|
|||
'Kevin Ngo',
|
||||
'Ori Avtalion',
|
||||
'shizeeg',
|
||||
'Filippo Valsorda',
|
||||
)
|
||||
|
||||
__license__ = 'Public Domain'
|
||||
|
|
@ -849,27 +850,26 @@ class FileDownloader(object):
|
|||
self.trouble(u'ERROR: Cannot write metadata to JSON file ' + infofn)
|
||||
return
|
||||
|
||||
if not self.params.get('skip_download', False):
|
||||
if self.params.get('nooverwrites', False) and os.path.exists(_encodeFilename(filename)):
|
||||
success = True
|
||||
else:
|
||||
try:
|
||||
success = self._do_download(filename, info_dict)
|
||||
except (OSError, IOError), err:
|
||||
raise UnavailableVideoError
|
||||
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
||||
self.trouble(u'ERROR: unable to download video data: %s' % str(err))
|
||||
return
|
||||
except (ContentTooShortError, ), err:
|
||||
self.trouble(u'ERROR: content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))
|
||||
return
|
||||
|
||||
if success:
|
||||
try:
|
||||
self.post_process(filename, info_dict)
|
||||
except (PostProcessingError), err:
|
||||
self.trouble(u'ERROR: postprocessing: %s' % str(err))
|
||||
return
|
||||
if self.params.get('nooverwrites', False) and os.path.exists(_encodeFilename(filename)):
|
||||
success = True
|
||||
else:
|
||||
try:
|
||||
success = self._do_download(filename, info_dict)
|
||||
except (OSError, IOError), err:
|
||||
raise UnavailableVideoError
|
||||
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
||||
self.trouble(u'ERROR: unable to download video data: %s' % str(err))
|
||||
return
|
||||
except (ContentTooShortError, ), err:
|
||||
self.trouble(u'ERROR: content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))
|
||||
return
|
||||
|
||||
if success:
|
||||
try:
|
||||
self.post_process(filename, info_dict)
|
||||
except (PostProcessingError), err:
|
||||
self.trouble(u'ERROR: postprocessing: %s' % str(err))
|
||||
return
|
||||
|
||||
def download(self, url_list):
|
||||
"""Download a given list of URLs."""
|
||||
|
|
@ -1038,6 +1038,9 @@ class FileDownloader(object):
|
|||
return False
|
||||
|
||||
data_len = data.info().get('Content-length', None)
|
||||
self.to_screen(u'[info] File size: ' + self.format_bytes(data_len) + ' bytes')
|
||||
if self.params.get('skip_download', False):
|
||||
return True;
|
||||
if data_len is not None:
|
||||
data_len = long(data_len) + resume_len
|
||||
data_len_str = self.format_bytes(data_len)
|
||||
|
|
@ -1177,8 +1180,8 @@ class YoutubeIE(InfoExtractor):
|
|||
_AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
|
||||
_NETRC_MACHINE = 'youtube'
|
||||
# Listed in order of quality
|
||||
_available_formats = ['38', '37', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13']
|
||||
_available_formats_prefer_free = ['38', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '17', '13']
|
||||
_available_formats = ['38', '37', '46', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13']
|
||||
_available_formats_prefer_free = ['38', '46', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '17', '13']
|
||||
_video_extensions = {
|
||||
'13': '3gp',
|
||||
'17': 'mp4',
|
||||
|
|
@ -1189,6 +1192,7 @@ class YoutubeIE(InfoExtractor):
|
|||
'43': 'webm',
|
||||
'44': 'webm',
|
||||
'45': 'webm',
|
||||
'46': 'webm',
|
||||
}
|
||||
_video_dimensions = {
|
||||
'5': '240x400',
|
||||
|
|
@ -1204,6 +1208,7 @@ class YoutubeIE(InfoExtractor):
|
|||
'43': '360x640',
|
||||
'44': '480x854',
|
||||
'45': '720x1280',
|
||||
'46': '1080x1920',
|
||||
}
|
||||
IE_NAME = u'youtube'
|
||||
|
||||
|
|
@ -3093,14 +3098,14 @@ class BlipTVIE(InfoExtractor):
|
|||
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']
|
||||
umobj = re.match(self._URL_EXT, video_url)
|
||||
if umobj is None:
|
||||
raise ValueError('Can not determine filename extension')
|
||||
ext = umobj.group(1)
|
||||
|
||||
|
||||
info = {
|
||||
'id': data['item_id'],
|
||||
'url': video_url,
|
||||
|
|
@ -3201,7 +3206,7 @@ class ComedyCentralIE(InfoExtractor):
|
|||
|
||||
def report_extraction(self, episode_id):
|
||||
self._downloader.to_screen(u'[comedycentral] %s: Extracting information' % episode_id)
|
||||
|
||||
|
||||
def report_config_download(self, episode_id):
|
||||
self._downloader.to_screen(u'[comedycentral] %s: Downloading configuration' % episode_id)
|
||||
|
||||
|
|
@ -3763,7 +3768,6 @@ class MixcloudIE(InfoExtractor):
|
|||
url_list = jsonData[fmt][bitrate]
|
||||
except TypeError: # we have no bitrate info.
|
||||
url_list = jsonData[fmt]
|
||||
|
||||
return url_list
|
||||
|
||||
def check_urls(self, url_list):
|
||||
|
|
@ -3883,7 +3887,7 @@ class StanfordOpenClassroomIE(InfoExtractor):
|
|||
info = {
|
||||
'id': _simplify_title(course + '_' + video),
|
||||
}
|
||||
|
||||
|
||||
self.report_extraction(info['id'])
|
||||
baseUrl = 'http://openclassroom.stanford.edu/MainFolder/courses/' + course + '/videos/'
|
||||
xmlUrl = baseUrl + video + '.xml'
|
||||
|
|
@ -4688,7 +4692,7 @@ def _real_main():
|
|||
parser.error(u'you must provide at least one URL')
|
||||
else:
|
||||
sys.exit()
|
||||
|
||||
|
||||
try:
|
||||
retcode = fd.download(all_urls)
|
||||
except MaxDownloadsReached:
|
||||
|
|
|
|||
Reference in a new issue