Add support for Radio Bremen
[youtube-dl] / youtube_dl / extractor / radiobremen.py
1 # -*- coding: utf-8 -*-
2
3 from __future__ import unicode_literals
4
5 import re
6
7 from .common import InfoExtractor
8
9
10 class RadioBremenIE(InfoExtractor):
11     _VALID_URL = r'http?://(?:www\.)?radiobremen\.de/mediathek/(index\.html)?\?id=(?P<video_id>[0-9]+)'
12     IE_NAME = 'radiobremen'
13
14     _TEST = {
15         'url': 'http://www.radiobremen.de/mediathek/index.html?id=114720',
16         'info_dict': {
17             'id': '114720',
18             'ext': 'mp4',
19             'height': 288,
20             'width': 512,
21             'title': 'buten un binnen vom 22. Dezember',
22             'description': 'Unter anderem mit diesen Themen: 45 Flüchtlinge sind in Worpswede angekommen +++ Freies Internet für alle: Bremer arbeiten an einem flächendeckenden W-Lan-Netzwerk +++ Aktivisten kämpfen für das Unibad +++ So war das Wetter 2014 +++',
23         },
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('video_id')
29
30         meta_url = "http://www.radiobremen.de/apps/php/mediathek/metadaten.php?id=%s" % video_id
31         meta_doc = self._download_webpage(meta_url, video_id, 'Downloading metadata')
32         title = self._html_search_regex("<h1.*>(?P<title>.+)</h1>", meta_doc, "title")
33         description = self._html_search_regex("<p>(?P<description>.*)</p>", meta_doc, "description")
34         duration = self._html_search_regex("L&auml;nge:</td>\s+<td>(?P<duration>[0-9]+:[0-9]+)</td>", meta_doc, "duration")
35
36         page_doc = self._download_webpage(url, video_id, 'Downloading video information')
37         pattern = "ardformatplayerclassic\(\'playerbereich\',\'(?P<width>[0-9]+)\',\'.*\',\'(?P<video_id>[0-9]+)\',\'(?P<secret>[0-9]+)\',\'(?P<thumbnail>.+)\',\'\'\)"
38         mobj = re.search(pattern, page_doc)
39         width, video_id, secret, thumbnail = int(mobj.group("width")), mobj.group("video_id"), mobj.group("secret"), mobj.group("thumbnail")
40         video_url = "http://dl-ondemand.radiobremen.de/mediabase/{:}/{:}_{:}_{:}.mp4".format(video_id, video_id, secret, width)
41
42         return {
43             'id': video_id,
44             'title': title,
45             'description': description,
46             'duration': duration,
47             'formats': [
48                 {'url': video_url,
49                  'ext': 'mp4',
50                  'width': width,
51                  'protocol': 'http'
52                  }
53             ],
54             'thumbnail': thumbnail,
55         }