From 7b9efbd9a908c2fb4ea983bc5ebb69bcde9c3f35 Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:08:32 +0900 Subject: [PATCH] [utils] Deprecate `encodeArgument` (#17621) Authored by: doe1080 --- pyproject.toml | 1 + yt_dlp/downloader/external.py | 4 +--- yt_dlp/downloader/rtmp.py | 4 ---- yt_dlp/postprocessor/embedthumbnail.py | 7 +++---- yt_dlp/postprocessor/ffmpeg.py | 27 ++++++++++---------------- yt_dlp/utils/_deprecated.py | 4 ++++ yt_dlp/utils/_utils.py | 9 +-------- 7 files changed, 20 insertions(+), 36 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4f0df72a8d..978b4099ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -403,6 +403,7 @@ banned-from = [ "yt_dlp.utils.random_uuidv4".msg = "Use `str(uuid.uuid4())` instead." "yt_dlp.utils.decodeArgument".msg = "Do not use" "yt_dlp.utils.decodeFilename".msg = "Do not use" +"yt_dlp.utils.encodeArgument".msg = "Do not use" "yt_dlp.utils.encodeFilename".msg = "Do not use" "yt_dlp.compat.compat_os_name".msg = "Use `os.name` instead." "yt_dlp.compat.compat_realpath".msg = "Use `os.path.realpath` instead." diff --git a/yt_dlp/downloader/external.py b/yt_dlp/downloader/external.py index 27428821e1..abfdf8aea7 100644 --- a/yt_dlp/downloader/external.py +++ b/yt_dlp/downloader/external.py @@ -22,7 +22,6 @@ from ..utils import ( cli_option, cli_valueless_option, determine_ext, - encodeArgument, remove_end, traverse_obj, version_tuple, @@ -141,7 +140,7 @@ class ExternalFD(FragmentFD): def _call_downloader(self, tmpfilename, info_dict): """ Either overwrite this or implement _make_cmd """ - cmd = [encodeArgument(a) for a in self._make_cmd(tmpfilename, info_dict)] + cmd = self._make_cmd(tmpfilename, info_dict) self._debug_cmd(cmd) @@ -552,7 +551,6 @@ class FFmpegFD(ExternalFD): args += self._configuration_args(('_o1', '_o', '')) - args = [encodeArgument(opt) for opt in args] args.append(ffpp._ffmpeg_filename_argument(tmpfilename)) self._debug_cmd(args) diff --git a/yt_dlp/downloader/rtmp.py b/yt_dlp/downloader/rtmp.py index 1b831e5f30..5167eb5e93 100644 --- a/yt_dlp/downloader/rtmp.py +++ b/yt_dlp/downloader/rtmp.py @@ -7,7 +7,6 @@ from .common import FileDownloader from ..utils import ( Popen, check_executable, - encodeArgument, get_exe_version, ) @@ -154,8 +153,6 @@ class RtmpFD(FileDownloader): if not live and continue_dl: args += ['--skip', '1'] - args = [encodeArgument(a) for a in args] - self._debug_cmd(args, exe='rtmpdump') RD_SUCCESS = 0 @@ -184,7 +181,6 @@ class RtmpFD(FileDownloader): args = [*basic_args, '--resume'] if retval == RD_FAILED: args += ['--skip', '1'] - args = [encodeArgument(a) for a in args] retval = run_rtmpdump(args) cursize = os.path.getsize(tmpfilename) if prevsize == cursize and retval == RD_FAILED: diff --git a/yt_dlp/postprocessor/embedthumbnail.py b/yt_dlp/postprocessor/embedthumbnail.py index 39e8826c6f..5d571247eb 100644 --- a/yt_dlp/postprocessor/embedthumbnail.py +++ b/yt_dlp/postprocessor/embedthumbnail.py @@ -11,7 +11,6 @@ from ..utils import ( Popen, PostProcessingError, check_executable, - encodeArgument, prepend_extension, shell_quote, ) @@ -155,11 +154,11 @@ class EmbedThumbnailPP(FFmpegPostProcessor): self.to_screen('mutagen was not found. Falling back to AtomicParsley') cmd = [atomicparsley, filename, - encodeArgument('--artwork'), + '--artwork', thumbnail_filename, - encodeArgument('-o'), + '-o', temp_filename] - cmd += [encodeArgument(o) for o in self._configuration_args('AtomicParsley')] + cmd += self._configuration_args('AtomicParsley') self._report_run('atomicparsley', filename) self.write_debug(f'AtomicParsley command line: {shell_quote(cmd)}') diff --git a/yt_dlp/postprocessor/ffmpeg.py b/yt_dlp/postprocessor/ffmpeg.py index 587cad805c..26fb8f1040 100644 --- a/yt_dlp/postprocessor/ffmpeg.py +++ b/yt_dlp/postprocessor/ffmpeg.py @@ -20,7 +20,6 @@ from ..utils import ( detect_exe_version, determine_ext, dfxp2srt, - encodeArgument, filter_dict, float_or_none, is_outdated_version, @@ -235,14 +234,10 @@ class FFmpegPostProcessor(PostProcessor): raise PostProcessingError('ffprobe and ffmpeg not found. Please install or provide the path using --ffmpeg-location') try: if use_ffprobe: - cmd = [ - self.probe_executable, - encodeArgument('-show_streams')] + cmd = [self.probe_executable, '-show_streams'] basename = self.probe_basename else: - cmd = [ - self.executable, - encodeArgument('-i')] + cmd = [self.executable, '-i'] basename = self.basename cmd.append(self._ffmpeg_filename_argument(path)) self.write_debug(f'{basename} command line: {shell_quote(cmd)}') @@ -278,11 +273,11 @@ class FFmpegPostProcessor(PostProcessor): cmd = [ self.probe_executable, - encodeArgument('-hide_banner'), - encodeArgument('-show_format'), - encodeArgument('-show_streams'), - encodeArgument('-print_format'), - encodeArgument('json'), + '-hide_banner', + '-show_format', + '-show_streams', + '-print_format', + 'json', ] cmd += opts @@ -332,10 +327,10 @@ class FFmpegPostProcessor(PostProcessor): oldest_mtime = min( os.stat(path).st_mtime for path, _ in input_path_opts if path) - cmd = [self.executable, encodeArgument('-y')] + cmd = [self.executable, '-y'] # avconv does not have repeat option if self.basename == 'ffmpeg': - cmd += [encodeArgument('-loglevel'), encodeArgument('repeat+info')] + cmd += ['-loglevel', 'repeat+info'] def make_args(file, args, name, number): keys = [f'_{name}{number}', f'_{name}'] @@ -346,9 +341,7 @@ class FFmpegPostProcessor(PostProcessor): args += self._configuration_args(self.basename, keys) if name == 'i': args.append('-i') - return ( - [encodeArgument(arg) for arg in args] - + [self._ffmpeg_filename_argument(file)]) + return [*args, self._ffmpeg_filename_argument(file)] for arg_type, path_opts in (('i', input_path_opts), ('o', output_path_opts)): cmd += itertools.chain.from_iterable( diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index 506914668e..d76746ea30 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -67,6 +67,10 @@ def random_uuidv4(): return str(uuid.uuid4()) +def encodeArgument(s): + return s if isinstance(s, str) else s.decode('ascii') + + def bytes_to_long(s): return int.from_bytes(s, 'big') diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 9dfcdd74b5..01434d907b 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -929,13 +929,6 @@ class Popen(subprocess.Popen): return stdout or default, stderr or default, proc.returncode -def encodeArgument(s): - # Legacy code that uses byte strings - # Uncomment the following line after fixing all post processors - # assert isinstance(s, str), 'Internal error: %r should be of type %r, is %r' % (s, str, type(s)) - return s if isinstance(s, str) else s.decode('ascii') - - _timetuple = collections.namedtuple('Time', ('hours', 'minutes', 'seconds', 'milliseconds')) @@ -2180,7 +2173,7 @@ def _get_exe_version_output(exe, args, ignore_return_code=False): # STDIN should be redirected too. On UNIX-like systems, ffmpeg triggers # SIGTTOU if yt-dlp is run in the background. # See https://github.com/ytdl-org/youtube-dl/issues/955#issuecomment-209789656 - stdout, _, ret = Popen.run([encodeArgument(exe), *args], text=True, + stdout, _, ret = Popen.run([exe, *args], text=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if not ignore_return_code and ret: return None