]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dailymail.py
Update the changelog.
[youtubedl] / youtube_dl / extractor / dailymail.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 determine_protocol,
8 )
9
10
11 class DailyMailIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?dailymail\.co\.uk/video/[^/]+/video-(?P<id>[0-9]+)'
13 _TEST = {
14 'url': 'http://www.dailymail.co.uk/video/sciencetech/video-1288527/Turn-video-impressionist-masterpiece.html',
15 'md5': '2f639d446394f53f3a33658b518b6615',
16 'info_dict': {
17 'id': '1288527',
18 'ext': 'mp4',
19 'title': 'Turn any video into an impressionist masterpiece',
20 'description': 'md5:88ddbcb504367987b2708bb38677c9d2',
21 }
22 }
23
24 def _real_extract(self, url):
25 video_id = self._match_id(url)
26 webpage = self._download_webpage(url, video_id)
27 video_data = self._parse_json(self._search_regex(
28 r"data-opts='({.+?})'", webpage, 'video data'), video_id)
29 title = video_data['title']
30 video_sources = self._download_json(video_data.get(
31 'sources', {}).get('url') or 'http://www.dailymail.co.uk/api/player/%s/video-sources.json' % video_id, video_id)
32
33 formats = []
34 for rendition in video_sources['renditions']:
35 rendition_url = rendition.get('url')
36 if not rendition_url:
37 continue
38 tbr = int_or_none(rendition.get('encodingRate'), 1000)
39 container = rendition.get('videoContainer')
40 is_hls = container == 'M2TS'
41 protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
42 formats.append({
43 'format_id': ('hls' if is_hls else protocol) + ('-%d' % tbr if tbr else ''),
44 'url': rendition_url,
45 'width': int_or_none(rendition.get('frameWidth')),
46 'height': int_or_none(rendition.get('frameHeight')),
47 'tbr': tbr,
48 'vcodec': rendition.get('videoCodec'),
49 'container': container,
50 'protocol': protocol,
51 'ext': 'mp4' if is_hls else None,
52 })
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': title,
58 'description': video_data.get('descr'),
59 'thumbnail': video_data.get('poster') or video_data.get('thumbnail'),
60 'formats': formats,
61 }