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