]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wdr.py
Tidy the changelog.
[youtubedl] / youtube_dl / extractor / wdr.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import itertools
5 import re
6
7 from .common import InfoExtractor
8 from ..compat import (
9 compat_parse_qs,
10 compat_urlparse,
11 )
12 from ..utils import (
13 determine_ext,
14 unified_strdate,
15 )
16
17
18 class WDRIE(InfoExtractor):
19 _PLAYER_REGEX = '-(?:video|audio)player(?:_size-[LMS])?'
20 _VALID_URL = r'(?P<url>https?://www\d?\.(?:wdr\d?|funkhauseuropa)\.de/)(?P<id>.+?)(?P<player>%s)?\.html' % _PLAYER_REGEX
21
22 _TESTS = [
23 {
24 'url': 'http://www1.wdr.de/mediathek/video/sendungen/servicezeit/videoservicezeit560-videoplayer_size-L.html',
25 'info_dict': {
26 'id': 'mdb-362427',
27 'ext': 'flv',
28 'title': 'Servicezeit',
29 'description': 'md5:c8f43e5e815eeb54d0b96df2fba906cb',
30 'upload_date': '20140310',
31 },
32 'params': {
33 'skip_download': True,
34 },
35 },
36 {
37 'url': 'http://www1.wdr.de/themen/av/videomargaspiegelisttot101-videoplayer.html',
38 'info_dict': {
39 'id': 'mdb-363194',
40 'ext': 'flv',
41 'title': 'Marga Spiegel ist tot',
42 'description': 'md5:2309992a6716c347891c045be50992e4',
43 'upload_date': '20140311',
44 },
45 'params': {
46 'skip_download': True,
47 },
48 },
49 {
50 'url': 'http://www1.wdr.de/themen/kultur/audioerlebtegeschichtenmargaspiegel100-audioplayer.html',
51 'md5': '83e9e8fefad36f357278759870805898',
52 'info_dict': {
53 'id': 'mdb-194332',
54 'ext': 'mp3',
55 'title': 'Erlebte Geschichten: Marga Spiegel (29.11.2009)',
56 'description': 'md5:2309992a6716c347891c045be50992e4',
57 'upload_date': '20091129',
58 },
59 },
60 {
61 'url': 'http://www.funkhauseuropa.de/av/audioflaviacoelhoamaramar100-audioplayer.html',
62 'md5': '99a1443ff29af19f6c52cf6f4dc1f4aa',
63 'info_dict': {
64 'id': 'mdb-478135',
65 'ext': 'mp3',
66 'title': 'Flavia Coelho: Amar é Amar',
67 'description': 'md5:7b29e97e10dfb6e265238b32fa35b23a',
68 'upload_date': '20140717',
69 },
70 },
71 {
72 'url': 'http://www1.wdr.de/mediathek/video/sendungen/quarks_und_co/filterseite-quarks-und-co100.html',
73 'playlist_mincount': 146,
74 'info_dict': {
75 'id': 'mediathek/video/sendungen/quarks_und_co/filterseite-quarks-und-co100',
76 }
77 }
78 ]
79
80 def _real_extract(self, url):
81 mobj = re.match(self._VALID_URL, url)
82 page_url = mobj.group('url')
83 page_id = mobj.group('id')
84
85 webpage = self._download_webpage(url, page_id)
86
87 if mobj.group('player') is None:
88 entries = [
89 self.url_result(page_url + href, 'WDR')
90 for href in re.findall(r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX, webpage)
91 ]
92
93 if entries: # Playlist page
94 return self.playlist_result(entries, page_id)
95
96 # Overview page
97 entries = []
98 for page_num in itertools.count(2):
99 hrefs = re.findall(
100 r'<li class="mediathekvideo"\s*>\s*<img[^>]*>\s*<a href="(/mediathek/video/[^"]+)"',
101 webpage)
102 entries.extend(
103 self.url_result(page_url + href, 'WDR')
104 for href in hrefs)
105 next_url_m = re.search(
106 r'<li class="nextToLast">\s*<a href="([^"]+)"', webpage)
107 if not next_url_m:
108 break
109 next_url = page_url + next_url_m.group(1)
110 webpage = self._download_webpage(
111 next_url, page_id,
112 note='Downloading playlist page %d' % page_num)
113 return self.playlist_result(entries, page_id)
114
115 flashvars = compat_parse_qs(
116 self._html_search_regex(r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
117
118 page_id = flashvars['trackerClipId'][0]
119 video_url = flashvars['dslSrc'][0]
120 title = flashvars['trackerClipTitle'][0]
121 thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
122
123 if 'trackerClipAirTime' in flashvars:
124 upload_date = flashvars['trackerClipAirTime'][0]
125 else:
126 upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
127
128 if upload_date:
129 upload_date = unified_strdate(upload_date)
130
131 if video_url.endswith('.f4m'):
132 video_url += '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
133 ext = 'flv'
134 else:
135 ext = determine_ext(video_url)
136
137 description = self._html_search_meta('Description', webpage, 'description')
138
139 return {
140 'id': page_id,
141 'url': video_url,
142 'ext': ext,
143 'title': title,
144 'description': description,
145 'thumbnail': thumbnail,
146 'upload_date': upload_date,
147 }
148
149
150 class WDRMobileIE(InfoExtractor):
151 _VALID_URL = r'''(?x)
152 https?://mobile-ondemand\.wdr\.de/
153 .*?/fsk(?P<age_limit>[0-9]+)
154 /[0-9]+/[0-9]+/
155 (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
156 IE_NAME = 'wdr:mobile'
157 _TEST = {
158 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
159 'info_dict': {
160 'title': '4283021',
161 'id': '421735',
162 'ext': 'mp4',
163 'age_limit': 0,
164 },
165 'skip': 'Problems with loading data.'
166 }
167
168 def _real_extract(self, url):
169 mobj = re.match(self._VALID_URL, url)
170 return {
171 'id': mobj.group('id'),
172 'title': mobj.group('title'),
173 'age_limit': int(mobj.group('age_limit')),
174 'url': url,
175 'http_headers': {
176 'User-Agent': 'mobile',
177 },
178 }
179
180
181 class WDRMausIE(InfoExtractor):
182 _VALID_URL = 'http://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
183 IE_DESC = 'Sendung mit der Maus'
184 _TESTS = [{
185 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
186 'info_dict': {
187 'id': 'aktuelle-sendung',
188 'ext': 'mp4',
189 'thumbnail': 're:^http://.+\.jpg',
190 'upload_date': 're:^[0-9]{8}$',
191 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
192 }
193 }, {
194 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
195 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
196 'info_dict': {
197 'id': '40_jahre_maus',
198 'ext': 'mp4',
199 'thumbnail': 're:^http://.+\.jpg',
200 'upload_date': '20131007',
201 'title': '12.03.2011 - 40 Jahre Maus',
202 }
203 }]
204
205 def _real_extract(self, url):
206 video_id = self._match_id(url)
207
208 webpage = self._download_webpage(url, video_id)
209 param_code = self._html_search_regex(
210 r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
211
212 title_date = self._search_regex(
213 r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
214 webpage, 'air date')
215 title_str = self._html_search_regex(
216 r'<h1>(.*?)</h1>', webpage, 'title')
217 title = '%s - %s' % (title_date, title_str)
218 upload_date = unified_strdate(
219 self._html_search_meta('dc.date', webpage))
220
221 fields = compat_parse_qs(param_code)
222 video_url = fields['firstVideo'][0]
223 thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
224
225 formats = [{
226 'format_id': 'rtmp',
227 'url': video_url,
228 }]
229
230 jscode = self._download_webpage(
231 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
232 video_id, fatal=False,
233 note='Downloading URL translation table',
234 errnote='Could not download URL translation table')
235 if jscode:
236 for m in re.finditer(
237 r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
238 jscode):
239 if video_url.startswith(m.group('stream')):
240 http_url = video_url.replace(
241 m.group('stream'), m.group('dl'))
242 formats.append({
243 'format_id': 'http',
244 'url': http_url,
245 })
246 break
247
248 self._sort_formats(formats)
249
250 return {
251 'id': video_id,
252 'title': title,
253 'formats': formats,
254 'thumbnail': thumbnail,
255 'upload_date': upload_date,
256 }