2014-01-26 23:47:30 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2021-02-08 11:46:01 -05: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 11:59:27 -04:00
|
|
|
from .common import FileDownloader
|
2021-02-08 11:46:01 -05:00
|
|
|
from .dash import DashSegmentsFD
|
2015-01-23 19:38:48 -05:00
|
|
|
from .f4m import F4mFD
|
2013-09-23 11:59:27 -04:00
|
|
|
from .hls import HlsFD
|
|
|
|
from .http import HttpFD
|
|
|
|
from .rtmp import RtmpFD
|
2016-03-13 10:24:02 -04:00
|
|
|
from .rtsp import RtspFD
|
2016-10-19 11:22:40 -04:00
|
|
|
from .ism import IsmFD
|
2021-02-10 01:45:20 -05:00
|
|
|
from .niconico import NiconicoDmcFD
|
2020-08-04 18:02:23 -04:00
|
|
|
from .youtube_live_chat import YoutubeLiveChatReplayFD
|
2016-02-19 13:29:24 -05:00
|
|
|
from .external import (
|
|
|
|
get_external_downloader,
|
|
|
|
FFmpegFD,
|
|
|
|
)
|
2013-09-23 11:59:27 -04:00
|
|
|
|
2015-01-23 17:50:31 -05:00
|
|
|
PROTOCOL_MAP = {
|
|
|
|
'rtmp': RtmpFD,
|
2016-02-19 13:29:24 -05:00
|
|
|
'm3u8_native': HlsFD,
|
|
|
|
'm3u8': FFmpegFD,
|
2016-03-13 10:24:02 -04:00
|
|
|
'mms': RtspFD,
|
|
|
|
'rtsp': RtspFD,
|
2015-01-23 17:50:31 -05:00
|
|
|
'f4m': F4mFD,
|
2015-06-04 10:27:29 -04:00
|
|
|
'http_dash_segments': DashSegmentsFD,
|
2016-10-19 11:22:40 -04:00
|
|
|
'ism': IsmFD,
|
2021-02-10 01:45:20 -05:00
|
|
|
'niconico_dmc': NiconicoDmcFD,
|
2020-08-04 18:02:23 -04:00
|
|
|
'youtube_live_chat_replay': YoutubeLiveChatReplayFD,
|
2015-01-23 17:50:31 -05:00
|
|
|
}
|
2014-01-25 06:02:43 -05:00
|
|
|
|
2015-01-23 17:50:31 -05:00
|
|
|
|
2021-02-08 11:46:01 -05:00
|
|
|
def get_suitable_downloader(info_dict, params={}, default=HttpFD):
|
2013-09-23 11:59:27 -04:00
|
|
|
"""Get the downloader class that can handle the info dict."""
|
2015-01-23 17:50:31 -05:00
|
|
|
protocol = determine_protocol(info_dict)
|
|
|
|
info_dict['protocol'] = protocol
|
|
|
|
|
2016-03-13 15:25:39 -04: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 11:16:26 -04:00
|
|
|
# return FFmpegFD
|
2016-02-19 13:29:24 -05:00
|
|
|
|
2015-01-23 19:38:48 -05:00
|
|
|
external_downloader = params.get('external_downloader')
|
|
|
|
if external_downloader is not None:
|
|
|
|
ed = get_external_downloader(external_downloader)
|
2016-03-13 09:53:17 -04:00
|
|
|
if ed.can_download(info_dict):
|
2015-01-23 19:38:48 -05:00
|
|
|
return ed
|
|
|
|
|
2021-02-08 11:46:01 -05:00
|
|
|
if protocol.startswith('m3u8'):
|
|
|
|
if info_dict.get('is_live'):
|
|
|
|
return FFmpegFD
|
|
|
|
elif _get_real_downloader(info_dict, 'frag_urls', params, None):
|
|
|
|
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 13:02:17 -04:00
|
|
|
|
2021-02-08 11:46:01 -05:00
|
|
|
return PROTOCOL_MAP.get(protocol, default)
|
2015-01-23 17:50:31 -05:00
|
|
|
|
2014-11-23 16:25:12 -05:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'get_suitable_downloader',
|
|
|
|
'FileDownloader',
|
|
|
|
]
|