From c2934512c29e300e7a525c339751c9a8bde65e1b Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 18 Feb 2021 00:39:38 +0530 Subject: Option `--windows-filenames` to force use of windows compatible filenames * Also changed `--trim-file-name` to `--trim-filenames` to be similar to related options Related: https://web.archive.org/web/20210217190806/https://old.reddit.com/r/youtubedl/comments/llc4o5/do_you_guys_also_have_this_error :ci skip dl --- youtube_dlc/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 5aaec4f17..99cbb8a28 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -2125,13 +2125,17 @@ def sanitize_filename(s, restricted=False, is_id=False): return result -def sanitize_path(s): +def sanitize_path(s, force=False): """Sanitizes and normalizes path on Windows""" - if sys.platform != 'win32': + if sys.platform == 'win32': + drive_or_unc, _ = os.path.splitdrive(s) + if sys.version_info < (2, 7) and not drive_or_unc: + drive_or_unc, _ = os.path.splitunc(s) + elif force: + drive_or_unc = '' + else: return s - drive_or_unc, _ = os.path.splitdrive(s) - if sys.version_info < (2, 7) and not drive_or_unc: - drive_or_unc, _ = os.path.splitunc(s) + norm_path = os.path.normpath(remove_start(s, drive_or_unc)).split(os.path.sep) if drive_or_unc: norm_path.pop(0) -- cgit v1.2.3