[radiobremen] Add test for thumbnail
[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 from ..utils import parse_duration
9
10
11 class RadioBremenIE(InfoExtractor):
12     _VALID_URL = r'http?://(?:www\.)?radiobremen\.de/mediathek/(?:index\.html)?\?id=(?P<id>[0-9]+)'
13     IE_NAME = 'radiobremen'
14
15     _TEST = {
16         'url': 'http://www.radiobremen.de/mediathek/index.html?id=114720',
17         'info_dict': {
18             'id': '114720',
19             'ext': 'mp4',
20             'duration': 1685,
21             'width': 512,
22             'title': 'buten un binnen vom 22. Dezember',
23             'thumbnail': 're:https?://.*\.jpg$',
24             '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 +++',
25         },
26     }
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30
31         meta_url = "http://www.radiobremen.de/apps/php/mediathek/metadaten.php?id=%s" % video_id
32         meta_doc = self._download_webpage(meta_url, video_id, 'Downloading metadata')
33         title = self._html_search_regex("<h1.*>(?P<title>.+)</h1>", meta_doc, "title")
34         description = self._html_search_regex("<p>(?P<description>.*)</p>", meta_doc, "description")
35         duration = parse_duration(
36             self._html_search_regex("L&auml;nge:</td>\s+<td>(?P<duration>[0-9]+:[0-9]+)</td>", meta_doc, "duration"))
37
38         page_doc = self._download_webpage(url, video_id, 'Downloading video information')
39         pattern = "ardformatplayerclassic\(\'playerbereich\',\'(?P<width>[0-9]+)\',\'.*\',\'(?P<video_id>[0-9]+)\',\'(?P<secret>[0-9]+)\',\'(?P<thumbnail>.+)\',\'\'\)"
40         mobj = re.search(pattern, page_doc)
41         video_url = (
42             "http://dl-ondemand.radiobremen.de/mediabase/%s/%s_%s_%s.mp4" %
43             (video_id, video_id, mobj.group("secret"), mobj.group('width')))
44
45         formats = [{
46             'url': video_url,
47             'ext': 'mp4',
48             'width': int(mobj.group("width")),
49         }]
50         return {
51             'id': video_id,
52             'title': title,
53             'description': description,
54             'duration': duration,
55             'formats': formats,
56             'thumbnail': mobj.group('thumbnail'),
57         }