Browse Source

Minor filename encoding improvement in a common case

rtmp_test
Philipp Hagemeister 12 years ago
parent
commit
46cbda0be4
2 changed files with 10 additions and 0 deletions
  1. +7
    -0
      test/test_utils.py
  2. +3
    -0
      youtube_dl/utils.py

+ 7
- 0
test/test_utils.py View File

@ -61,6 +61,13 @@ class TestUtil(unittest.TestCase):
for fbc in forbidden: for fbc in forbidden:
self.assertTrue(fbc not in sanitize_filename(fc, restricted=True)) 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): 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([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7])
self.assertEqual(orderedSet([]), []) self.assertEqual(orderedSet([]), [])


+ 3
- 0
youtube_dl/utils.py View File

@ -218,6 +218,9 @@ def sanitize_filename(s, restricted=False):
while '__' in result: while '__' in result:
result = result.replace('__', '_') result = result.replace('__', '_')
result = result.strip('_') result = result.strip('_')
# Common case of "Foreign band name - English song title"
if restricted and result.startswith('-_'):
result = result[2:]
if not result: if not result:
result = '_' result = '_'
return result return result


Loading…
Cancel
Save