__init__.py 1.4 KB

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