]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/__init__.py
1 from __future__
import unicode_literals
3 from ..compat
import compat_str
10 def get_suitable_downloader(info_dict
, params
={}, default
=NO_DEFAULT
, protocol
=None, to_stdout
=False):
11 info_dict
['protocol'] = determine_protocol(info_dict
)
12 info_copy
= info_dict
.copy()
14 info_copy
['protocol'] = protocol
15 info_copy
['to_stdout'] = to_stdout
16 return _get_suitable_downloader(info_copy
, params
, default
)
19 # Some of these require get_suitable_downloader
20 from .common
import FileDownloader
21 from .dash
import DashSegmentsFD
22 from .f4m
import F4mFD
23 from .hls
import HlsFD
24 from .http
import HttpFD
25 from .rtmp
import RtmpFD
26 from .rtsp
import RtspFD
27 from .ism
import IsmFD
28 from .mhtml
import MhtmlFD
29 from .niconico
import NiconicoDmcFD
30 from .websocket
import WebSocketFragmentFD
31 from .youtube_live_chat
import YoutubeLiveChatFD
32 from .external
import (
33 get_external_downloader
,
39 'rtmp_ffmpeg': FFmpegFD
,
45 'http_dash_segments': DashSegmentsFD
,
48 'niconico_dmc': NiconicoDmcFD
,
49 'websocket_frag': WebSocketFragmentFD
,
50 'youtube_live_chat': YoutubeLiveChatFD
,
51 'youtube_live_chat_replay': YoutubeLiveChatFD
,
55 def shorten_protocol_name(proto
, simplify
=False):
56 short_protocol_names
= {
57 'm3u8_native': 'm3u8_n',
58 'rtmp_ffmpeg': 'rtmp_f',
59 'http_dash_segments': 'dash',
60 'niconico_dmc': 'dmc',
61 'websocket_frag': 'WSfrag',
64 short_protocol_names
.update({
67 'm3u8_native': 'm3u8',
68 'rtmp_ffmpeg': 'rtmp',
69 'm3u8_frag_urls': 'm3u8',
70 'dash_frag_urls': 'dash',
72 return short_protocol_names
.get(proto
, proto
)
75 def _get_suitable_downloader(info_dict
, params
, default
):
76 """Get the downloader class that can handle the info dict."""
77 if default
is NO_DEFAULT
:
80 # 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):
83 protocol
= info_dict
['protocol']
84 downloaders
= params
.get('external_downloader')
85 external_downloader
= (
86 downloaders
if isinstance(downloaders
, compat_str
) or downloaders
is None
87 else downloaders
.get(shorten_protocol_name(protocol
, True), downloaders
.get('default')))
89 if external_downloader
is None:
90 if info_dict
['to_stdout'] and FFmpegFD
.can_merge_formats(info_dict
, params
):
92 elif external_downloader
.lower() != 'native':
93 ed
= get_external_downloader(external_downloader
)
94 if ed
.can_download(info_dict
, external_downloader
):
97 if protocol
== 'http_dash_segments':
98 if info_dict
.get('is_live') and (external_downloader
or '').lower() != 'native':
101 if protocol
in ('m3u8', 'm3u8_native'):
102 if info_dict
.get('is_live'):
104 elif (external_downloader
or '').lower() == 'native':
106 elif get_suitable_downloader(
107 info_dict
, params
, None, protocol
='m3u8_frag_urls', to_stdout
=info_dict
['to_stdout']):
109 elif params
.get('hls_prefer_native') is True:
111 elif params
.get('hls_prefer_native') is False:
114 return PROTOCOL_MAP
.get(protocol
, default
)
119 'get_suitable_downloader',
120 'shorten_protocol_name',