]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/downloader/external.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / downloader / external.py
index a9da966709a7856ef4ea81eb4bc6aeae4658d11f..66eced1b33f6a5b569f94d56b4a1cc4ec9c48c13 100644 (file)
@@ -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,
 )
 
 
+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'):