__init__.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from __future__ import unicode_literals
  2. from .extractors import *
  3. _ALL_CLASSES = [
  4. klass
  5. for name, klass in globals().items()
  6. if name.endswith('IE') and name != 'GenericIE'
  7. ]
  8. _ALL_CLASSES.append(GenericIE)
  9. def gen_extractor_classes():
  10. """ Return a list of supported extractors.
  11. The order does matter; the first extractor matched is the one handling the URL.
  12. """
  13. return _ALL_CLASSES
  14. def gen_extractors():
  15. """ Return a list of an instance of every supported extractor.
  16. The order does matter; the first extractor matched is the one handling the URL.
  17. """
  18. return [klass() for klass in gen_extractor_classes()]
  19. def list_extractors(age_limit):
  20. """
  21. Return a list of extractors that are suitable for the given age,
  22. sorted by extractor ID.
  23. """
  24. return sorted(
  25. filter(lambda ie: ie.is_suitable(age_limit), gen_extractors()),
  26. key=lambda ie: ie.IE_NAME.lower())
  27. def get_info_extractor(ie_name):
  28. """Returns the info extractor class with the given ie_name"""
  29. return globals()[ie_name + 'IE']