logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

__init__.py (2031B)


  1. from __future__ import unicode_literals
  2. from ..utils import (
  3. determine_protocol,
  4. )
  5. def get_suitable_downloader(info_dict, params={}):
  6. info_dict['protocol'] = determine_protocol(info_dict)
  7. info_copy = info_dict.copy()
  8. return _get_suitable_downloader(info_copy, params)
  9. # Some of these require get_suitable_downloader
  10. from .common import FileDownloader
  11. from .dash import DashSegmentsFD
  12. from .f4m import F4mFD
  13. from .hls import HlsFD
  14. from .http import HttpFD
  15. from .rtmp import RtmpFD
  16. from .rtsp import RtspFD
  17. from .ism import IsmFD
  18. from .niconico import NiconicoDmcFD
  19. from .external import (
  20. get_external_downloader,
  21. FFmpegFD,
  22. )
  23. PROTOCOL_MAP = {
  24. 'rtmp': RtmpFD,
  25. 'm3u8_native': HlsFD,
  26. 'm3u8': FFmpegFD,
  27. 'mms': RtspFD,
  28. 'rtsp': RtspFD,
  29. 'f4m': F4mFD,
  30. 'http_dash_segments': DashSegmentsFD,
  31. 'ism': IsmFD,
  32. 'niconico_dmc': NiconicoDmcFD,
  33. }
  34. def _get_suitable_downloader(info_dict, params={}):
  35. """Get the downloader class that can handle the info dict."""
  36. # 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):
  37. # return FFmpegFD
  38. external_downloader = params.get('external_downloader')
  39. if external_downloader is not None:
  40. ed = get_external_downloader(external_downloader)
  41. if ed.can_download(info_dict):
  42. return ed
  43. # Avoid using unwanted args since external_downloader was rejected
  44. if params.get('external_downloader_args'):
  45. params['external_downloader_args'] = None
  46. protocol = info_dict['protocol']
  47. if protocol.startswith('m3u8') and info_dict.get('is_live'):
  48. return FFmpegFD
  49. if protocol == 'm3u8' and params.get('hls_prefer_native') is True:
  50. return HlsFD
  51. if protocol == 'm3u8_native' and params.get('hls_prefer_native') is False:
  52. return FFmpegFD
  53. return PROTOCOL_MAP.get(protocol, HttpFD)
  54. __all__ = [
  55. 'get_suitable_downloader',
  56. 'FileDownloader',
  57. ]