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