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