You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

  1. from __future__ import unicode_literals
  2. from .common import FileDownloader
  3. from .f4m import F4mFD
  4. from .hls import HlsFD
  5. from .http import HttpFD
  6. from .rtmp import RtmpFD
  7. from .dash import DashSegmentsFD
  8. from .external import (
  9. get_external_downloader,
  10. FFmpegFD,
  11. )
  12. from ..utils import (
  13. determine_protocol,
  14. )
  15. PROTOCOL_MAP = {
  16. 'rtmp': RtmpFD,
  17. 'm3u8_native': HlsFD,
  18. 'm3u8': FFmpegFD,
  19. 'mms': FFmpegFD,
  20. 'rtsp': FFmpegFD,
  21. 'f4m': F4mFD,
  22. 'http_dash_segments': DashSegmentsFD,
  23. }
  24. def get_suitable_downloader(info_dict, params={}):
  25. """Get the downloader class that can handle the info dict."""
  26. protocol = determine_protocol(info_dict)
  27. info_dict['protocol'] = protocol
  28. if (info_dict.get('start_time') or info_dict.get('end_time')) and FFmpegFD.available() and FFmpegFD.supports(info_dict):
  29. return FFmpegFD
  30. external_downloader = params.get('external_downloader')
  31. if external_downloader is not None:
  32. ed = get_external_downloader(external_downloader)
  33. if ed.available() and ed.supports(info_dict):
  34. return ed
  35. if protocol == 'm3u8' and params.get('hls_prefer_native'):
  36. return HlsFD
  37. return PROTOCOL_MAP.get(protocol, HttpFD)
  38. __all__ = [
  39. 'get_suitable_downloader',
  40. 'FileDownloader',
  41. ]