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.

62 lines
1.5KB

  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 .rtsp import RtspFD
  9. from .ism import IsmFD
  10. from .external import (
  11. get_external_downloader,
  12. FFmpegFD,
  13. )
  14. from ..utils import (
  15. determine_protocol,
  16. )
  17. PROTOCOL_MAP = {
  18. 'rtmp': RtmpFD,
  19. 'm3u8_native': HlsFD,
  20. 'm3u8': FFmpegFD,
  21. 'mms': RtspFD,
  22. 'rtsp': RtspFD,
  23. 'f4m': F4mFD,
  24. 'http_dash_segments': DashSegmentsFD,
  25. 'ism': IsmFD,
  26. }
  27. def get_suitable_downloader(info_dict, params={}):
  28. """Get the downloader class that can handle the info dict."""
  29. protocol = determine_protocol(info_dict)
  30. info_dict['protocol'] = protocol
  31. # if (info_dict.get('start_time') or info_dict.get('end_time')) and not info_dict.get('requested_formats') and FFmpegFD.can_download(info_dict):
  32. # return FFmpegFD
  33. external_downloader = params.get('external_downloader')
  34. if external_downloader is not None:
  35. ed = get_external_downloader(external_downloader)
  36. if ed.can_download(info_dict):
  37. return ed
  38. if protocol.startswith('m3u8') and info_dict.get('is_live'):
  39. return FFmpegFD
  40. if protocol == 'm3u8' and params.get('hls_prefer_native') is True:
  41. return HlsFD
  42. if protocol == 'm3u8_native' and params.get('hls_prefer_native') is False:
  43. return FFmpegFD
  44. return PROTOCOL_MAP.get(protocol, HttpFD)
  45. __all__ = [
  46. 'get_suitable_downloader',
  47. 'FileDownloader',
  48. ]