]>
Commit | Line | Data |
---|---|---|
a517bb4b PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
e3d17b3c S |
5 | from ..compat import ( |
6 | compat_urllib_parse_unquote, | |
e3d17b3c | 7 | ) |
a517bb4b PH |
8 | from ..utils import ( |
9 | int_or_none, | |
0c9ff240 | 10 | find_xpath_attr, |
a517bb4b | 11 | xpath_text, |
cf6cd073 | 12 | update_url_query, |
a517bb4b PH |
13 | ) |
14 | ||
15 | ||
16 | class NozIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?noz\.de/video/(?P<id>[0-9]+)/' | |
18 | _TESTS = [{ | |
19 | 'url': 'http://www.noz.de/video/25151/32-Deutschland-gewinnt-Badminton-Lnderspiel-in-Melle', | |
20 | 'info_dict': { | |
21 | 'id': '25151', | |
22 | 'ext': 'mp4', | |
23 | 'duration': 215, | |
24 | 'title': '3:2 - Deutschland gewinnt Badminton-Länderspiel in Melle', | |
25 | 'description': 'Vor rund 370 Zuschauern gewinnt die deutsche Badminton-Nationalmannschaft am Donnerstag ein EM-Vorbereitungsspiel gegen Frankreich in Melle. Video Moritz Frankenberg.', | |
ec85ded8 | 26 | 'thumbnail': r're:^http://.*\.jpg', |
a517bb4b PH |
27 | }, |
28 | }] | |
29 | ||
30 | def _real_extract(self, url): | |
31 | video_id = self._match_id(url) | |
32 | webpage = self._download_webpage(url, video_id) | |
33 | description = self._og_search_description(webpage) | |
34 | ||
35 | edge_url = self._html_search_regex( | |
36 | r'<script\s+(?:type="text/javascript"\s+)?src="(.*?/videojs_.*?)"', | |
37 | webpage, 'edge URL') | |
38 | edge_content = self._download_webpage(edge_url, 'meta configuration') | |
39 | ||
40 | config_url_encoded = self._search_regex( | |
41 | r'so\.addVariable\("config_url","[^,]*,(.*?)"', | |
42 | edge_content, 'config URL' | |
43 | ) | |
44 | config_url = compat_urllib_parse_unquote(config_url_encoded) | |
45 | ||
46 | doc = self._download_xml(config_url, 'video configuration') | |
47 | title = xpath_text(doc, './/title') | |
48 | thumbnail = xpath_text(doc, './/article/thumbnail/url') | |
49 | duration = int_or_none(xpath_text( | |
50 | doc, './/article/movie/file/duration')) | |
51 | formats = [] | |
f9934b96 | 52 | for qnode in doc.findall('.//article/movie/file/qualities/qual'): |
0c9ff240 | 53 | http_url_ele = find_xpath_attr( |
54 | qnode, './html_urls/video_url', 'format', 'video/mp4') | |
55 | http_url = http_url_ele.text if http_url_ele is not None else None | |
cf6cd073 | 56 | if http_url: |
57 | formats.append({ | |
58 | 'url': http_url, | |
59 | 'format_name': xpath_text(qnode, './name'), | |
60 | 'format_id': '%s-%s' % ('http', xpath_text(qnode, './id')), | |
61 | 'height': int_or_none(xpath_text(qnode, './height')), | |
62 | 'width': int_or_none(xpath_text(qnode, './width')), | |
63 | 'tbr': int_or_none(xpath_text(qnode, './bitrate'), scale=1000), | |
64 | }) | |
65 | else: | |
66 | f4m_url = xpath_text(qnode, 'url_hd2') | |
67 | if f4m_url: | |
68 | formats.extend(self._extract_f4m_formats( | |
69 | update_url_query(f4m_url, {'hdcore': '3.4.0'}), | |
70 | video_id, f4m_id='hds', fatal=False)) | |
0c9ff240 | 71 | m3u8_url_ele = find_xpath_attr( |
72 | qnode, './html_urls/video_url', | |
73 | 'format', 'application/vnd.apple.mpegurl') | |
74 | m3u8_url = m3u8_url_ele.text if m3u8_url_ele is not None else None | |
cf6cd073 | 75 | if m3u8_url: |
76 | formats.extend(self._extract_m3u8_formats( | |
77 | m3u8_url, video_id, 'mp4', 'm3u8_native', | |
78 | m3u8_id='hls', fatal=False)) | |
a517bb4b PH |
79 | self._sort_formats(formats) |
80 | ||
81 | return { | |
82 | 'id': video_id, | |
83 | 'formats': formats, | |
84 | 'title': title, | |
85 | 'duration': duration, | |
86 | 'description': description, | |
87 | 'thumbnail': thumbnail, | |
88 | } |