From 7afa5c42bf3485799130d1be738c7aed25e53d9b Mon Sep 17 00:00:00 2001 From: Dirley Rodrigues Date: Fri, 27 Sep 2013 10:00:25 -0300 Subject: [PATCH] Make sure things still work without pkg_resources --- youtube_dl/extractor/__init__.py | 16 +++++++++------- youtube_dl/utils.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 4bdfcc558..27acce9d9 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -1,5 +1,4 @@ from __future__ import unicode_literals - import pkg_resources from .abc import ABCIE from .academicearth import AcademicEarthCourseIE @@ -541,6 +540,7 @@ from .zingmp3 import ( ZingMp3SongIE, ZingMp3AlbumIE, ) +from ..utils import pkg_resources_iter_entry_points _ALL_CLASSES = [ @@ -555,23 +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. """ + extractors = [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]] + # the GenericIE must be the last one in the list, so we'll reappend it + # later + generic_ie = extractors.pop() - # load external extractors registered throguh the setuptools - # entry-point `youtube_dl.extractor.gen_extractors` + # load external extractors registered through the entry point + # `youtube_dl.extractors` group = 'youtube_dl.extractors' - for entrypoint in pkg_resources.iter_entry_points(group=group): + 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()) + extractors.append(generic_ie) return extractors diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 43b7c94ba..78949b763 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1543,3 +1543,13 @@ def ytdl_is_updateable(): def args_to_str(args): # Get a short string representation for a subprocess command return ' '.join(shlex_quote(a) for a in args) + + +# Support for platforms where pkg_resources is not available +try: + import pkg_resources + def pkg_resources_iter_entry_points(*args, **kwargs): + return pkg_resources.iter_entry_points(*args, **kwargs) +except ImportError: + def pkg_resources_iter_entry_points(*args, **kwargs): + return []