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