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