[downloader/external] check for external downloaders availability
[youtube-dl] / youtube_dl / downloader / __init__.py
1 from __future__ import unicode_literals
2
3 from .common import FileDownloader
4 from .f4m import F4mFD
5 from .hls import HlsFD
6 from .http import HttpFD
7 from .rtmp import RtmpFD
8 from .dash import DashSegmentsFD
9 from .external import (
10     get_external_downloader,
11     FFmpegFD,
12 )
13
14 from ..utils import (
15     determine_protocol,
16 )
17
18 PROTOCOL_MAP = {
19     'rtmp': RtmpFD,
20     'm3u8_native': HlsFD,
21     'm3u8': FFmpegFD,
22     'mms': FFmpegFD,
23     'rtsp': FFmpegFD,
24     'f4m': F4mFD,
25     'http_dash_segments': DashSegmentsFD,
26 }
27
28
29 def get_suitable_downloader(info_dict, params={}):
30     """Get the downloader class that can handle the info dict."""
31     protocol = determine_protocol(info_dict)
32     info_dict['protocol'] = protocol
33
34     if (info_dict.get('start_time') or info_dict.get('end_time')) and FFmpegFD.available() and FFmpegFD.supports(info_dict):
35         return FFmpegFD
36
37     external_downloader = params.get('external_downloader')
38     if external_downloader is not None:
39         ed = get_external_downloader(external_downloader)
40         if ed.available() and ed.supports(info_dict):
41             return ed
42
43     if protocol == 'm3u8' and params.get('hls_prefer_native'):
44         return HlsFD
45
46     return PROTOCOL_MAP.get(protocol, HttpFD)
47
48
49 __all__ = [
50     'get_suitable_downloader',
51     'FileDownloader',
52 ]