X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2FFileDownloader.py;h=b43acd19b42a1b7ad8b4c8329657864b35b365b3;hb=95eb771dcda47f948b050da85c7ff22539e3ee12;hp=a135be3525d2cc699e9a8ae4b9447e96a3ee762d;hpb=9e8056d5a7b6b366874088cd30d23ba4a52d3861;p=youtube-dl diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index a135be352..b43acd19b 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -10,6 +10,7 @@ import socket import subprocess import sys import time +import traceback if os.name == 'nt': import ctypes @@ -78,6 +79,7 @@ class FileDownloader(object): writeinfojson: Write the video description to a .info.json file writesubtitles: Write the video subtitles to a .srt file subtitleslang: Language of the subtitles to download + test: Download only first bytes to test the downloader. """ params = None @@ -216,6 +218,8 @@ class FileDownloader(object): """ if message is not None: self.to_stderr(message) + if self.params.get('verbose'): + self.to_stderr(u''.join(traceback.format_list(traceback.extract_stack()))) if not self.params.get('ignoreerrors', False): raise DownloadError(message) self._download_retcode = 1 @@ -334,8 +338,11 @@ class FileDownloader(object): template_dict['epoch'] = int(time.time()) template_dict['autonumber'] = u'%05d' % self._num_downloads - template_dict = dict((key, u'NA' if val is None else val) for key, val in template_dict.items()) - template_dict = dict((k, sanitize_filename(compat_str(v), self.params.get('restrictfilenames'))) for k,v in template_dict.items()) + sanitize = lambda k,v: sanitize_filename( + u'NA' if v is None else compat_str(v), + restricted=self.params.get('restrictfilenames'), + is_id=(k==u'id')) + template_dict = dict((k, sanitize(k, v)) for k,v in template_dict.items()) filename = self.params['outtmpl'] % template_dict return filename @@ -463,7 +470,7 @@ class FileDownloader(object): try: success = self._do_download(filename, info_dict) except (OSError, IOError) as err: - raise UnavailableVideoError + raise UnavailableVideoError() except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: self.trouble(u'ERROR: unable to download video data: %s' % str(err)) return @@ -591,6 +598,9 @@ class FileDownloader(object): basic_request = compat_urllib_request.Request(url, None, headers) request = compat_urllib_request.Request(url, None, headers) + if self.params.get('test', False): + request.add_header('Range','bytes=0-10240') + # Establish possible resume length if os.path.isfile(encodeFilename(tmpfilename)): resume_len = os.path.getsize(encodeFilename(tmpfilename))