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