X-Git-Url: https://jfr.im/git/yt-dlp.git/blobdiff_plain/415f8d51a8f3565d7a1d4a8188511e7ad68514c7..c487cf00101525ff836d59a2a42ef63e85ea9556:/yt_dlp/downloader/external.py diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.py index a9da96670..66eced1b3 100644 --- a/yt_dlp/downloader/external.py +++ b/yt_dlp/downloader/external.py @@ -1,3 +1,4 @@ +import enum import os.path import re import subprocess @@ -5,8 +6,8 @@ import time from .fragment import FragmentFD -from ..compat import functools -from ..compat import compat_setenv, compat_str +from ..compat import functools # isort: split +from ..compat import compat_setenv from ..postprocessor.ffmpeg import EXT_TO_OUT_FORMATS, FFmpegPostProcessor from ..utils import ( Popen, @@ -25,9 +26,14 @@ ) +class Features(enum.Enum): + TO_STDOUT = enum.auto() + MULTIPLE_FORMATS = enum.auto() + + class ExternalFD(FragmentFD): SUPPORTED_PROTOCOLS = ('http', 'https', 'ftp', 'ftps') - can_download_to_stdout = False + SUPPORTED_FEATURES = () def real_download(self, filename, info_dict): self.report_destination(filename) @@ -91,9 +97,11 @@ def available(cls, path=None): @classmethod def supports(cls, info_dict): - return ( - (cls.can_download_to_stdout or not info_dict.get('to_stdout')) - and info_dict['protocol'] in cls.SUPPORTED_PROTOCOLS) + return all(( + not info_dict.get('to_stdout') or Features.TO_STDOUT in cls.SUPPORTED_FEATURES, + '+' not in info_dict['protocol'] or Features.MULTIPLE_FORMATS in cls.SUPPORTED_FEATURES, + all(proto in cls.SUPPORTED_PROTOCOLS for proto in info_dict['protocol'].split('+')), + )) @classmethod def can_download(cls, info_dict, path=None): @@ -324,7 +332,7 @@ def _make_cmd(self, tmpfilename, info_dict): class FFmpegFD(ExternalFD): SUPPORTED_PROTOCOLS = ('http', 'https', 'ftp', 'ftps', 'm3u8', 'm3u8_native', 'rtsp', 'rtmp', 'rtmp_ffmpeg', 'mms', 'http_dash_segments') - can_download_to_stdout = True + SUPPORTED_FEATURES = (Features.TO_STDOUT, Features.MULTIPLE_FORMATS) @classmethod def available(cls, path=None): @@ -332,10 +340,6 @@ def available(cls, path=None): # Fixme: This may be wrong when --ffmpeg-location is used return FFmpegPostProcessor().available - @classmethod - def supports(cls, info_dict): - return all(proto in cls.SUPPORTED_PROTOCOLS for proto in info_dict['protocol'].split('+')) - def on_process_started(self, proc, stdin): """ Override this in subclasses """ pass @@ -382,10 +386,10 @@ def _call_downloader(self, tmpfilename, info_dict): # start_time = info_dict.get('start_time') or 0 # if start_time: - # args += ['-ss', compat_str(start_time)] + # args += ['-ss', str(start_time)] # end_time = info_dict.get('end_time') # if end_time: - # args += ['-t', compat_str(end_time - start_time)] + # args += ['-t', str(end_time - start_time)] http_headers = None if info_dict.get('http_headers'): @@ -444,7 +448,7 @@ def _call_downloader(self, tmpfilename, info_dict): if isinstance(conn, list): for entry in conn: args += ['-rtmp_conn', entry] - elif isinstance(conn, compat_str): + elif isinstance(conn, str): args += ['-rtmp_conn', conn] for i, url in enumerate(urls): @@ -462,7 +466,7 @@ def _call_downloader(self, tmpfilename, info_dict): args.extend(['-map', f'{i}:{stream_number}']) if self.params.get('test', False): - args += ['-fs', compat_str(self._TEST_FILE_SIZE)] + args += ['-fs', str(self._TEST_FILE_SIZE)] ext = info_dict['ext'] if protocol in ('m3u8', 'm3u8_native'):