[utils] Improve colon handling (Fixes #4683)
authorPhilipp Hagemeister <phihag@phihag.de>
Sun, 11 Jan 2015 16:40:45 +0000 (17:40 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Sun, 11 Jan 2015 16:40:45 +0000 (17:40 +0100)
test/test_utils.py
youtube_dl/utils.py

index 16e1a1ddfdef5be7c0ba941d8793b3c8b88faf08..5e16f30a2d2a08220909b04228d97683be486061 100644 (file)
@@ -79,6 +79,10 @@ class TestUtil(unittest.TestCase):
         tests = '\u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430'
         self.assertEqual(sanitize_filename(tests), tests)
 
+        self.assertEqual(
+            sanitize_filename('New World record at 0:12:34'),
+            'New World record at 0_12_34')
+
         forbidden = '"\0\\/'
         for fc in forbidden:
             for fbc in forbidden:
index 42f0b07ce89bc882fe38319ded77c077238250d2..deaf718030f0f7f16e923dfe92d42a8d6ec1f53a 100644 (file)
@@ -287,6 +287,8 @@ def sanitize_filename(s, restricted=False, is_id=False):
             return '_'
         return char
 
+    # Handle timestamps
+    s = re.sub(r'[0-9]+(?::[0-9]+)+', lambda m: m.group(0).replace(':', '_'), s)
     result = ''.join(map(replace_insane, s))
     if not is_id:
         while '__' in result: