]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/noz.py
[cleanup] Mark some compat variables for removal (#2173)
[yt-dlp.git] / yt_dlp / extractor / noz.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import (
6 compat_urllib_parse_unquote,
7 )
8 from ..utils import (
9 int_or_none,
10 find_xpath_attr,
11 xpath_text,
12 update_url_query,
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.',
26 'thumbnail': r're:^http://.*\.jpg',
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 = []
52 for qnode in doc.findall('.//article/movie/file/qualities/qual'):
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
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))
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
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))
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 }