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