aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-02-18 00:39:38 +0530
committerpukkandan <pukkandan@gmail.com>2021-02-18 01:06:40 +0530
commitc2934512c29e300e7a525c339751c9a8bde65e1b (patch)
tree2613aaee9435252418f2233ee4846ac04accd284 /youtube_dlc/utils.py
parent55e36f035cff0b7b75118930bb7bd03a75ffd534 (diff)
downloadhypervideo-pre-c2934512c29e300e7a525c339751c9a8bde65e1b.tar.lz
hypervideo-pre-c2934512c29e300e7a525c339751c9a8bde65e1b.tar.xz
hypervideo-pre-c2934512c29e300e7a525c339751c9a8bde65e1b.zip
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
Diffstat (limited to 'youtube_dlc/utils.py')
-rw-r--r--youtube_dlc/utils.py14
1 files changed, 9 insertions, 5 deletions
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)