Merge remote-tracking branch 'ckrooss/master'
[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             'width': 512,
20             'title': 'buten un binnen vom 22. Dezember',
21             '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 +++',
22         },
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         video_id = mobj.group('video_id')
28
29         meta_url = "http://www.radiobremen.de/apps/php/mediathek/metadaten.php?id=%s" % video_id
30         meta_doc = self._download_webpage(meta_url, video_id, 'Downloading metadata')
31         title = self._html_search_regex("<h1.*>(?P<title>.+)</h1>", meta_doc, "title")
32         description = self._html_search_regex("<p>(?P<description>.*)</p>", meta_doc, "description")
33         duration = self._html_search_regex("L&auml;nge:</td>\s+<td>(?P<duration>[0-9]+:[0-9]+)</td>", meta_doc, "duration")
34
35         page_doc = self._download_webpage(url, video_id, 'Downloading video information')
36         pattern = "ardformatplayerclassic\(\'playerbereich\',\'(?P<width>[0-9]+)\',\'.*\',\'(?P<video_id>[0-9]+)\',\'(?P<secret>[0-9]+)\',\'(?P<thumbnail>.+)\',\'\'\)"
37         mobj = re.search(pattern, page_doc)
38         width, video_id, secret, thumbnail = int(mobj.group("width")), mobj.group("video_id"), mobj.group("secret"), mobj.group("thumbnail")
39         video_url = "http://dl-ondemand.radiobremen.de/mediabase/{:}/{:}_{:}_{:}.mp4".format(video_id, video_id, secret, width)
40
41         return {
42             'id': video_id,
43             'title': title,
44             'description': description,
45             'duration': duration,
46             'formats': [
47                 {'url': video_url,
48                  'ext': 'mp4',
49                  'width': width,
50                  'protocol': 'http'
51                  }
52             ],
53             'thumbnail': thumbnail,
54         }