]> jfr.im git - yt-dlp.git/blame - yt_dlp/downloader/__init__.py
[youtube:tab] Support channel search
[yt-dlp.git] / yt_dlp / downloader / __init__.py
CommitLineData
db1f3888
PH
1from __future__ import unicode_literals
2
52a8a1e1 3from ..compat import compat_str
5219cb3e 4from ..utils import (
5 determine_protocol,
6)
7
8
9def _get_real_downloader(info_dict, protocol=None, *args, **kwargs):
10 info_copy = info_dict.copy()
11 if protocol:
12 info_copy['protocol'] = protocol
13 return get_suitable_downloader(info_copy, *args, **kwargs)
14
15
16# Some of these require _get_real_downloader
3bc2ddcc 17from .common import FileDownloader
5219cb3e 18from .dash import DashSegmentsFD
222516d9 19from .f4m import F4mFD
3bc2ddcc
JMF
20from .hls import HlsFD
21from .http import HttpFD
3bc2ddcc 22from .rtmp import RtmpFD
be24916a 23from .rtsp import RtspFD
b2758123 24from .ism import IsmFD
fb198a8a 25from .niconico import NiconicoDmcFD
a78e3a57 26from .youtube_live_chat import YoutubeLiveChatReplayFD
12b84ac8 27from .external import (
28 get_external_downloader,
29 FFmpegFD,
30)
3bc2ddcc 31
a055469f
PH
32PROTOCOL_MAP = {
33 'rtmp': RtmpFD,
0fa9a1e2 34 'rtmp_ffmpeg': FFmpegFD,
12b84ac8 35 'm3u8_native': HlsFD,
36 'm3u8': FFmpegFD,
be24916a 37 'mms': RtspFD,
38 'rtsp': RtspFD,
a055469f 39 'f4m': F4mFD,
423d2be5 40 'http_dash_segments': DashSegmentsFD,
b2758123 41 'ism': IsmFD,
fb198a8a 42 'niconico_dmc': NiconicoDmcFD,
a78e3a57 43 'youtube_live_chat_replay': YoutubeLiveChatReplayFD,
a055469f 44}
f89197d7 45
a055469f 46
52a8a1e1 47def shorten_protocol_name(proto, simplify=False):
48 short_protocol_names = {
49 'm3u8_native': 'm3u8_n',
0fa9a1e2 50 'rtmp_ffmpeg': 'rtmp_f',
52a8a1e1 51 'http_dash_segments': 'dash',
52 'niconico_dmc': 'dmc',
53 }
54 if simplify:
55 short_protocol_names.update({
56 'https': 'http',
57 'ftps': 'ftp',
58 'm3u8_native': 'm3u8',
0fa9a1e2 59 'rtmp_ffmpeg': 'rtmp',
52a8a1e1 60 'm3u8_frag_urls': 'm3u8',
61 'dash_frag_urls': 'dash',
62 })
63 return short_protocol_names.get(proto, proto)
64
65
5219cb3e 66def get_suitable_downloader(info_dict, params={}, default=HttpFD):
3bc2ddcc 67 """Get the downloader class that can handle the info dict."""
a055469f
PH
68 protocol = determine_protocol(info_dict)
69 info_dict['protocol'] = protocol
70
6ae27bed 71 # 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 72 # return FFmpegFD
12b84ac8 73
52a8a1e1 74 downloaders = params.get('external_downloader')
75 external_downloader = (
68379de5 76 downloaders if isinstance(downloaders, compat_str) or downloaders is None
52a8a1e1 77 else downloaders.get(shorten_protocol_name(protocol, True), downloaders.get('default')))
78 if external_downloader and external_downloader.lower() == 'native':
79 external_downloader = 'native'
80
81 if external_downloader not in (None, 'native'):
222516d9 82 ed = get_external_downloader(external_downloader)
7f7de7f9 83 if ed.can_download(info_dict, external_downloader):
222516d9
PH
84 return ed
85
72e1fe96 86 if protocol in ('m3u8', 'm3u8_native'):
5219cb3e 87 if info_dict.get('is_live'):
88 return FFmpegFD
52a8a1e1 89 elif external_downloader == 'native':
90 return HlsFD
a31953b0 91 elif _get_real_downloader(info_dict, 'm3u8_frag_urls', params, None):
5219cb3e 92 return HlsFD
93 elif params.get('hls_prefer_native') is True:
94 return HlsFD
95 elif params.get('hls_prefer_native') is False:
96 return FFmpegFD
bf09af3a 97
5219cb3e 98 return PROTOCOL_MAP.get(protocol, default)
a055469f 99
14d4e90e
PH
100
101__all__ = [
14d4e90e 102 'FileDownloader',
52a8a1e1 103 'get_suitable_downloader',
104 'shorten_protocol_name',
14d4e90e 105]