diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-07-31 16:21:01 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-08-01 12:38:05 +0530 |
commit | dbf5416a20b8a4ff301ef6c641f516fa20a546cb (patch) | |
tree | 959c28dd0afea7a2571066765eeb744b5d0a826e /yt_dlp/downloader/__init__.py | |
parent | d74a58a186603670f0f8acbc07a54f6381ca267f (diff) | |
download | hypervideo-pre-dbf5416a20b8a4ff301ef6c641f516fa20a546cb.tar.lz hypervideo-pre-dbf5416a20b8a4ff301ef6c641f516fa20a546cb.tar.xz hypervideo-pre-dbf5416a20b8a4ff301ef6c641f516fa20a546cb.zip |
[cleanup] Refactor some code
Diffstat (limited to 'yt_dlp/downloader/__init__.py')
-rw-r--r-- | yt_dlp/downloader/__init__.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/yt_dlp/downloader/__init__.py b/yt_dlp/downloader/__init__.py index 6769cf8e6..53393e89f 100644 --- a/yt_dlp/downloader/__init__.py +++ b/yt_dlp/downloader/__init__.py @@ -3,17 +3,19 @@ from __future__ import unicode_literals from ..compat import compat_str from ..utils import ( determine_protocol, + NO_DEFAULT ) -def _get_real_downloader(info_dict, protocol=None, *args, **kwargs): +def get_suitable_downloader(info_dict, params={}, default=NO_DEFAULT, protocol=None): + info_dict['protocol'] = determine_protocol(info_dict) info_copy = info_dict.copy() if protocol: info_copy['protocol'] = protocol - return get_suitable_downloader(info_copy, *args, **kwargs) + return _get_suitable_downloader(info_copy, params, default) -# Some of these require _get_real_downloader +# Some of these require get_suitable_downloader from .common import FileDownloader from .dash import DashSegmentsFD from .f4m import F4mFD @@ -69,14 +71,15 @@ def shorten_protocol_name(proto, simplify=False): return short_protocol_names.get(proto, proto) -def get_suitable_downloader(info_dict, params={}, default=HttpFD): +def _get_suitable_downloader(info_dict, params, default): """Get the downloader class that can handle the info dict.""" - protocol = determine_protocol(info_dict) - info_dict['protocol'] = protocol + if default is NO_DEFAULT: + default = HttpFD # 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): # return FFmpegFD + protocol = info_dict['protocol'] downloaders = params.get('external_downloader') external_downloader = ( downloaders if isinstance(downloaders, compat_str) or downloaders is None @@ -94,7 +97,7 @@ def get_suitable_downloader(info_dict, params={}, default=HttpFD): return FFmpegFD elif external_downloader == 'native': return HlsFD - elif _get_real_downloader(info_dict, 'm3u8_frag_urls', params, None): + elif get_suitable_downloader(info_dict, params, None, protocol='m3u8_frag_urls'): return HlsFD elif params.get('hls_prefer_native') is True: return HlsFD |