aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2012-11-26 23:58:46 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2012-11-26 23:58:46 +0100
commit1c469a9480e9d8bea45950898eb46e07b0c58290 (patch)
tree36e38f86d0fc967a76c991ccd68b22c7a622024c /youtube_dl/utils.py
parent71f36332dd9f17edef7c1f8d3b0bedc737b250e4 (diff)
New optoin --restrict-filenames
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 658fd2686..55f2fe02c 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -194,18 +194,22 @@ def timeconvert(timestr):
if timetuple is not None:
timestamp = email.utils.mktime_tz(timetuple)
return timestamp
-
-def sanitize_filename(s):
- """Sanitizes a string so it could be used as part of a filename."""
+
+def sanitize_filename(s, restricted=False):
+ """Sanitizes a string so it could be used as part of a filename.
+ If restricted is set, use a stricter subset of allowed characters.
+ """
def replace_insane(char):
if char == '?' or ord(char) < 32 or ord(char) == 127:
return ''
elif char == '"':
- return '\''
+ return '' if restricted else 'FOO\''
elif char == ':':
- return ' -'
+ return '_-' if restricted else ' -'
elif char in '\\/|*<>':
return '-'
+ if restricted and (char in '&\'' or char.isspace()):
+ return '_'
return char
result = u''.join(map(replace_insane, s))