]>
Commit | Line | Data |
---|---|---|
db1f3888 PH |
1 | from __future__ import unicode_literals |
2 | ||
5219cb3e | 3 | from ..utils import ( |
4 | determine_protocol, | |
5 | ) | |
6 | ||
7 | ||
8 | def _get_real_downloader(info_dict, protocol=None, *args, **kwargs): | |
9 | info_copy = info_dict.copy() | |
10 | if protocol: | |
11 | info_copy['protocol'] = protocol | |
12 | return get_suitable_downloader(info_copy, *args, **kwargs) | |
13 | ||
14 | ||
15 | # Some of these require _get_real_downloader | |
3bc2ddcc | 16 | from .common import FileDownloader |
5219cb3e | 17 | from .dash import DashSegmentsFD |
222516d9 | 18 | from .f4m import F4mFD |
3bc2ddcc JMF |
19 | from .hls import HlsFD |
20 | from .http import HttpFD | |
3bc2ddcc | 21 | from .rtmp import RtmpFD |
be24916a | 22 | from .rtsp import RtspFD |
b2758123 | 23 | from .ism import IsmFD |
a78e3a57 | 24 | from .youtube_live_chat import YoutubeLiveChatReplayFD |
12b84ac8 | 25 | from .external import ( |
26 | get_external_downloader, | |
27 | FFmpegFD, | |
28 | ) | |
3bc2ddcc | 29 | |
a055469f PH |
30 | PROTOCOL_MAP = { |
31 | 'rtmp': RtmpFD, | |
12b84ac8 | 32 | 'm3u8_native': HlsFD, |
33 | 'm3u8': FFmpegFD, | |
be24916a | 34 | 'mms': RtspFD, |
35 | 'rtsp': RtspFD, | |
a055469f | 36 | 'f4m': F4mFD, |
423d2be5 | 37 | 'http_dash_segments': DashSegmentsFD, |
b2758123 | 38 | 'ism': IsmFD, |
a78e3a57 | 39 | 'youtube_live_chat_replay': YoutubeLiveChatReplayFD, |
a055469f | 40 | } |
f89197d7 | 41 | |
a055469f | 42 | |
5219cb3e | 43 | def get_suitable_downloader(info_dict, params={}, default=HttpFD): |
3bc2ddcc | 44 | """Get the downloader class that can handle the info dict.""" |
a055469f PH |
45 | protocol = determine_protocol(info_dict) |
46 | info_dict['protocol'] = protocol | |
47 | ||
6ae27bed | 48 | # 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): |
da1973a0 | 49 | # return FFmpegFD |
12b84ac8 | 50 | |
222516d9 PH |
51 | external_downloader = params.get('external_downloader') |
52 | if external_downloader is not None: | |
53 | ed = get_external_downloader(external_downloader) | |
2cb99ebb | 54 | if ed.can_download(info_dict): |
222516d9 PH |
55 | return ed |
56 | ||
5219cb3e | 57 | if protocol.startswith('m3u8'): |
58 | if info_dict.get('is_live'): | |
59 | return FFmpegFD | |
60 | elif _get_real_downloader(info_dict, 'frag_urls', params, None): | |
61 | return HlsFD | |
62 | elif params.get('hls_prefer_native') is True: | |
63 | return HlsFD | |
64 | elif params.get('hls_prefer_native') is False: | |
65 | return FFmpegFD | |
bf09af3a | 66 | |
5219cb3e | 67 | return PROTOCOL_MAP.get(protocol, default) |
a055469f | 68 | |
14d4e90e PH |
69 | |
70 | __all__ = [ | |
71 | 'get_suitable_downloader', | |
72 | 'FileDownloader', | |
73 | ] |