]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/utils.py
remove accidental remnants
[youtube-dl] / youtube_dl / utils.py
index 658fd2686b8534e834c34872883fd26d3d820cde..1f60d34ae23ad2f36b54072e0b133d3cd2a22149 100644 (file)
@@ -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 '\''
                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))