]> git.bitcoin.ninja Git - youtube-dl/commitdiff
use mimetype2ext to determine manifest ext in multiple extractors
authorRemita Amine <remitamine@gmail.com>
Wed, 6 Jul 2016 08:11:46 +0000 (09:11 +0100)
committerRemita Amine <remitamine@gmail.com>
Wed, 6 Jul 2016 08:11:46 +0000 (09:11 +0100)
youtube_dl/extractor/amp.py
youtube_dl/extractor/dailymotion.py
youtube_dl/extractor/metacafe.py
youtube_dl/extractor/onionstudios.py
youtube_dl/extractor/sixplay.py
youtube_dl/extractor/threeqsdn.py

index 8545681bead617b2ffedeee04212e032bdc3406e..283736fc5ab720b49faaf3d1101b4f95d26a7cb9 100644 (file)
@@ -5,6 +5,8 @@ from .common import InfoExtractor
 from ..utils import (
     int_or_none,
     parse_iso8601,
+    mimetype2ext,
+    determine_ext,
 )
 
 
@@ -50,21 +52,25 @@ class AMPIE(InfoExtractor):
         if isinstance(media_content, dict):
             media_content = [media_content]
         for media_data in media_content:
-            media = media_data['@attributes']
-            media_type = media['type']
-            if media_type in ('video/f4m', 'application/f4m+xml'):
+            media = media_data.get('@attributes', {})
+            media_url = media.get('url')
+            if not media_url:
+                continue
+            ext = mimetype2ext(media.get('type')) or determne_ext(media_url)
+            if ext == 'f4m':
                 formats.extend(self._extract_f4m_formats(
-                    media['url'] + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
+                    media_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
                     video_id, f4m_id='hds', fatal=False))
-            elif media_type == 'application/x-mpegURL':
+            elif ext == 'm3u8':
                 formats.extend(self._extract_m3u8_formats(
-                    media['url'], video_id, 'mp4', m3u8_id='hls', fatal=False))
+                    media_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
             else:
                 formats.append({
                     'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'),
                     'url': media['url'],
                     'tbr': int_or_none(media.get('bitrate')),
                     'filesize': int_or_none(media.get('fileSize')),
+                    'ext': ext,
                 })
 
         self._sort_formats(formats)
index 2e6226ea0774af2e636cbc4b4a4ca9f1ecb763a3..15bfc59b24d7dc0e43623722486a71bd70bbe2ef 100644 (file)
@@ -16,6 +16,7 @@ from ..utils import (
     sanitized_Request,
     str_to_int,
     unescapeHTML,
+    mimetype2ext,
 )
 
 
@@ -153,18 +154,19 @@ class DailymotionIE(DailymotionBaseInfoExtractor):
                     type_ = media.get('type')
                     if type_ == 'application/vnd.lumberjack.manifest':
                         continue
-                    ext = determine_ext(media_url)
-                    if type_ == 'application/x-mpegURL' or ext == 'm3u8':
+                    ext = mimetype2ext(type_) or determine_ext(media_url)
+                    if ext == 'm3u8':
                         formats.extend(self._extract_m3u8_formats(
                             media_url, video_id, 'mp4', preference=-1,
                             m3u8_id='hls', fatal=False))
-                    elif type_ == 'application/f4m' or ext == 'f4m':
+                    elif ext == 'f4m':
                         formats.extend(self._extract_f4m_formats(
                             media_url, video_id, preference=-1, f4m_id='hds', fatal=False))
                     else:
                         f = {
                             'url': media_url,
                             'format_id': 'http-%s' % quality,
+                            'ext': ext,
                         }
                         m = re.search(r'H264-(?P<width>\d+)x(?P<height>\d+)', media_url)
                         if m:
index acab81863c2f5601b1e1f3d13dbc677e701966a8..e6e7659a1de0ebe86f48a4128192de5d14d6d586 100644 (file)
@@ -234,9 +234,8 @@ class MetacafeIE(InfoExtractor):
                     source_url = source.get('src')
                     if not source_url:
                         continue
