aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2012-10-28 15:33:59 -0700
committerPhilipp Hagemeister <phihag@phihag.de>2012-10-28 15:33:59 -0700
commitaeca861f227abd282e1ee57b13d1bcba28fe40db (patch)
tree39e1a4b11aeb7290f77103611dba0a6dc718a3f8 /youtube_dl
parentfe4d68e1967cc39cc00a06c3e2e722d51b8e1419 (diff)
parent42cb53fcfa2e8bbc7a96bc1a0ad1e90c1917dccd (diff)
Merge pull request #502 from FiloSottile/new_sanitize_filename
My sanitize_filename proposal
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/utils.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 839da17d0..a64937b4c 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -194,10 +194,20 @@ def timeconvert(timestr):
def sanitize_filename(s):
"""Sanitizes a string so it could be used as part of a filename."""
def replace_insane(char):
- if char in u' .\\/|?*<>:"' or ord(char) < 32:
- return '_'
+ if char == '?' or ord(char) < 32 or ord(char) == 127:
+ return ''
+ elif char == '"':
+ return '\''
+ elif char == ':':
+ return ' -'
+ elif char in '\\/|*<>':
+ return '-'
return char
- return u''.join(map(replace_insane, s)).strip('_')
+
+ result = u''.join(map(replace_insane, s))
+ while '--' in result:
+ result = result.replace('--', '-')
+ return result.strip('-')
def orderedSet(iterable):
""" Remove all duplicates from the input iterable """