aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2015-03-09 03:01:28 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2015-03-09 03:01:28 +0100
commitdcca5819675df1e9d9a1caf00af0f98bb2ce511c (patch)
tree47523d0851107978072ca6dd5c982dafe7abff47 /youtube_dl/utils.py
parentd475b3384cd372d89c35b9b1c26499f1e9cc1915 (diff)
parentdd7831fe94a0fb8270e7fa3699677c7476a5cd83 (diff)
downloadyoutube-dl-dcca5819675df1e9d9a1caf00af0f98bb2ce511c.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: youtube_dl/YoutubeDL.py
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 7426e2a1f..d5597d514 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -252,15 +252,12 @@ def sanitize_open(filename, open_mode):
raise
# In case of error, try to remove win32 forbidden chars
- alt_filename = os.path.join(
- re.sub('[/<>:"\\|\\\\?\\*]', '#', path_part)
- for path_part in os.path.split(filename)
- )
+ alt_filename = sanitize_path(filename)
if alt_filename == filename:
raise
else:
# An exception here should be caught in the caller
- stream = open(encodeFilename(filename), open_mode)
+ stream = open(encodeFilename(alt_filename), open_mode)
return (stream, alt_filename)
@@ -311,6 +308,24 @@ def sanitize_filename(s, restricted=False, is_id=False):
return result
+def sanitize_path(s):
+ """Sanitizes and normalizes path on Windows"""
+ if sys.platform != 'win32':
+ return s
+ drive, _ = os.path.splitdrive(s)
+ unc, _ = os.path.splitunc(s)
+ unc_or_drive = unc or drive
+ norm_path = os.path.normpath(remove_start(s, unc_or_drive)).split(os.path.sep)
+ if unc_or_drive:
+ norm_path.pop(0)
+ sanitized_path = [
+ re.sub('(?:[/<>:"\\|\\\\?\\*]|\.$)', '#', path_part)
+ for path_part in norm_path]
+ if unc_or_drive:
+ sanitized_path.insert(0, unc_or_drive + os.path.sep)
+ return os.path.join(*sanitized_path)
+
+
def orderedSet(iterable):
""" Remove all duplicates from the input iterable """
res = []