]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/wdr.py
[wdr] Add support for more wdrmaus subpages
[yt-dlp.git] / 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 compat_parse_qs,
8 compat_urlparse,
9 determine_ext,
10 unified_strdate,
11 )
12
13
14 class WDRIE(InfoExtractor):
15 _PLAYER_REGEX = '-(?:video|audio)player(?:_size-[LMS])?'
16 _VALID_URL = r'(?P<url>https?://www\d?\.(?:wdr\d?|funkhauseuropa)\.de/)(?P<id>.+?)(?P<player>%s)?\.html' % _PLAYER_REGEX
17
18 _TESTS = [
19 {
20 'url': 'http://www1.wdr.de/mediathek/video/sendungen/servicezeit/videoservicezeit560-videoplayer_size-L.html',
21 'info_dict': {
22 'id': 'mdb-362427',
23 'ext': 'flv',
24 'title': 'Servicezeit',
25 'description': 'md5:c8f43e5e815eeb54d0b96df2fba906cb',
26 'upload_date': '20140310',
27 },
28 'params': {
29 'skip_download': True,
30 },
31 },
32 {
33 'url': 'http://www1.wdr.de/themen/av/videomargaspiegelisttot101-videoplayer.html',
34 'info_dict': {
35 'id': 'mdb-363194',
36 'ext': 'flv',
37 'title': 'Marga Spiegel ist tot',
38 'description': 'md5:2309992a6716c347891c045be50992e4',
39 'upload_date': '20140311',
40 },
41 'params': {
42 'skip_download': True,
43 },
44 },
45 {
46 'url': 'http://www1.wdr.de/themen/kultur/audioerlebtegeschichtenmargaspiegel100-audioplayer.html',
47 'md5': '83e9e8fefad36f357278759870805898',
48 'info_dict': {
49 'id': 'mdb-194332',
50 'ext': 'mp3',
51 'title': 'Erlebte Geschichten: Marga Spiegel (29.11.2009)',
52 'description': 'md5:2309992a6716c347891c045be50992e4',
53 'upload_date': '20091129',
54 },
55 },
56 {
57 'url': 'http://www.funkhauseuropa.de/av/audiogrenzenlosleckerbaklava101-audioplayer.html',
58 'md5': 'cfff440d4ee64114083ac44676df5d15',
59 'info_dict': {
60 'id': 'mdb-363068',
61 'ext': 'mp3',
62 'title': 'Grenzenlos lecker - Baklava',
63 'description': 'md5:7b29e97e10dfb6e265238b32fa35b23a',
64 'upload_date': '20140311',
65 },
66 },
67 ]
68
69 def _real_extract(self, url):
70 mobj = re.match(self._VALID_URL, url)
71 page_url = mobj.group('url')
72 page_id = mobj.group('id')
73
74 webpage = self._download_webpage(url, page_id)
75
76 if mobj.group('player') is None:
77 entries = [
78 self.url_result(page_url + href, 'WDR')
79 for href in re.findall(r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX, webpage)
80 ]
81 return self.playlist_result(entries, page_id)
82
83 flashvars = compat_urlparse.parse_qs(
84 self._html_search_regex(r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
85
86 page_id = flashvars['trackerClipId'][0]
87 video_url = flashvars['dslSrc'][0]
88 title = flashvars['trackerClipTitle'][0]
89 thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
90
91 if 'trackerClipAirTime' in flashvars:
92 upload_date = flashvars['trackerClipAirTime'][0]
93 else:
94 upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
95
96 if upload_date:
97 upload_date = unified_strdate(upload_date)
98
99 if video_url.endswith('.f4m'):
100 video_url += '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
101 ext = 'flv'
102 else:
103 ext = determine_ext(video_url)
104
105 description = self._html_search_meta('Description', webpage, 'description')
106
107 return {
108 'id': page_id,
109 'url': video_url,
110 'ext': ext,
111 'title': title,
112 'description': description,
113 'thumbnail': thumbnail,
114 'upload_date': upload_date,
115 }
116
117
118 class WDRMausIE(InfoExtractor):
119 _VALID_URL = 'http://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
120 IE_DESC = 'Sendung mit der Maus'
121 _TESTS = [{
122 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
123 'info_dict': {
124 'id': 'aktuelle-sendung',
125 'ext': 'mp4',
126 'thumbnail': 're:^http://.+\.jpg',
127 'upload_date': 're:^[0-9]{8}$',
128 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
129 }
130 }, {
131 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
132 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
133 'info_dict': {
134 'id': '40_jahre_maus',
135 'ext': 'mp4',
136 'thumbnail': 're:^http://.+\.jpg',
137 'upload_date': '20131007',
138 'title': '12.03.2011 - 40 Jahre Maus',
139 }
140 }]
141
142 def _real_extract(self, url):
143 mobj = re.match(self._VALID_URL, url)
144 video_id = mobj.group('id')
145
146 webpage = self._download_webpage(url, video_id)
147 param_code = self._html_search_regex(
148 r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
149
150 title_date = self._search_regex(
151 r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
152 webpage, 'air date')
153 title_str = self._html_search_regex(
154 r'<h1>(.*?)</h1>', webpage, 'title')
155 title = '%s - %s' % (title_date, title_str)
156 upload_date = unified_strdate(
157 self._html_search_meta('dc.date', webpage))
158
159 fields = compat_parse_qs(param_code)
160 video_url = fields['firstVideo'][0]
161 thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
162
163 formats = [{
164 'format_id': 'rtmp',
165 'url': video_url,
166 }]
167
168 jscode = self._download_webpage(
169 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
170 video_id, fatal=False,
171 note='Downloading URL translation table',
172 errnote='Could not download URL translation table')
173 if jscode:
174 for m in re.finditer(
175 r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
176 jscode):
177 if video_url.startswith(m.group('stream')):
178 http_url = video_url.replace(
179 m.group('stream'), m.group('dl'))
180 formats.append({
181 'format_id': 'http',
182 'url': http_url,
183 })
184 break
185
186 self._sort_formats(formats)
187
188 return {
189 'id': video_id,
190 'title': title,
191 'formats': formats,
192 'thumbnail': thumbnail,
193 'upload_date': upload_date,
194 }
195
196 # TODO test _1