[utils] Deprecate encodeArgument (#17621)

Authored by: doe1080
This commit is contained in:
doe1080
2026-12-01 05:08:32 +00:00
committed by GitHub
parent 9370822e3b
commit 7b9efbd9a9
7 changed files with 20 additions and 36 deletions
+1
View File
@@ -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."
+1 -3
View File
@@ -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)
-4
View File
@@ -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:
+3 -4
View File
@@ -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)}')
+10 -17
View File
@@ -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(
+4
View File
@@ -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')
+1 -8
View File
@@ -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