From 2aeb06d6dc8c615cf98b7d21ad152bb393726b8a Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Sun, 11 Jan 2015 17:40:45 +0100 Subject: [PATCH] [utils] Improve colon handling (Fixes #4683) --- test/test_utils.py | 4 ++++ youtube_dl/utils.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/test/test_utils.py b/test/test_utils.py index 16e1a1ddf..5e16f30a2 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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: diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 42f0b07ce..deaf71803 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -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: -- 2.22.2