[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / hrfensehen.py
blob17673d5b8f80fd6699d120d877ee297b126b367b
1 import json
2 import re
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 traverse_obj,
8 try_call,
9 unescapeHTML,
10 unified_timestamp,
14 class HRFernsehenIE(InfoExtractor):
15 IE_NAME = 'hrfernsehen'
16 _VALID_URL = r'^https?://www\.(?:hr-fernsehen|hessenschau)\.de/.*,video-(?P<id>[0-9]{6})\.html'
17 _TESTS = [{
18 'url': 'https://www.hessenschau.de/tv-sendung/hessenschau-vom-26082020,video-130546.html',
19 'md5': '5c4e0ba94677c516a2f65a84110fc536',
20 'info_dict': {
21 'id': '130546',
22 'ext': 'mp4',
23 'description': 'Sturmtief Kirsten fegt über Hessen / Die Corona-Pandemie – eine Chronologie / '
24 'Sterbehilfe: Die Lage in Hessen / Miss Hessen leitet zwei eigene Unternehmen / '
25 'Pop-Up Museum zeigt Schwarze Unterhaltung und Black Music',
26 'subtitles': {'de': [{
27 'url': 'https://hr-a.akamaihd.net/video/as/hessenschau/2020_08/hrLogo_200826200407_L385592_512x288-25p-500kbit.vtt',
28 }]},
29 'timestamp': 1598400000,
30 'upload_date': '20200826',
31 'thumbnail': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9.jpg',
32 'title': 'hessenschau vom 26.08.2020',
33 'duration': 1654,
35 }, {
36 'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html',
37 'only_matching': True,
40 _GEO_COUNTRIES = ['DE']
42 def extract_formats(self, loader_data):
43 stream_formats = []
44 data = loader_data['mediaCollection']['streams'][0]['media']
45 for inner in data[1:]:
46 stream_format = {
47 'format_id': try_call(lambda: f'{inner["maxHResolutionPx"]}p'),
48 'height': inner.get('maxHResolutionPx'),
49 'url': inner['url'],
52 quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit',
53 inner['url'])
54 if quality_information:
55 stream_format['width'] = int_or_none(quality_information.group(1))
56 stream_format['height'] = int_or_none(quality_information.group(2))
57 stream_format['fps'] = int_or_none(quality_information.group(3))
58 stream_format['tbr'] = int_or_none(quality_information.group(4))
60 stream_formats.append(stream_format)
61 return stream_formats
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65 webpage = self._download_webpage(url, video_id)
67 title = self._html_search_meta(
68 ['og:title', 'twitter:title', 'name'], webpage)
69 description = self._html_search_meta(
70 ['description'], webpage)
72 loader_str = unescapeHTML(self._search_regex(r"data-(?:new-)?hr-mediaplayer-loader='([^']*)'", webpage, 'ardloader'))
73 loader_data = json.loads(loader_str)
75 subtitle = traverse_obj(loader_data, ('mediaCollection', 'subTitles', 0, 'sources', 0, 'url'))
77 return {
78 'id': video_id,
79 'title': title,
80 'description': description,
81 'formats': self.extract_formats(loader_data),
82 'subtitles': {'de': [{'url': subtitle}]},
83 'timestamp': unified_timestamp(self._search_regex(
84 r'<time\sdatetime="(\d{4}\W\d{1,2}\W\d{1,2})', webpage, 'datetime', fatal=False)),
85 'duration': int_or_none(traverse_obj(
86 loader_data, ('playerConfig', 'pluginData', 'trackingAti@all', 'richMedia', 'duration'))),
87 'thumbnail': self._search_regex(r'thumbnailUrl\W*([^"]+)', webpage, 'thumbnail', default=None),