]>
Commit | Line | Data |
---|---|---|
758a0592 | 1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
758a0592 | 3 | determine_protocol, |
e897bd82 | 4 | int_or_none, |
6aaf96a3 | 5 | join_nonempty, |
1c45b7a8 | 6 | try_get, |
111de002 | 7 | unescapeHTML, |
758a0592 | 8 | ) |
9 | ||
10 | ||
11 | class DailyMailIE(InfoExtractor): | |
71a1db89 | 12 | _VALID_URL = r'https?://(?:www\.)?dailymail\.co\.uk/(?:video/[^/]+/video-|embed/video/)(?P<id>[0-9]+)' |
bfd973ec | 13 | _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?dailymail\.co\.uk/embed/video/\d+\.html)'] |
71a1db89 | 14 | _TESTS = [{ |
111de002 DR |
15 | 'url': 'http://www.dailymail.co.uk/video/tvshowbiz/video-1295863/The-Mountain-appears-sparkling-water-ad-Heavy-Bubbles.html', |
16 | 'md5': 'f6129624562251f628296c3a9ffde124', | |
758a0592 | 17 | 'info_dict': { |
111de002 | 18 | 'id': '1295863', |
758a0592 | 19 | 'ext': 'mp4', |
111de002 DR |
20 | 'title': 'The Mountain appears in sparkling water ad for \'Heavy Bubbles\'', |
21 | 'description': 'md5:a93d74b6da172dd5dc4d973e0b766a84', | |
add96eb9 | 22 | }, |
71a1db89 S |
23 | }, { |
24 | 'url': 'http://www.dailymail.co.uk/embed/video/1295863.html', | |
25 | 'only_matching': True, | |
26 | }] | |
27 | ||
758a0592 | 28 | def _real_extract(self, url): |
29 | video_id = self._match_id(url) | |
30 | webpage = self._download_webpage(url, video_id) | |
31 | video_data = self._parse_json(self._search_regex( | |
32 | r"data-opts='({.+?})'", webpage, 'video data'), video_id) | |
111de002 | 33 | title = unescapeHTML(video_data['title']) |
1c45b7a8 S |
34 | |
35 | sources_url = (try_get( | |
36 | video_data, | |
37 | (lambda x: x['plugins']['sources']['url'], | |
add96eb9 | 38 | lambda x: x['sources']['url']), str) |
39 | or f'http://www.dailymail.co.uk/api/player/{video_id}/video-sources.json') | |
1c45b7a8 S |
40 | |
41 | video_sources = self._download_json(sources_url, video_id) | |
5e733b06 RA |
42 | body = video_sources.get('body') |
43 | if body: | |
44 | video_sources = body | |
758a0592 | 45 | |
46 | formats = [] | |
47 | for rendition in video_sources['renditions']: | |
48 | rendition_url = rendition.get('url') | |
49 | if not rendition_url: | |
50 | continue | |
51 | tbr = int_or_none(rendition.get('encodingRate'), 1000) | |
52 | container = rendition.get('videoContainer') | |
53 | is_hls = container == 'M2TS' | |
54 | protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url}) | |
55 | formats.append({ | |
6aaf96a3 | 56 | 'format_id': join_nonempty('hls' if is_hls else protocol, tbr), |
758a0592 | 57 | 'url': rendition_url, |
58 | 'width': int_or_none(rendition.get('frameWidth')), | |
59 | 'height': int_or_none(rendition.get('frameHeight')), | |
60 | 'tbr': tbr, | |
61 | 'vcodec': rendition.get('videoCodec'), | |
62 | 'container': container, | |
63 | 'protocol': protocol, | |
64 | 'ext': 'mp4' if is_hls else None, | |
65 | }) | |
758a0592 | 66 | |
67 | return { | |
68 | 'id': video_id, | |
69 | 'title': title, | |
111de002 | 70 | 'description': unescapeHTML(video_data.get('descr')), |
758a0592 | 71 | 'thumbnail': video_data.get('poster') or video_data.get('thumbnail'), |
72 | 'formats': formats, | |
73 | } |