From b05b408d10ebf8f4c47c0db1236eb713b6ad7ab6 Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Sat, 13 Jun 2026 07:53:58 +0900 Subject: [PATCH] [utils] Deprecate `make_dir` in favor of `make_parent_dirs` (#16931) Authored by: doe1080 --- pyproject.toml | 1 + yt_dlp/YoutubeDL.py | 9 +++++++-- yt_dlp/postprocessor/movefilesafterdownload.py | 7 +++++-- yt_dlp/utils/_deprecated.py | 12 ++++++++++++ yt_dlp/utils/_utils.py | 13 +++---------- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8128fb31a8..ccbfa74404 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -395,6 +395,7 @@ banned-from = [ "yt_dlp.utils.bytes_to_intlist".msg = "Use `list` instead." "yt_dlp.utils.intlist_to_bytes".msg = "Use `bytes` instead." "yt_dlp.utils.jwt_encode_hs256".msg = "Use `yt_dlp.utils.jwt_encode` instead." +"yt_dlp.utils.make_dir".msg = "Use `yt_dlp.utils.make_parent_dirs` instead." "yt_dlp.utils.decodeArgument".msg = "Do not use" "yt_dlp.utils.decodeFilename".msg = "Do not use" "yt_dlp.utils.encodeFilename".msg = "Do not use" diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 6e7ae2a9ee..08c3404d64 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -139,7 +139,7 @@ from .utils import ( join_nonempty, locked_file, make_archive_id, - make_dir, + make_parent_dirs, number_of_digits, orderedSet, orderedSet_from_options, @@ -2036,7 +2036,12 @@ class YoutubeDL: raise Exception(f'Invalid result type: {result_type}') def _ensure_dir_exists(self, path): - return make_dir(path, self.report_error) + try: + make_parent_dirs(path) + return True + except OSError as e: + self.report_error(f'Unable to create directory: {e}') + return False @staticmethod def _playlist_infodict(ie_result, strict=False, **kwargs): diff --git a/yt_dlp/postprocessor/movefilesafterdownload.py b/yt_dlp/postprocessor/movefilesafterdownload.py index 964ca1f921..8a15491979 100644 --- a/yt_dlp/postprocessor/movefilesafterdownload.py +++ b/yt_dlp/postprocessor/movefilesafterdownload.py @@ -4,7 +4,7 @@ from .common import PostProcessor from ..compat import shutil from ..utils import ( PostProcessingError, - make_dir, + make_parent_dirs, ) @@ -42,7 +42,10 @@ class MoveFilesAfterDownloadPP(PostProcessor): self.report_warning( f'Cannot move file "{oldfile}" out of temporary directory since "{newfile}" already exists. ') continue - make_dir(newfile, PostProcessingError) + try: + make_parent_dirs(newfile) + except OSError as e: + raise PostProcessingError(f'Unable to create directory: {e}') from e self.to_screen(f'Moving file "{oldfile}" to "{newfile}"') shutil.move(oldfile, newfile) # os.rename cannot move between volumes diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index 4797cfef53..9fada27fd8 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -46,4 +46,16 @@ def jwt_encode_hs256(payload_data, key, headers={}): return header_b64 + b'.' + payload_b64 + b'.' + signature_b64 +def make_dir(path, to_screen=None): + from . import make_parent_dirs + + try: + make_parent_dirs(path) + return True + except OSError as e: + if to_screen is not None: + to_screen(f'Unable to create directory: {e}') + return False + + compiled_regex_type = type(re.compile('')) diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 43ee53729e..4cc7a76d17 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -4713,16 +4713,9 @@ def random_uuidv4(): return re.sub(r'[xy]', lambda x: _HEX_TABLE[random.randint(0, 15)], 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx') -def make_dir(path, to_screen=None): - try: - dn = os.path.dirname(path) - if dn: - os.makedirs(dn, exist_ok=True) - return True - except OSError as err: - if callable(to_screen) is not None: - to_screen(f'unable to create directory {err}') - return False +def make_parent_dirs(path): + if dir_name := os.path.dirname(path): + os.makedirs(dir_name, exist_ok=True) def get_executable_path():