-                    mime_type = source.get('type')
-                    ext = mimetype2ext(mime_type) or determine_ext(source_url)
-                    if mime_type == 'application/x-mpegURL' or ext == 'm3u8':
+                    ext = mimetype2ext(source.get('type')) or determine_ext(source_url)
+                    if ext == 'm3u8':
                         video_url.extend(self._extract_m3u8_formats(
                             source_url, video_id, 'mp4',
                             'm3u8_native', m3u8_id='hls', fatal=False))
index 9fd5b212314405faa40e4cb18dd9e259b45fcbab..6fb1a3fcc0bd565677b232adcb883b3649715dde 100644 (file)
@@ -8,6 +8,7 @@ from ..utils import (
     determine_ext,
     int_or_none,
     float_or_none,
+    mimetype2ext,
 )
 
 
@@ -50,9 +51,8 @@ class OnionStudiosIE(InfoExtractor):
             source_url = source.get('url')
             if not source_url:
                 continue
-            content_type = source.get('content_type')
-            ext = determine_ext(source_url)
-            if content_type == 'application/x-mpegURL' or ext == 'm3u8':
+            ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url)
+            if ext == 'm3u8':
                 formats.extend(self._extract_m3u8_formats(
                     source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
             else:
index 759a332d28f92b9be043c2d26ac062f02d2031e0..d3aba58a29a981829d0562ee56d992fc49f2f67c 100644 (file)
@@ -5,6 +5,8 @@ from .common import InfoExtractor
 from ..utils import (
     qualities,
     int_or_none,
+    mimetype2ext,
+    determine_ext,
 )
 
 
@@ -34,19 +36,21 @@ class SixPlayIE(InfoExtractor):
             source_type, source_url = source.get('type'), source.get('src')
             if not source_url or source_type == 'hls/primetime':
                 continue
-            if source_type == 'application/vnd.apple.mpegURL':
+            ext = mimetype2ext(source_type) or determine_ext(source_url)
+            if ext == 'm3u8':
                 formats.extend(self._extract_m3u8_formats(
                     source_url, video_id, 'mp4', 'm3u8_native',
                     m3u8_id='hls', fatal=False))
                 formats.extend(self._extract_f4m_formats(
                     source_url.replace('.m3u8', '.f4m'),
                     video_id, f4m_id='hds', fatal=False))
-            elif source_type == 'video/mp4':
+            elif ext == 'mp4':
                 quality = source.get('quality')
                 formats.append({
                     'url': source_url,
                     'format_id': quality,
                     'quality': quality_key(quality),
+                    'ext': ext,
                 })
         self._sort_formats(formats)
 
index c77a07989a97629a715a3b164b06c60151f71a3e..a0bc12c81fc6ffc07ff723b67aa2ba00e6ae9e67 100644 (file)
@@ -92,12 +92,11 @@ class ThreeQSDNIE(InfoExtractor):
             if not item_url or item_url in urls:
                 return
             urls.add(item_url)
-            type_ = item.get('type')
-            ext = determine_ext(item_url, default_ext=None)
-            if type_ == 'application/dash+xml' or ext == 'mpd':
+            ext = mimetype2ext(item.get('type')) or determine_ext(item_url, default_ext=None)
+            if ext == 'mpd':
                 formats.extend(self._extract_mpd_formats(
                     item_url, video_id, mpd_id='mpd', fatal=False))
-            elif type_ in ('application/vnd.apple.mpegURL', 'application/x-mpegurl') or ext == 'm3u8':
+            elif ext == 'm3u8':
                 formats.extend(self._extract_m3u8_formats(
                     item_url, video_id, 'mp4',
                     entry_protocol='m3u8' if live else 'm3u8_native',
@@ -111,7 +110,7 @@ class ThreeQSDNIE(InfoExtractor):
                 formats.append({
                     'url': item_url,
                     'format_id': item.get('quality'),
-                    'ext': 'mp4' if item_url.startswith('rtsp') else mimetype2ext(type_) or ext,
+                    'ext': 'mp4' if item_url.startswith('rtsp') else ext,
                     'vcodec': 'none' if stream_type == 'audio' else None,
                 })