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