]>
Commit | Line | Data |
---|---|---|
43c53a17 RA |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | js_to_json, | |
4 | mimetype2ext, | |
5 | determine_ext, | |
6 | update_url_query, | |
7 | get_element_by_attribute, | |
8 | int_or_none, | |
9 | ) | |
10 | ||
11 | ||
12 | class NobelPrizeIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://(?:www\.)?nobelprize\.org/mediaplayer.*?\bid=(?P<id>\d+)' | |
14 | _TEST = { | |
15 | 'url': 'http://www.nobelprize.org/mediaplayer/?id=2636', | |
16 | 'md5': '04c81e5714bb36cc4e2232fee1d8157f', | |
17 | 'info_dict': { | |
18 | 'id': '2636', | |
19 | 'ext': 'mp4', | |
20 | 'title': 'Announcement of the 2016 Nobel Prize in Physics', | |
21 | 'description': 'md5:05beba57f4f5a4bbd4cf2ef28fcff739', | |
22 | } | |
23 | } | |
24 | ||
25 | def _real_extract(self, url): | |
26 | video_id = self._match_id(url) | |
27 | webpage = self._download_webpage(url, video_id) | |
28 | media = self._parse_json(self._search_regex( | |
29 | r'(?s)var\s*config\s*=\s*({.+?});', webpage, | |
30 | 'config'), video_id, js_to_json)['media'] | |
31 | title = media['title'] | |
32 | ||
33 | formats = [] | |
34 | for source in media.get('source', []): | |
35 | source_src = source.get('src') | |
36 | if not source_src: | |
37 | continue | |
38 | ext = mimetype2ext(source.get('type')) or determine_ext(source_src) | |
39 | if ext == 'm3u8': | |
40 | formats.extend(self._extract_m3u8_formats( | |
41 | source_src, video_id, 'mp4', 'm3u8_native', | |
42 | m3u8_id='hls', fatal=False)) | |
43 | elif ext == 'f4m': | |
44 | formats.extend(self._extract_f4m_formats( | |
45 | update_url_query(source_src, {'hdcore': '3.7.0'}), | |
46 | video_id, f4m_id='hds', fatal=False)) | |
47 | else: | |
48 | formats.append({ | |
49 | 'url': source_src, | |
50 | }) | |
51 | self._sort_formats(formats) | |
52 | ||
53 | return { | |
54 | 'id': video_id, | |
55 | 'title': title, | |
56 | 'description': get_element_by_attribute('itemprop', 'description', webpage), | |
57 | 'duration': int_or_none(media.get('duration')), | |
58 | 'formats': formats, | |
59 | } |