]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Check ext with trailing slash against the list of known extensions
authorSergey M․ <dstftw@gmail.com>
Sun, 22 Nov 2015 11:27:13 +0000 (17:27 +0600)
committerSergey M․ <dstftw@gmail.com>
Sun, 22 Nov 2015 11:27:13 +0000 (17:27 +0600)
test/test_utils.py
youtube_dl/utils.py

index 4f0d9e4819e721c9c61665e87c24e6af1fa1fd09..501355c74ad9a745bf8788d0f2e2c603f11b39d8 100644 (file)
@@ -242,6 +242,9 @@ class TestUtil(unittest.TestCase):
     def test_determine_ext(self):
         self.assertEqual(determine_ext('http://example.com/foo/bar.mp4/?download'), 'mp4')
         self.assertEqual(determine_ext('http://example.com/foo/bar/?download', None), None)
+        self.assertEqual(determine_ext('http://example.com/foo/bar.nonext/?download', None), None)
+        self.assertEqual(determine_ext('http://example.com/foo/bar/mp4?download', None), None)
+        self.assertEqual(determine_ext('http://example.com/foo/bar.m3u8//?download'), 'm3u8')
 
     def test_find_xpath_attr(self):
         testxml = '''<root>
index 7dab60bb859b3ad52ea3e52b079e7087d7165099..c0325f054ddfccd2c601acaee3812be5e00a4e6e 100644 (file)
@@ -922,9 +922,24 @@ def unified_strdate(date_str, day_first=True):
 def determine_ext(url, default_ext='unknown_video'):
     if url is None:
         return default_ext
-    guess = url.partition('?')[0].rpartition('.')[2].rstrip('/')
+    guess = url.partition('?')[0].rpartition('.')[2]
     if re.match(r'^[A-Za-z0-9]+$', guess):
         return guess
+    elif guess.rstrip('/') in (
+            'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'aac',
+            'flv', 'f4v', 'f4a', 'f4b',
+            'webm', 'ogg', 'ogv', 'oga', 'ogx', 'spx', 'opus',
+            'mkv', 'mka', 'mk3d',
+            'avi', 'divx',
+            'mov',
+            'asf', 'wmv', 'wma',
+            '3gp', '3g2',
+            'mp3',
+            'flac',
+            'ape',
+            'wav',
+            'f4f', 'f4m', 'm3u8', 'smil'):
+        return guess.rstrip('/')
     else:
         return default_ext