From 8f2216b9f679587dbf670cb5e622610857e8ea58 Mon Sep 17 00:00:00 2001 From: Dirley Rodrigues Date: Tue, 6 Aug 2013 17:54:31 -0300 Subject: [PATCH] Add support for third-party extractors Other packages can register new extractors through the `youtube_dl.extractors` setuptools entry-point: # in mypackage/setup.py setup( ... entry_points={ 'youtube_dl.extractors': [ 'myextractor = mypackage.extractor.MyExtractorIE', ], }, ) --- youtube_dl/extractor/__init__.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index c30cbc926..4bdfcc558 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import pkg_resources from .abc import ABCIE from .academicearth import AcademicEarthCourseIE from .addanime import AddAnimeIE @@ -541,6 +542,7 @@ from .zingmp3 import ( ZingMp3AlbumIE, ) + _ALL_CLASSES = [ klass for name, klass in globals().items() @@ -553,7 +555,25 @@ def gen_extractors(): """ Return a list of an instance of every supported extractor. The order does matter; the first extractor matched is the one handling the URL. """ - return [klass() for klass in _ALL_CLASSES] + + # our extractors have priority over external extractors, but + # the GenericIE must be inserted later + extractors = [klass() for klass in _ALL_CLASSES[:-1]] + + # load external extractors registered throguh the setuptools + # entry-point `youtube_dl.extractor.gen_extractors` + group = 'youtube_dl.extractors' + + for entrypoint in pkg_resources.iter_entry_points(group=group): + # grab the callable that is the actual plugin + plugin = entrypoint.load() + + # install the plugin + extractors.append(plugin()) + + extractors.append(GenericIE()) + + return extractors def get_info_extractor(ie_name):