浏览代码

[YoutubeDL] Simplify API of YoutubeDL

Calling add_default_extractors twice should be harmless since the first set of extractors will match.
Philipp Hagemeister 11 年之前
父节点
当前提交
3511266bc3
共有 2 个文件被更改,包括 5 次插入4 次删除
  1. 5 1
      youtube_dl/YoutubeDL.py
  2. 0 3
      youtube_dl/__init__.py

+ 5 - 1
youtube_dl/YoutubeDL.py

@@ -189,7 +189,7 @@ class YoutubeDL(object):
     _num_downloads = None
     _num_downloads = None
     _screen_file = None
     _screen_file = None
 
 
-    def __init__(self, params=None):
+    def __init__(self, params=None, auto_init=True):
         """Create a FileDownloader object with the given options."""
         """Create a FileDownloader object with the given options."""
         if params is None:
         if params is None:
             params = {}
             params = {}
@@ -246,6 +246,10 @@ class YoutubeDL(object):
 
 
         self._setup_opener()
         self._setup_opener()
 
 
+        if auto_init:
+            self.print_debug_header()
+            self.add_default_info_extractors()
+
     def add_info_extractor(self, ie):
     def add_info_extractor(self, ie):
         """Add an InfoExtractor object to the end of the list."""
         """Add an InfoExtractor object to the end of the list."""
         self._ies.append(ie)
         self._ies.append(ie)

+ 0 - 3
youtube_dl/__init__.py

@@ -293,9 +293,6 @@ def _real_main(argv=None):
     }
     }
 
 
     with YoutubeDL(ydl_opts) as ydl:
     with YoutubeDL(ydl_opts) as ydl:
-        ydl.print_debug_header()
-        ydl.add_default_info_extractors()
-
         # PostProcessors
         # PostProcessors
         # Add the metadata pp first, the other pps will copy it
         # Add the metadata pp first, the other pps will copy it
         if opts.addmetadata:
         if opts.addmetadata: