[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / drbonanza.py
blob40dc1416850cc1c7e571676bb52dcf4705347034
1 from .common import InfoExtractor
2 from ..utils import (
3 js_to_json,
4 parse_duration,
5 unescapeHTML,
9 class DRBonanzaIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/[^/]+/\d+/[^/]+/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
11 _TEST = {
12 'url': 'http://www.dr.dk/bonanza/serie/154/matador/40312/matador---0824-komme-fremmede-',
13 'info_dict': {
14 'id': '40312',
15 'display_id': 'matador---0824-komme-fremmede-',
16 'ext': 'mp4',
17 'title': 'MATADOR - 08:24. "Komme fremmede".',
18 'description': 'md5:77b4c1ac4d4c1b9d610ab4395212ff84',
19 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
20 'duration': 4613,
24 def _real_extract(self, url):
25 mobj = self._match_valid_url(url)
26 video_id, display_id = mobj.group('id', 'display_id')
28 webpage = self._download_webpage(url, display_id)
30 info = self._parse_html5_media_entries(
31 url, webpage, display_id, m3u8_id='hls',
32 m3u8_entry_protocol='m3u8_native')[0]
34 asset = self._parse_json(
35 self._search_regex(
36 r'(?s)currentAsset\s*=\s*({.+?})\s*</script', webpage, 'asset'),
37 display_id, transform_source=js_to_json)
39 title = unescapeHTML(asset['AssetTitle']).strip()
41 def extract(field):
42 return self._search_regex(
43 rf'<div[^>]+>\s*<p>{field}:<p>\s*</div>\s*<div[^>]+>\s*<p>([^<]+)</p>',
44 webpage, field, default=None)
46 info.update({
47 'id': asset.get('AssetId') or video_id,
48 'display_id': display_id,
49 'title': title,
50 'description': extract('Programinfo'),
51 'duration': parse_duration(extract('Tid')),
52 'thumbnail': asset.get('AssetImageUrl'),
54 return info