From 431b60a7885e3f471f4983bcaa8e75bd8989d8be Mon Sep 17 00:00:00 2001 From: gfabiano Date: Fri, 16 Jun 2017 01:46:58 +0200 Subject: [PATCH] [mirror] Add new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/mirror.py | 73 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 youtube_dl/extractor/mirror.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 7e45232dd..cd9cf0149 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -565,6 +565,7 @@ from .minhateca import MinhatecaIE from .ministrygrid import MinistryGridIE from .minoto import MinotoIE from .miomio import MioMioIE +from .mirror import MirrorIE from .mit import TechTVMITIE, MITIE, OCWMITIE from .mitele import MiTeleIE from .mixcloud import ( diff --git a/youtube_dl/extractor/mirror.py b/youtube_dl/extractor/mirror.py new file mode 100644 index 000000000..e8512a7c2 --- /dev/null +++ b/youtube_dl/extractor/mirror.py @@ -0,0 +1,73 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + +from ..utils import ( + ExtractorError, +) + +import re + + +class MirrorIE(InfoExtractor): + _VALID_URL = (r'https?://(?:www\.)?(?:mirror\.co\.uk)/.*') + + _TESTS = [{ + 'url': 'http://www.mirror.co.uk/news/uk-news/grenfell-tower-block-fire-london-10619120?service=responsive', + 'md5': 'e8c52bcdf5180884b4e4d3159de3a40b', + 'info_dict': { + 'id': '5470567455001', + 'ext': 'mp4', + 'title': 'Blaze at Grenfell Tower continues 11 hours on', + 'timestamp': 1497433370, + 'uploader_id': '4221396001', + 'upload_date': '20170614' + } + }, { + 'url': 'http://www.mirror.co.uk/tv/tv-news/tim-brown-grenfell-fire-us-10627790', + 'md5': 'cd8e2ee6a57b043d9612321d8b4d07be', + 'info_dict': { + 'id': '5472207456001', + 'ext': 'mp4', + 'title': 'Structural engineer who warned of cladding fire dangers explains Grenfell Tower fire', + 'timestamp': 1497527486, + 'uploader_id': '4221396001', + 'upload_date': '20170615', + 'description': 'Structural engineer who warned of cladding fire dangers explains what made Grenfell Tower a death trap' + } + }] + + def _real_extract(self, url): + webpage = self._download_webpage(url, '', 'Downloading webpage') + + mobj = re.search(r'.+?brightcove\.com/\d+/(?P[^/]+)/\d+/\d+/\2_\d+_(?P[^.]+)\.mp4)', webpage) + + if mobj is None: + raise ExtractorError('Video does not exist', expected=True) + + account_id = mobj.group('account_id') + video_id = mobj.group('video_id') + video_url = mobj.group('video_url') + + player_id = self._search_regex( + r'(&l?s?quot?;)+playerId\1+:\1+(?P[a-zA-Z0-9]+)\1+,', + webpage, 'player id', group='player_id' + ) + + player_url = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s' % (account_id, player_id, video_id) + info = None + try: + info = self.url_result( + player_url, 'BrightcoveNew', video_id + ) + except: + info = { + 'id': video_id, + 'title': self._search_regex( + r'(&l?s?quot?;)videoTitle\1+:\1(?P[^&]+)\1[^}]+%s' % video_id, + webpage, 'video title', group='video_title' + ), + 'url': video_url + } + return info