]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/YoutubeDL.py
Option '--load-info': if the download fails, try extracting the info with the 'webpag...
[youtube-dl] / youtube_dl / YoutubeDL.py
index b7393fd7983327c0df3d95f931d843967ca0a57e..77339dddfd591f2a02bdba3e91414142ec9c1d7c 100644 (file)
@@ -812,6 +812,21 @@ class YoutubeDL(object):
 
         return self._download_retcode
 
+    def download_with_info_file(self, info_filename):
+        with open(info_filename, 'r') as f:
+            # TODO: Check for errors
+            info = json.load(f)
+        try:
+            self.process_ie_result(info, download=True)
+        except DownloadError:
+            webpage_url = info.get('webpage_url')
+            if webpage_url is not None:
+                self.report_warning(u'The info failed to download, trying with "%s"' % webpage_url)
+                return self.download([webpage_url])
+            else:
+                raise
+        return self._download_retcode
+
     def post_process(self, filename, ie_info):
         """Run all the postprocessors on the given file."""
         info = dict(ie_info)
@@ -971,7 +986,9 @@ class YoutubeDL(object):
         write_string(u'[debug] Proxy map: ' + compat_str(proxy_map) + u'\n')
 
     def _setup_opener(self):
-        timeout = float(self.params.get('socket_timeout', 600))
+        timeout_val = self.params.get('socket_timeout')
+        timeout = 600 if timeout_val is None else float(timeout_val)
+
         opts_cookiefile = self.params.get('cookiefile')
         opts_proxy = self.params.get('proxy')