]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/YoutubeDL.py
YoutubeDL: rename `_fd_progress_hooks` back to `_progress_hooks`
[youtube-dl] / youtube_dl / YoutubeDL.py
index e705c410b6451c983cfc43928af584025581dfa3..ac4627c4e684ce25b1b319934b5eeae5ae3805a9 100644 (file)
@@ -53,7 +53,7 @@ from .utils import (
     YoutubeDLHandler,
 )
 from .extractor import get_info_extractor, gen_extractors
-from .FileDownloader import FileDownloader
+from .downloader import get_suitable_downloader
 from .version import __version__
 
 
@@ -211,8 +211,6 @@ class YoutubeDL(object):
                 u'Set the LC_ALL environment variable to fix this.')
             self.params['restrictfilenames'] = True
 
-        self.fd = FileDownloader(self, self.params)
-
         if '%(stitle)s' in self.params.get('outtmpl', ''):
             self.report_warning(u'%(stitle)s is deprecated. Use the %(title)s and the --restrict-filenames flag(which also secures %(uploader)s et al) instead.')
 
@@ -248,6 +246,10 @@ class YoutubeDL(object):
         self._pps.append(pp)
         pp.set_downloader(self)
 
+    def add_progress_hook(self, ph):
+        """Add the progress hook (currently only for the file downloader)"""
+        self._progress_hooks.append(ph)
+
     def _bidi_workaround(self, message):
         if not hasattr(self, '_output_channel'):
             return message
@@ -686,7 +688,12 @@ class YoutubeDL(object):
                         ext_ord)
             formats = sorted(formats, key=_free_formats_key)
 
-        info_dict['formats'] = formats
+        if formats[0] is not info_dict: 
+            # only set the 'formats' fields if the original info_dict list them
+            # otherwise we end up with a circular reference, the first (and unique)
+            # element in the 'formats' field in info_dict is info_dict itself, 
+            # wich can't be exported to json
+            info_dict['formats'] = formats
         if self.params.get('listformats', None):
             self.list_formats(info_dict)
             return
@@ -880,7 +887,10 @@ class YoutubeDL(object):
                 success = True
             else:
                 try:
-                    success = self.fd._do_download(filename, info_dict)
+                    fd = get_suitable_downloader(info_dict)(self, self.params)
+                    for ph in self._progress_hooks:
+                        fd.add_progress_hook(ph)
+                    success = fd.download(filename, info_dict)
                 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
                     self.report_error(u'unable to download video data: %s' % str(err))
                     return