2014-01-27 05:47:30 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2021-12-08 00:30:30 +01:00
|
|
|
from ..utils import (
|
|
|
|
determine_protocol,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def get_suitable_downloader(info_dict, params={}):
|
|
|
|
info_dict['protocol'] = determine_protocol(info_dict)
|
|
|
|
info_copy = info_dict.copy()
|
|
|
|
return _get_suitable_downloader(info_copy, params)
|
|
|
|
|
|
|
|
|
|
|
|
# Some of these require get_suitable_downloader
|
2013-09-23 17:59:27 +02:00
|
|
|
from .common import FileDownloader
|
2021-12-08 00:30:30 +01:00
|
|
|
from .dash import DashSegmentsFD
|
2015-01-24 01:38:48 +01:00
|
|
|
from .f4m import F4mFD
|
2013-09-23 17:59:27 +02:00
|
|
|
from .hls import HlsFD
|
|
|
|
from .http import HttpFD
|
|
|
|
from .rtmp import RtmpFD
|
2016-03-13 15:24:02 +01:00
|
|
|
from .rtsp import RtspFD
|
2016-10-19 17:22:40 +02:00
|
|
|
from .ism import IsmFD
|
2021-12-08 00:30:30 +01:00
|
|
|
from .niconico import NiconicoDmcFD
|
2016-02-19 19:29:24 +01:00
|
|
|
from .external import (
|
|
|
|
get_external_downloader,
|
|
|
|
FFmpegFD,
|
|
|
|
)
|
2013-09-23 17:59:27 +02:00
|
|
|
|
2015-01-23 23:50:31 +01:00
|
|
|
PROTOCOL_MAP = {
|
|
|
|
'rtmp': RtmpFD,
|
2016-02-19 19:29:24 +01:00
|
|
|
'm3u8_native': HlsFD,
|
|
|
|
'm3u8': FFmpegFD,
|
2016-03-13 15:24:02 +01:00
|
|
|
'mms': RtspFD,
|
|
|
|
'rtsp': RtspFD,
|
2015-01-23 23:50:31 +01:00
|
|
|
'f4m': F4mFD,
|
2015-06-04 16:27:29 +02:00
|
|
|
'http_dash_segments': DashSegmentsFD,
|
2016-10-19 17:22:40 +02:00
|
|
|
'ism': IsmFD,
|
2021-12-08 00:30:30 +01:00
|
|
|
'niconico_dmc': NiconicoDmcFD,
|
2015-01-23 23:50:31 +01:00
|
|
|
}
|
2014-01-25 12:02:43 +01:00
|
|
|
|
2015-01-23 23:50:31 +01:00
|
|
|
|
2021-12-08 00:30:30 +01:00
|
|
|
def _get_suitable_downloader(info_dict, params={}):
|
2013-09-23 17:59:27 +02:00
|
|
|
"""Get the downloader class that can handle the info dict."""
|
2015-01-23 23:50:31 +01:00
|
|
|
|
2016-03-13 20:25:39 +01: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 16:16:26 +01:00
|
|
|
# return FFmpegFD
|
2016-02-19 19:29:24 +01:00
|
|
|
|
2015-01-24 01:38:48 +01:00
|
|
|
external_downloader = params.get('external_downloader')
|
|
|
|
if external_downloader is not None:
|
|
|
|
ed = get_external_downloader(external_downloader)
|
2016-03-13 14:53:17 +01:00
|
|
|
if ed.can_download(info_dict):
|
2015-01-24 01:38:48 +01:00
|
|
|
return ed
|
2022-02-22 12:24:06 +01:00
|
|
|
# Avoid using unwanted args since external_downloader was rejected
|
|
|
|
if params.get('external_downloader_args'):
|
|
|
|
params['external_downloader_args'] = None
|
2015-01-24 01:38:48 +01:00
|
|
|
|
2021-12-08 00:30:30 +01:00
|
|
|
protocol = info_dict['protocol']
|
2017-03-25 23:06:33 +01:00
|
|
|
if protocol.startswith('m3u8') and info_dict.get('is_live'):
|
|
|
|
return FFmpegFD
|
|
|
|
|
2016-04-21 19:02:17 +02:00
|
|
|
if protocol == 'm3u8' and params.get('hls_prefer_native') is True:
|
2016-02-19 19:29:24 +01:00
|
|
|
return HlsFD
|
2015-02-17 12:09:12 +01:00
|
|
|
|
2016-04-21 19:02:17 +02:00
|
|
|
if protocol == 'm3u8_native' and params.get('hls_prefer_native') is False:
|
|
|
|
return FFmpegFD
|
|
|
|
|
2015-01-23 23:50:31 +01:00
|
|
|
return PROTOCOL_MAP.get(protocol, HttpFD)
|
|
|
|
|
2014-11-23 22:25:12 +01:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'get_suitable_downloader',
|
|
|
|
'FileDownloader',
|
|
|
|
]
|