1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-14 07:37:25 +08:00

Make sure things still work without pkg_resources

This commit is contained in:
Dirley Rodrigues 2013-09-27 10:00:25 -03:00
parent 8f2216b9f6
commit 7afa5c42bf
2 changed files with 19 additions and 7 deletions

View File

@ -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

View File

@ -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 []