[wdr] Add support for WDR sites (Closes #1367)
[youtube-dl] / youtube_dl / extractor / wdr.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     unified_strdate,
8     compat_urlparse,
9     determine_ext,
10 )
11
12
13 class WDRIE(InfoExtractor):
14     _PLAYER_REGEX = '-(?:video|audio)player(?:_size-[LMS])?'
15     _VALID_URL = r'(?P<url>https?://www\d?\.(?:wdr\d?|funkhauseuropa)\.de/)(?P<id>.+?)(?P<player>%s)?\.html' % _PLAYER_REGEX
16
17     _TESTS = [
18         {
19             'url': 'http://www1.wdr.de/mediathek/video/sendungen/servicezeit/videoservicezeit560-videoplayer_size-L.html',
20             'info_dict': {
21                 'id': 'mdb-362427',
22                 'ext': 'flv',
23                 'title': 'Servicezeit',
24                 'description': 'md5:c8f43e5e815eeb54d0b96df2fba906cb',
25                 'upload_date': '20140310',
26             },
27             'params': {
28                 'skip_download': True,
29             },
30         },
31         {
32             'url': 'http://www1.wdr.de/themen/av/videomargaspiegelisttot101-videoplayer.html',
33             'info_dict': {
34                 'id': 'mdb-363194',
35                 'ext': 'flv',
36                 'title': 'Marga Spiegel ist tot',
37                 'upload_date': '20140311',
38             },
39             'params': {
40                 'skip_download': True,
41             },
42         },
43         {
44             'url': 'http://www1.wdr.de/themen/kultur/audioerlebtegeschichtenmargaspiegel100-audioplayer.html',
45             'md5': '83e9e8fefad36f357278759870805898',
46             'info_dict': {
47                 'id': 'mdb-194332',
48                 'ext': 'mp3',
49                 'title': 'Erlebte Geschichten: Marga Spiegel (29.11.2009)',
50                 'upload_date': '20091129',
51             },
52         },
53         {
54             'url': 'http://www.funkhauseuropa.de/av/audiogrenzenlosleckerbaklava101-audioplayer.html',
55             'md5': 'cfff440d4ee64114083ac44676df5d15',
56             'info_dict': {
57                 'id': 'mdb-363068',
58                 'ext': 'mp3',
59                 'title': 'Grenzenlos lecker - Baklava',
60                 'upload_date': '20140311',
61             },
62         },
63     ]
64
65     def _real_extract(self, url):
66         mobj = re.match(self._VALID_URL, url)
67         page_url = mobj.group('url')
68         page_id = mobj.group('id')
69
70         webpage = self._download_webpage(url, page_id)
71
72         if mobj.group('player') is None:
73             entries = [
74                 self.url_result(page_url + href, 'WDR')
75                 for href in re.findall(r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX, webpage)
76             ]
77             return self.playlist_result(entries, page_id)
78
79         flashvars = compat_urlparse.parse_qs(
80             self._html_search_regex(r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
81
82         page_id = flashvars['trackerClipId'][0]
83         video_url = flashvars['dslSrc'][0]
84         title = flashvars['trackerClipTitle'][0]
85         thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
86
87         if 'trackerClipAirTime' in flashvars:
88             upload_date = flashvars['trackerClipAirTime'][0]
89         else:
90             upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
91
92         if upload_date:
93             upload_date = unified_strdate(upload_date)
94
95         if video_url.endswith('.f4m'):
96             video_url += '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
97             ext = 'flv'
98         else:
99             ext = determine_ext(video_url)
100
101         description = self._html_search_meta('Description', webpage, 'description')
102
103         return {
104             'id': page_id,
105             'url': video_url,
106             'ext': ext,
107             'title': title,
108             'description': description,
109             'thumbnail': thumbnail,
110             'upload_date': upload_date,
111         }