[wdr] Add description to tests
[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                 'description': 'md5:2309992a6716c347891c045be50992e4',
38                 'upload_date': '20140311',
39             },
40             'params': {
41                 'skip_download': True,
42             },
43         },
44         {
45             'url': 'http://www1.wdr.de/themen/kultur/audioerlebtegeschichtenmargaspiegel100-audioplayer.html',
46             'md5': '83e9e8fefad36f357278759870805898',
47             'info_dict': {
48                 'id': 'mdb-194332',
49                 'ext': 'mp3',
50                 'title': 'Erlebte Geschichten: Marga Spiegel (29.11.2009)',
51                 'description': 'md5:2309992a6716c347891c045be50992e4',
52                 'upload_date': '20091129',
53             },
54         },
55         {
56             'url': 'http://www.funkhauseuropa.de/av/audiogrenzenlosleckerbaklava101-audioplayer.html',
57             'md5': 'cfff440d4ee64114083ac44676df5d15',
58             'info_dict': {
59                 'id': 'mdb-363068',
60                 'ext': 'mp3',
61                 'title': 'Grenzenlos lecker - Baklava',
62                 'description': 'md5:7b29e97e10dfb6e265238b32fa35b23a',
63                 'upload_date': '20140311',
64             },
65         },
66     ]
67
68     def _real_extract(self, url):
69         mobj = re.match(self._VALID_URL, url)
70         page_url = mobj.group('url')
71         page_id = mobj.group('id')
72
73         webpage = self._download_webpage(url, page_id)
74
75         if mobj.group('player') is None:
76             entries = [
77                 self.url_result(page_url + href, 'WDR')
78                 for href in re.findall(r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX, webpage)
79             ]
80             return self.playlist_result(entries, page_id)
81
82         flashvars = compat_urlparse.parse_qs(
83             self._html_search_regex(r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
84
85         page_id = flashvars['trackerClipId'][0]
86         video_url = flashvars['dslSrc'][0]
87         title = flashvars['trackerClipTitle'][0]
88         thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
89
90         if 'trackerClipAirTime' in flashvars:
91             upload_date = flashvars['trackerClipAirTime'][0]
92         else:
93             upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
94
95         if upload_date:
96             upload_date = unified_strdate(upload_date)
97
98         if video_url.endswith('.f4m'):
99             video_url += '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
100             ext = 'flv'
101         else:
102             ext = determine_ext(video_url)
103
104         description = self._html_search_meta('Description', webpage, 'description')
105
106         return {
107             'id': page_id,
108             'url': video_url,
109             'ext': ext,
110             'title': title,
111             'description': description,
112             'thumbnail': thumbnail,
113             'upload_date': upload_date,
114         }