]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/__init__.py
510c7b60140054619464d0bee70eacc68431d0e3
1 from __future__
import unicode_literals
3 from ..compat
import compat_str
9 def _get_real_downloader(info_dict
, protocol
=None, *args
, **kwargs
):
10 info_copy
= info_dict
.copy()
12 info_copy
['protocol'] = protocol
13 return get_suitable_downloader(info_copy
, *args
, **kwargs
)
16 # Some of these require _get_real_downloader
17 from .common
import FileDownloader
18 from .dash
import DashSegmentsFD
19 from .f4m
import F4mFD
20 from .hls
import HlsFD
21 from .http
import HttpFD
22 from .rtmp
import RtmpFD
23 from .rtsp
import RtspFD
24 from .ism
import IsmFD
25 from .niconico
import NiconicoDmcFD
26 from .youtube_live_chat
import YoutubeLiveChatReplayFD
27 from .external
import (
28 get_external_downloader
,
39 'http_dash_segments': DashSegmentsFD
,
41 'niconico_dmc': NiconicoDmcFD
,
42 'youtube_live_chat_replay': YoutubeLiveChatReplayFD
,
46 def shorten_protocol_name(proto
, simplify
=False):
47 short_protocol_names
= {
48 'm3u8_native': 'm3u8_n',
49 'http_dash_segments': 'dash',
50 'niconico_dmc': 'dmc',
53 short_protocol_names
.update({
56 'm3u8_native': 'm3u8',
57 'm3u8_frag_urls': 'm3u8',
58 'dash_frag_urls': 'dash',
60 return short_protocol_names
.get(proto
, proto
)
63 def get_suitable_downloader(info_dict
, params
={}, default
=HttpFD
):
64 """Get the downloader class that can handle the info dict."""
65 protocol
= determine_protocol(info_dict
)
66 info_dict
['protocol'] = protocol
68 # 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):
71 downloaders
= params
.get('external_downloader')
72 external_downloader
= (
73 downloaders
if isinstance(downloaders
, compat_str
) or downloaders
is None
74 else downloaders
.get(shorten_protocol_name(protocol
, True), downloaders
.get('default')))
75 if external_downloader
and external_downloader
.lower() == 'native':
76 external_downloader
= 'native'
78 if external_downloader
not in (None, 'native'):
79 ed
= get_external_downloader(external_downloader
)
80 if ed
.can_download(info_dict
, external_downloader
):
83 if protocol
in ('m3u8', 'm3u8_native'):
84 if info_dict
.get('is_live'):
86 elif external_downloader
== 'native':
88 elif _get_real_downloader(info_dict
, 'm3u8_frag_urls', params
, None):
90 elif params
.get('hls_prefer_native') is True:
92 elif params
.get('hls_prefer_native') is False:
95 return PROTOCOL_MAP
.get(protocol
, default
)
100 'get_suitable_downloader',
101 'shorten_protocol_name',