youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

commit ab49d7a9fae08763de549f85ba138b22f9122a99
parent b4173f1551c47f64745cb91451c46891e2aaac16
Author: Remita Amine <remitamine@gmail.com>
Date:   Wed,  6 Jul 2016 09:11:46 +0100

use mimetype2ext to determine manifest ext in multiple extractors

Diffstat:
Myoutube_dl/extractor/amp.py | 18++++++++++++------
Myoutube_dl/extractor/dailymotion.py | 8+++++---
Myoutube_dl/extractor/metacafe.py | 5++---
Myoutube_dl/extractor/onionstudios.py | 6+++---
Myoutube_dl/extractor/sixplay.py | 8++++++--
Myoutube_dl/extractor/threeqsdn.py | 9++++-----
6 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/youtube_dl/extractor/amp.py b/youtube_dl/extractor/amp.py @@ -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) diff --git a/youtube_dl/extractor/dailymotion.py b/youtube_dl/extractor/dailymotion.py @@ -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: diff --git a/youtube_dl/extractor/metacafe.py b/youtube_dl/extractor/metacafe.py @@ -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)) diff --git a/youtube_dl/extractor/onionstudios.py b/youtube_dl/extractor/onionstudios.py @@ -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: diff --git a/youtube_dl/extractor/sixplay.py b/youtube_dl/extractor/sixplay.py @@ -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) diff --git a/youtube_dl/extractor/threeqsdn.py b/youtube_dl/extractor/threeqsdn.py @@ -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, })