From 46cbda0be4bed00122a5cf43e640808e6c32222d Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Tue, 27 Nov 2012 15:07:10 +0100 Subject: [PATCH] Minor filename encoding improvement in a common case --- test/test_utils.py | 7 +++++++ youtube_dl/utils.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/test/test_utils.py b/test/test_utils.py index 4208ee6532..e806a10c53 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -61,6 +61,13 @@ def test_sanitize_filename_restricted(self): for fbc in forbidden: self.assertTrue(fbc not in sanitize_filename(fc, restricted=True)) + # Handle a common case more neatly + self.assertEqual(sanitize_filename(u'大声带 - Song', restricted=True), u'Song') + self.assertEqual(sanitize_filename(u'总统: Speech', restricted=True), u'Speech') + # .. but make sure the file name is never empty + self.assertTrue(sanitize_filename(u'-', restricted=True) != u'') + self.assertTrue(sanitize_filename(u':', restricted=True) != u'') + def test_ordered_set(self): self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7]) self.assertEqual(orderedSet([]), []) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3339f56ec1..4ace22c2fc 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -218,6 +218,9 @@ def replace_insane(char): while '__' in result: result = result.replace('__', '_') result = result.strip('_') + # Common case of "Foreign band name - English song title" + if restricted and result.startswith('-_'): + result = result[2:] if not result: result = '_' return result