]> jfr.im git - yt-dlp.git/blame - youtube_dlc/downloader/__init__.py
[version] update
[yt-dlp.git] / youtube_dlc / downloader / __init__.py
CommitLineData
db1f3888
PH
1from __future__ import unicode_literals
2
5219cb3e 3from ..utils import (
4 determine_protocol,
5)
6
7
8def _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 16from .common import FileDownloader
5219cb3e 17from .dash import DashSegmentsFD
222516d9 18from .f4m import F4mFD
3bc2ddcc
JMF
19from .hls import HlsFD
20from .http import HttpFD
3bc2ddcc 21from .rtmp import RtmpFD
be24916a 22from .rtsp import RtspFD
b2758123 23from .ism import IsmFD
a78e3a57 24from .youtube_live_chat import YoutubeLiveChatReplayFD
12b84ac8 25from .external import (
26 get_external_downloader,
27 FFmpegFD,
28)
3bc2ddcc 29
a055469f
PH
30PROTOCOL_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 43def 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]