aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2009-05-24 11:07:51 +0200
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2010-10-31 11:24:32 +0100
commitcbfff4db630fef66847d326cdd70b9a6002c0d5b (patch)
tree95fc925f228f18b46763bf6b22f57385e7e0563b
parent781daeabdb6ffa2b63bf8f7dec715ac8835c558b (diff)
downloadyoutube-dl-cbfff4db630fef66847d326cdd70b9a6002c0d5b.tar.xz
Verify URLs in simulate mode (fixes issue #22)
-rwxr-xr-xyoutube-dl26
1 files changed, 20 insertions, 6 deletions
diff --git a/youtube-dl b/youtube-dl
index f6e472445..0aae90505 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -200,6 +200,14 @@ class FileDownloader(object):
multiplier = 1024.0 ** 'bkmgtpezy'.index(matchobj.group(2).lower())
return long(round(number * multiplier))
+ @staticmethod
+ def verify_url(url):
+ """Verify a URL is valid and data could be downloaded."""
+ request = urllib2.Request(url, None, std_headers)
+ data = urllib2.urlopen(request)
+ data.read(1)
+ data.close()
+
def add_info_extractor(self, ie):
"""Add an InfoExtractor object to the end of the list."""
self._ies.append(ie)
@@ -265,15 +273,21 @@ class FileDownloader(object):
def process_info(self, info_dict):
"""Process a single dictionary returned by an InfoExtractor."""
- # Forced printings
- if self.params.get('forcetitle', False):
- print info_dict['title'].encode(locale.getpreferredencoding())
- if self.params.get('forceurl', False):
- print info_dict['url'].encode(locale.getpreferredencoding())
-
# Do nothing else if in simulate mode
if self.params.get('simulate', False):
+ try:
+ self.verify_url(info_dict['url'])
+ except (OSError, IOError, urllib2.URLError, httplib.HTTPException, socket.error), err:
+ raise UnavailableFormatError
+
+ # Forced printings
+ if self.params.get('forcetitle', False):
+ print info_dict['title'].encode(locale.getpreferredencoding())
+ if self.params.get('forceurl', False):
+ print info_dict['url'].encode(locale.getpreferredencoding())
+
return
+
try:
template_dict = dict(info_dict)