__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from ..compat.compat_utils import passthrough_module
  2. passthrough_module(__name__, '.extractors')
  3. del passthrough_module
  4. def gen_extractor_classes():
  5. """ Return a list of supported extractors.
  6. The order does matter; the first extractor matched is the one handling the URL.
  7. """
  8. from .extractors import _ALL_CLASSES
  9. return _ALL_CLASSES
  10. def gen_extractors():
  11. """ Return a list of an instance of every supported extractor.
  12. The order does matter; the first extractor matched is the one handling the URL.
  13. """
  14. return [klass() for klass in gen_extractor_classes()]
  15. def list_extractor_classes(age_limit=None):
  16. """Return a list of extractors that are suitable for the given age, sorted by extractor name"""
  17. from .generic import GenericIE
  18. yield from sorted(filter(
  19. lambda ie: ie.is_suitable(age_limit) and ie != GenericIE,
  20. gen_extractor_classes()), key=lambda ie: ie.IE_NAME.lower())
  21. yield GenericIE
  22. def list_extractors(age_limit=None):
  23. """Return a list of extractor instances that are suitable for the given age, sorted by extractor name"""
  24. return [ie() for ie in list_extractor_classes(age_limit)]
  25. def get_info_extractor(ie_name):
  26. """Returns the info extractor class with the given ie_name"""
  27. from . import extractors
  28. return getattr(extractors, f'{ie_name}IE')