]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/radiode.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / radiode.py
1 from .common import InfoExtractor
2
3
4 class RadioDeIE(InfoExtractor):
5 IE_NAME = 'radio.de'
6 _VALID_URL = r'https?://(?P<id>.+?)\.(?:radio\.(?:de|at|fr|pt|es|pl|it)|rad\.io)'
7 _TEST = {
8 'url': 'http://ndr2.radio.de/',
9 'info_dict': {
10 'id': 'ndr2',
11 'ext': 'mp3',
12 'title': 're:^NDR 2 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
13 'description': 'md5:591c49c702db1a33751625ebfb67f273',
14 'thumbnail': r're:^https?://.*\.png',
15 'is_live': True,
16 },
17 'params': {
18 'skip_download': True,
19 }
20 }
21
22 def _real_extract(self, url):
23 radio_id = self._match_id(url)
24 webpage = self._download_webpage(url, radio_id)
25 jscode = self._search_regex(
26 r"'components/station/stationService':\s*\{\s*'?station'?:\s*(\{.*?\s*\}),\n",
27 webpage, 'broadcast')
28
29 broadcast = self._parse_json(jscode, radio_id)
30 title = broadcast['name']
31 description = broadcast.get('description') or broadcast.get('shortDescription')
32 thumbnail = broadcast.get('picture4Url') or broadcast.get('picture4TransUrl') or broadcast.get('logo100x100')
33
34 formats = [{
35 'url': stream['streamUrl'],
36 'ext': stream['streamContentFormat'].lower(),
37 'acodec': stream['streamContentFormat'],
38 'abr': stream['bitRate'],
39 'asr': stream['sampleRate']
40 } for stream in broadcast['streamUrls']]
41
42 return {
43 'id': radio_id,
44 'title': title,
45 'description': description,
46 'thumbnail': thumbnail,
47 'is_live': True,
48 'formats': formats,
49 }