2014-01-26 21:47:30 -07:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2021-04-10 09:08:33 -06:00
|
|
|
from ..compat import compat_str
|
2021-02-08 09:46:01 -07:00
|
|
|
from ..utils import (
|
|
|
|
determine_protocol,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_real_downloader(info_dict, protocol=None, *args, **kwargs):
|
|
|
|
info_copy = info_dict.copy()
|
|
|
|
if protocol:
|
|
|
|
info_copy['protocol'] = protocol
|
|
|
|
return get_suitable_downloader(info_copy, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
# Some of these require _get_real_downloader
|
2013-09-23 09:59:27 -06:00
|
|
|
from .common import FileDownloader
|
2021-02-08 09:46:01 -07:00
|
|
|
from .dash import DashSegmentsFD
|
2015-01-23 17:38:48 -07:00
|
|
|
from .f4m import F4mFD
|
2013-09-23 09:59:27 -06:00
|
|
|
from .hls import HlsFD
|
|
|
|
from .http import HttpFD
|
|
|
|
from .rtmp import RtmpFD
|
2016-03-13 08:24:02 -06:00
|
|
|
from .rtsp import RtspFD
|
2016-10-19 09:22:40 -06:00
|
|
|
from .ism import IsmFD
|
2021-02-09 23:45:20 -07:00
|
|
|
from .niconico import NiconicoDmcFD
|
2020-08-04 16:02:23 -06:00
|
|
|
from .youtube_live_chat import YoutubeLiveChatReplayFD
|
2016-02-19 11:29:24 -07:00
|
|
|
from .external import (
|
|
|
|
get_external_downloader,
|
|
|
|
FFmpegFD,
|
|
|
|
)
|
2013-09-23 09:59:27 -06:00
|
|
|
|
2015-01-23 15:50:31 -07:00
|
|
|
PROTOCOL_MAP = {
|
|
|
|
'rtmp': RtmpFD,
|
2016-02-19 11:29:24 -07:00
|
|
|
'm3u8_native': HlsFD,
|
|
|
|
'm3u8': FFmpegFD,
|
2016-03-13 08:24:02 -06:00
|
|
|
'mms': RtspFD,
|
|
|
|
'rtsp': RtspFD,
|
2015-01-23 15:50:31 -07:00
|
|
|
'f4m': F4mFD,
|
2015-06-04 08:27:29 -06:00
|
|
|
'http_dash_segments': DashSegmentsFD,
|
2016-10-19 09:22:40 -06:00
|
|
|
'ism': IsmFD,
|
2021-02-09 23:45:20 -07:00
|
|
|
'niconico_dmc': NiconicoDmcFD,
|
2020-08-04 16:02:23 -06:00
|
|
|
'youtube_live_chat_replay': YoutubeLiveChatReplayFD,
|
2015-01-23 15:50:31 -07:00
|
|
|
}
|
2014-01-25 04:02:43 -07:00
|
|
|
|
2015-01-23 15:50:31 -07:00
|
|
|
|
2021-04-10 09:08:33 -06:00
|
|
|
def shorten_protocol_name(proto, simplify=False):
|
|
|
|
short_protocol_names = {
|
|
|
|
'm3u8_native': 'm3u8_n',
|
|
|
|
'http_dash_segments': 'dash',
|
|
|
|
'niconico_dmc': 'dmc',
|
|
|
|
}
|
|
|
|
if simplify:
|
|
|
|
short_protocol_names.update({
|
|
|
|
'https': 'http',
|
|
|
|
'ftps': 'ftp',
|
|
|
|
'm3u8_native': 'm3u8',
|
|
|
|
'm3u8_frag_urls': 'm3u8',
|
|
|
|
'dash_frag_urls': 'dash',
|
|
|
|
})
|
|
|
|
return short_protocol_names.get(proto, proto)
|
|
|
|
|
|
|
|
|
2021-02-08 09:46:01 -07:00
|
|
|
def get_suitable_downloader(info_dict, params={}, default=HttpFD):
|
2013-09-23 09:59:27 -06:00
|
|
|
"""Get the downloader class that can handle the info dict."""
|
2015-01-23 15:50:31 -07:00
|
|
|
protocol = determine_protocol(info_dict)
|
|
|
|
info_dict['protocol'] = protocol
|
|
|
|
|
2016-03-13 13:25:39 -06:00
|
|
|
# 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):
|
2016-03-13 09:16:26 -06:00
|
|
|
# return FFmpegFD
|
2016-02-19 11:29:24 -07:00
|
|
|
|
2021-04-10 09:08:33 -06:00
|
|
|
downloaders = params.get('external_downloader')
|
|
|
|
external_downloader = (
|
2021-04-10 09:45:32 -06:00
|
|
|
downloaders if isinstance(downloaders, compat_str) or downloaders is None
|
2021-04-10 09:08:33 -06:00
|
|
|
else downloaders.get(shorten_protocol_name(protocol, True), downloaders.get('default')))
|
|
|
|
if external_downloader and external_downloader.lower() == 'native':
|
|
|
|
external_downloader = 'native'
|
|
|
|
|
|
|
|
if external_downloader not in (None, 'native'):
|
2015-01-23 17:38:48 -07:00
|
|
|
ed = get_external_downloader(external_downloader)
|
2021-02-27 04:22:27 -07:00
|
|
|
if ed.can_download(info_dict, external_downloader):
|
2015-01-23 17:38:48 -07:00
|
|
|
return ed
|
|
|
|
|
2021-04-13 22:27:48 -06:00
|
|
|
if protocol in ('m3u8', 'm3u8_native'):
|
2021-02-08 09:46:01 -07:00
|
|
|
if info_dict.get('is_live'):
|
|
|
|
return FFmpegFD
|
2021-04-10 09:08:33 -06:00
|
|
|
elif external_downloader == 'native':
|
|
|
|
return HlsFD
|
2021-04-12 11:04:11 -06:00
|
|
|
elif _get_real_downloader(info_dict, 'm3u8_frag_urls', params, None):
|
2021-02-08 09:46:01 -07:00
|
|
|
return HlsFD
|
|
|
|
elif params.get('hls_prefer_native') is True:
|
|
|
|
return HlsFD
|
|
|
|
elif params.get('hls_prefer_native') is False:
|
|
|
|
return FFmpegFD
|
2016-04-21 11:02:17 -06:00
|
|
|
|
2021-02-08 09:46:01 -07:00
|
|
|
return PROTOCOL_MAP.get(protocol, default)
|
2015-01-23 15:50:31 -07:00
|
|
|
|
2014-11-23 14:25:12 -07:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'FileDownloader',
|
2021-04-10 09:08:33 -06:00
|
|
|
'get_suitable_downloader',
|
|
|
|
'shorten_protocol_name',
|
2014-11-23 14:25:12 -07:00
|
|
|
]
|