]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Improve mimetype2ext
authorSergey M․ <dstftw@gmail.com>
Fri, 2 Sep 2016 15:57:48 +0000 (22:57 +0700)
committerSergey M․ <dstftw@gmail.com>
Fri, 2 Sep 2016 15:57:48 +0000 (22:57 +0700)
test/test_utils.py
youtube_dl/utils.py

index d16ea7f77cbd9ba0a5807f5857c1c06a43fe9054..405c5d3514b3e735c02ca6ec4722c2d878885f7a 100644 (file)
@@ -39,6 +39,7 @@ from youtube_dl.utils import (
     is_html,
     js_to_json,
     limit_length,
+    mimetype2ext,
     ohdave_rsa_encrypt,
     OnDemandPagedList,
     orderedSet,
@@ -625,6 +626,14 @@ class TestUtil(unittest.TestCase):
             limit_length('foo bar baz asd', 12).startswith('foo bar'))
         self.assertTrue('...' in limit_length('foo bar baz asd', 12))
 
+    def test_mimetype2ext(self):
+        self.assertEqual(mimetype2ext(None), None)
+        self.assertEqual(mimetype2ext('video/x-flv'), 'flv')
+        self.assertEqual(mimetype2ext('application/x-mpegURL'), 'm3u8')
+        self.assertEqual(mimetype2ext('text/vtt'), 'vtt')
+        self.assertEqual(mimetype2ext('text/vtt;charset=utf-8'), 'vtt')
+        self.assertEqual(mimetype2ext('text/html; charset=utf-8'), 'html')
+
     def test_parse_codecs(self):
         self.assertEqual(parse_codecs(''), {})
         self.assertEqual(parse_codecs('avc1.77.30, mp4a.40.2'), {
index 1091f17f32d3e8ba86b1a0c468e1564c8199e3f2..904f23fd7747f5fd1957ab268713513da1526d5c 100644 (file)
@@ -2148,7 +2148,7 @@ def mimetype2ext(mt):
         return ext
 
     _, _, res = mt.rpartition('/')
-    res = res.lower()
+    res = res.split(';')[0].strip().lower()
 
     return {
         '3gpp': '3gp',