mirror of
				https://github.com/ytdl-org/youtube-dl.git
				synced 2025-10-29 09:26:20 -07:00 
			
		
		
		
	Delay initialization of InfoExtractors until they are needed
This commit is contained in:
		| @@ -82,7 +82,7 @@ from .utils import ( | |||||||
|     YoutubeDLHandler, |     YoutubeDLHandler, | ||||||
| ) | ) | ||||||
| from .cache import Cache | from .cache import Cache | ||||||
| from .extractor import get_info_extractor, gen_extractors | from .extractor import get_info_extractor, gen_extractor_classes | ||||||
| from .downloader import get_suitable_downloader | from .downloader import get_suitable_downloader | ||||||
| from .downloader.rtmp import rtmpdump_version | from .downloader.rtmp import rtmpdump_version | ||||||
| from .postprocessor import ( | from .postprocessor import ( | ||||||
| @@ -378,8 +378,9 @@ class YoutubeDL(object): | |||||||
|     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) | ||||||
|         self._ies_instances[ie.ie_key()] = ie |         if not isinstance(ie, type): | ||||||
|         ie.set_downloader(self) |             self._ies_instances[ie.ie_key()] = ie | ||||||
|  |             ie.set_downloader(self) | ||||||
|  |  | ||||||
|     def get_info_extractor(self, ie_key): |     def get_info_extractor(self, ie_key): | ||||||
|         """ |         """ | ||||||
| @@ -397,7 +398,7 @@ class YoutubeDL(object): | |||||||
|         """ |         """ | ||||||
|         Add the InfoExtractors returned by gen_extractors to the end of the list |         Add the InfoExtractors returned by gen_extractors to the end of the list | ||||||
|         """ |         """ | ||||||
|         for ie in gen_extractors(): |         for ie in gen_extractor_classes(): | ||||||
|             self.add_info_extractor(ie) |             self.add_info_extractor(ie) | ||||||
|  |  | ||||||
|     def add_post_processor(self, pp): |     def add_post_processor(self, pp): | ||||||
| @@ -661,6 +662,7 @@ class YoutubeDL(object): | |||||||
|             if not ie.suitable(url): |             if not ie.suitable(url): | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|  |             ie = self.get_info_extractor(ie.ie_key()) | ||||||
|             if not ie.working(): |             if not ie.working(): | ||||||
|                 self.report_warning('The program functionality for this site has been marked as broken, ' |                 self.report_warning('The program functionality for this site has been marked as broken, ' | ||||||
|                                     'and will probably not work.') |                                     'and will probably not work.') | ||||||
|   | |||||||
| @@ -997,11 +997,18 @@ _ALL_CLASSES = [ | |||||||
| _ALL_CLASSES.append(GenericIE) | _ALL_CLASSES.append(GenericIE) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def gen_extractor_classes(): | ||||||
|  |     """ Return a list of supported extractors. | ||||||
|  |     The order does matter; the first extractor matched is the one handling the URL. | ||||||
|  |     """ | ||||||
|  |     return _ALL_CLASSES | ||||||
|  |  | ||||||
|  |  | ||||||
| def gen_extractors(): | def gen_extractors(): | ||||||
|     """ Return a list of an instance of every supported extractor. |     """ Return a list of an instance of every supported extractor. | ||||||
|     The order does matter; the first extractor matched is the one handling the URL. |     The order does matter; the first extractor matched is the one handling the URL. | ||||||
|     """ |     """ | ||||||
|     return [klass() for klass in _ALL_CLASSES] |     return [klass() for klass in gen_extractor_classes()] | ||||||
|  |  | ||||||
|  |  | ||||||
| def list_extractors(age_limit): | def list_extractors(age_limit): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user