]> jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/__init__.py
Improve argument parsing for `-P`, `-o`, `-S`
[yt-dlp.git] / yt_dlp / downloader / __init__.py
1 from __future__ import unicode_literals
2
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
16 from .common import FileDownloader
17 from .dash import DashSegmentsFD
18 from .f4m import F4mFD
19 from .hls import HlsFD
20 from .http import HttpFD
21 from .rtmp import RtmpFD
22 from .rtsp import RtspFD
23 from .ism import IsmFD
24 from .niconico import NiconicoDmcFD
25 from .youtube_live_chat import YoutubeLiveChatReplayFD
26 from .external import (
27 get_external_downloader,
28 FFmpegFD,
29 )
30
31 PROTOCOL_MAP = {
32 'rtmp': RtmpFD,
33 'm3u8_native': HlsFD,
34 'm3u8': FFmpegFD,
35 'mms': RtspFD,
36 'rtsp': RtspFD,
37 'f4m': F4mFD,
38 'http_dash_segments': DashSegmentsFD,
39 'ism': IsmFD,
40 'niconico_dmc': NiconicoDmcFD,
41 'youtube_live_chat_replay': YoutubeLiveChatReplayFD,
42 }
43
44
45 def get_suitable_downloader(info_dict, params={}, default=HttpFD):
46 """Get the downloader class that can handle the info dict."""
47 protocol = determine_protocol(info_dict)
48 info_dict['protocol'] = protocol
49
50 # 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):
51 # return FFmpegFD
52
53 external_downloader = params.get('external_downloader')
54 if external_downloader is not None:
55 ed = get_external_downloader(external_downloader)
56 if ed.can_download(info_dict, external_downloader):
57 return ed
58
59 if protocol.startswith('m3u8'):
60 if info_dict.get('is_live'):
61 return FFmpegFD
62 elif _get_real_downloader(info_dict, 'frag_urls', params, None):
63 return HlsFD
64 elif params.get('hls_prefer_native') is True:
65 return HlsFD
66 elif params.get('hls_prefer_native') is False:
67 return FFmpegFD
68
69 return PROTOCOL_MAP.get(protocol, default)
70
71
72 __all__ = [
73 'get_suitable_downloader',
74 'FileDownloader',
75 ]