]>
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()
13 info_copy
['to_stdout'] = to_stdout
15 downloaders
= [_get_suitable_downloader(info_copy
, proto
, params
, default
)
16 for proto
in (protocol
or info_copy
['protocol']).split('+')]
17 if set(downloaders
) == {FFmpegFD}
and FFmpegFD
.can_merge_formats(info_copy
, params
):
19 elif len(downloaders
) == 1:
24 # Some of these require get_suitable_downloader
25 from .common
import FileDownloader
26 from .dash
import DashSegmentsFD
27 from .f4m
import F4mFD
28 from .hls
import HlsFD
29 from .http
import HttpFD
30 from .rtmp
import RtmpFD
31 from .rtsp
import RtspFD
32 from .ism
import IsmFD
33 from .mhtml
import MhtmlFD
34 from .niconico
import NiconicoDmcFD
35 from .websocket
import WebSocketFragmentFD
36 from .youtube_live_chat
import YoutubeLiveChatFD
37 from .external
import (
38 get_external_downloader
,
44 'rtmp_ffmpeg': FFmpegFD
,
50 'http_dash_segments': DashSegmentsFD
,
53 'niconico_dmc': NiconicoDmcFD
,
54 'websocket_frag': WebSocketFragmentFD
,
55 'youtube_live_chat': YoutubeLiveChatFD
,
56 'youtube_live_chat_replay': YoutubeLiveChatFD
,
60 def shorten_protocol_name(proto
, simplify
=False):
61 short_protocol_names
= {
62 'm3u8_native': 'm3u8_n',
63 'rtmp_ffmpeg': 'rtmp_f',
64 'http_dash_segments': 'dash',
65 'niconico_dmc': 'dmc',
66 'websocket_frag': 'WSfrag',
69 short_protocol_names
.update({
72 'm3u8_native': 'm3u8',
73 'rtmp_ffmpeg': 'rtmp',
74 'm3u8_frag_urls': 'm3u8',
75 'dash_frag_urls': 'dash',
77 return short_protocol_names
.get(proto
, proto
)
80 def _get_suitable_downloader(info_dict
, protocol
, params
, default
):
81 """Get the downloader class that can handle the info dict."""
82 if default
is NO_DEFAULT
:
85 # 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):
88 info_dict
['protocol'] = protocol
89 downloaders
= params
.get('external_downloader')
90 external_downloader
= (
91 downloaders
if isinstance(downloaders
, compat_str
) or downloaders
is None
92 else downloaders
.get(shorten_protocol_name(protocol
, True), downloaders
.get('default')))
94 if external_downloader
is None:
95 if info_dict
['to_stdout'] and FFmpegFD
.can_merge_formats(info_dict
, params
):
97 elif external_downloader
.lower() != 'native':
98 ed
= get_external_downloader(external_downloader
)
99 if ed
.can_download(info_dict
, external_downloader
):
102 if protocol
== 'http_dash_segments':
103 if info_dict
.get('is_live') and (external_downloader
or '').lower() != 'native':
106 if protocol
in ('m3u8', 'm3u8_native'):
107 if info_dict
.get('is_live'):
109 elif (external_downloader
or '').lower() == 'native':
111 elif get_suitable_downloader(
112 info_dict
, params
, None, protocol
='m3u8_frag_urls', to_stdout
=info_dict
['to_stdout']):
114 elif params
.get('hls_prefer_native') is True:
116 elif params
.get('hls_prefer_native') is False:
119 return PROTOCOL_MAP
.get(protocol
, default
)
124 'get_suitable_downloader',
125 'shorten_protocol_name',