aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Thalhammer <s3544305@student.rmit.edu.au>2016-05-03 10:40:30 +1000
committerAdam Thalhammer <s3544305@student.rmit.edu.au>2016-05-03 10:40:30 +1000
commitc587cbb793a6eda4fc7b1c7b4163e236abec1a00 (patch)
tree580bdd0aad76bfc1fd5142b264697f9560c478df
parent31c4448f6ea8ec4236e0b67af33b53db1a93ef13 (diff)
improved performance by extracting accented chars to top level
-rw-r--r--youtube_dl/utils.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index f74f62268..a5922b2b5 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -89,6 +89,11 @@ KNOWN_EXTENSIONS = (
'wav',
'f4f', 'f4m', 'm3u8', 'smil')
+# needed for sanitizing filenames in restricted mode
+ACCENT_CHARS = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ',
+ itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOUUUUYP', ['ss'],
+ 'aaaaaa', ['ae'], 'ceeeeiiiionoooooouuuuypy')))
+
def preferredencoding():
"""Get preferred encoding.
@@ -365,11 +370,8 @@ def sanitize_filename(s, restricted=False, is_id=False):
Set is_id if this is not an arbitrary string, but an ID that should be kept if possible
"""
def replace_insane(char):
- accents = dict(zip('ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ',
- itertools.chain('AAAAAA', ['AE'], 'CEEEEIIIIDNOOOOOOUUUUYP', ['ss'],
- 'aaaaaa', ['ae'], 'ceeeeiiiionoooooouuuuypy')))
- if restricted and char in accents:
- return accents[char]
+ if restricted and char in ACCENT_CHARS:
+ return ACCENT_CHARS[char]
if char == '?' or ord(char) < 32 or ord(char) == 127:
return ''
elif char == '"':