]>
Commit | Line | Data |
---|---|---|
f9b85496 PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
d5822b96 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
3741302a | 7 | from .generic import GenericIE |
d5822b96 | 8 | from ..utils import ( |
f9b85496 | 9 | determine_ext, |
d5822b96 | 10 | ExtractorError, |
29546b34 | 11 | qualities, |
6d3d3fc0 PH |
12 | int_or_none, |
13 | parse_duration, | |
14 | unified_strdate, | |
bf0ff932 | 15 | xpath_text, |
d5822b96 | 16 | ) |
f7854627 | 17 | from ..compat import compat_etree_fromstring |
d5822b96 | 18 | |
f9b85496 | 19 | |
6d3d3fc0 PH |
20 | class ARDMediathekIE(InfoExtractor): |
21 | IE_NAME = 'ARD:mediathek' | |
29546b34 | 22 | _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?' |
f9b85496 | 23 | |
29546b34 | 24 | _TESTS = [{ |
769efa16 | 25 | 'url': 'http://www.ardmediathek.de/tv/Dokumentation-und-Reportage/Ich-liebe-das-Leben-trotzdem/rbb-Fernsehen/Video?documentId=29582122&bcastId=3822114', |
29546b34 | 26 | 'info_dict': { |
769efa16 | 27 | 'id': '29582122', |
29546b34 | 28 | 'ext': 'mp4', |
769efa16 S |
29 | 'title': 'Ich liebe das Leben trotzdem', |
30 | 'description': 'md5:45e4c225c72b27993314b31a84a5261c', | |
31 | 'duration': 4557, | |
32 | }, | |
33 | 'params': { | |
34 | # m3u8 download | |
35 | 'skip_download': True, | |
29546b34 | 36 | }, |
d719c6a5 S |
37 | }, { |
38 | 'url': 'http://www.ardmediathek.de/tv/Tatort/Tatort-Scheinwelten-H%C3%B6rfassung-Video/Das-Erste/Video?documentId=29522730&bcastId=602916', | |
39 | 'md5': 'f4d98b10759ac06c0072bbcd1f0b9e3e', | |
40 | 'info_dict': { | |
41 | 'id': '29522730', | |
42 | 'ext': 'mp4', | |
43 | 'title': 'Tatort: Scheinwelten - Hörfassung (Video tgl. ab 20 Uhr)', | |
44 | 'description': 'md5:196392e79876d0ac94c94e8cdb2875f1', | |
45 | 'duration': 5252, | |
46 | }, | |
86b4e98a S |
47 | }, { |
48 | # audio | |
49 | 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086', | |
50 | 'md5': '219d94d8980b4f538c7fcb0865eb7f2c', | |
51 | 'info_dict': { | |
52 | 'id': '28488308', | |
53 | 'ext': 'mp3', | |
54 | 'title': 'Tod eines Fußballers', | |
55 | 'description': 'md5:f6e39f3461f0e1f54bfa48c8875c86ef', | |
56 | 'duration': 3240, | |
57 | }, | |
769efa16 S |
58 | }, { |
59 | 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht', | |
60 | 'only_matching': True, | |
29546b34 | 61 | }] |
d5822b96 | 62 | |
e37c92ec S |
63 | def _extract_media_info(self, media_info_url, webpage, video_id): |
64 | media_info = self._download_json( | |
65 | media_info_url, video_id, 'Downloading media JSON') | |
66 | ||
67 | formats = self._extract_formats(media_info, video_id) | |
68 | ||
69 | if not formats: | |
70 | if '"fsk"' in webpage: | |
71 | raise ExtractorError( | |
72 | 'This video is only available after 20:00', expected=True) | |
73 | elif media_info.get('_geoblocked'): | |
74 | raise ExtractorError('This video is not available due to geo restriction', expected=True) | |
75 | ||
76 | self._sort_formats(formats) | |
77 | ||
78 | duration = int_or_none(media_info.get('_duration')) | |
79 | thumbnail = media_info.get('_previewImage') | |
80 | ||
81 | subtitles = {} | |
82 | subtitle_url = media_info.get('_subtitleUrl') | |
83 | if subtitle_url: | |
84 | subtitles['de'] = [{ | |
ffa2cecf | 85 | 'ext': 'ttml', |
e37c92ec S |
86 | 'url': subtitle_url, |
87 | }] | |
88 | ||
89 | return { | |
90 | 'id': video_id, | |
91 | 'duration': duration, | |
92 | 'thumbnail': thumbnail, | |
93 | 'formats': formats, | |
94 | 'subtitles': subtitles, | |
95 | } | |
96 | ||
97 | def _extract_formats(self, media_info, video_id): | |
98 | type_ = media_info.get('_type') | |
99 | media_array = media_info.get('_mediaArray', []) | |
100 | formats = [] | |
101 | for num, media in enumerate(media_array): | |
102 | for stream in media.get('_mediaStreamArray', []): | |
103 | stream_urls = stream.get('_stream') | |
104 | if not stream_urls: | |
105 | continue | |
106 | if not isinstance(stream_urls, list): | |
107 | stream_urls = [stream_urls] | |
108 | quality = stream.get('_quality') | |
109 | server = stream.get('_server') | |
110 | for stream_url in stream_urls: | |
111 | ext = determine_ext(stream_url) | |
1fc0b47f | 112 | if quality != 'auto' and ext in ('f4m', 'm3u8'): |
113 | continue | |
e37c92ec | 114 | if ext == 'f4m': |
7e5edcfd | 115 | formats.extend(self._extract_f4m_formats( |
e37c92ec | 116 | stream_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', |
7e5edcfd | 117 | video_id, preference=-1, f4m_id='hds', fatal=False)) |
e37c92ec | 118 | elif ext == 'm3u8': |
7e5edcfd S |
119 | formats.extend(self._extract_m3u8_formats( |
120 | stream_url, video_id, 'mp4', preference=1, m3u8_id='hls', fatal=False)) | |
e37c92ec S |
121 | else: |
122 | if server and server.startswith('rtmp'): | |
123 | f = { | |
124 | 'url': server, | |
125 | 'play_path': stream_url, | |
126 | 'format_id': 'a%s-rtmp-%s' % (num, quality), | |
127 | } | |
128 | elif stream_url.startswith('http'): | |
129 | f = { | |
130 | 'url': stream_url, | |
131 | 'format_id': 'a%s-%s-%s' % (num, ext, quality) | |
132 | } | |
133 | else: | |
134 | continue | |
135 | m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url) | |
136 | if m: | |
137 | f.update({ | |
138 | 'width': int(m.group('width')), | |
139 | 'height': int(m.group('height')), | |
140 | }) | |
141 | if type_ == 'audio': | |
142 | f['vcodec'] = 'none' | |
143 | formats.append(f) | |
144 | return formats | |
145 | ||
d5822b96 PH |
146 | def _real_extract(self, url): |
147 | # determine video id from url | |
148 | m = re.match(self._VALID_URL, url) | |
149 | ||
150 | numid = re.search(r'documentId=([0-9]+)', url) | |
151 | if numid: | |
152 | video_id = numid.group(1) | |
153 | else: | |
154 | video_id = m.group('video_id') | |
155 | ||
5622f29a | 156 | webpage = self._download_webpage(url, video_id) |
f9b85496 | 157 | |
3a5beb0c S |
158 | if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage: |
159 | raise ExtractorError('Video %s is no longer available' % video_id, expected=True) | |
160 | ||
39aa42ff S |
161 | if 'Diese Sendung ist für Jugendliche unter 12 Jahren nicht geeignet. Der Clip ist deshalb nur von 20 bis 6 Uhr verfügbar.' in webpage: |
162 | raise ExtractorError('This program is only suitable for those aged 12 and older. Video %s is therefore only available between 20 pm and 6 am.' % video_id, expected=True) | |
163 | ||
bfd91588 | 164 | if re.search(r'[\?&]rss($|[=&])', url): |
f7854627 | 165 | doc = compat_etree_fromstring(webpage.encode('utf-8')) |
3741302a OE |
166 | if doc.tag == 'rss': |
167 | return GenericIE()._extract_rss(url, video_id, doc) | |
168 | ||
f9b85496 | 169 | title = self._html_search_regex( |
0f97c9a0 | 170 | [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>', |
6a3fa81f | 171 | r'<meta name="dcterms.title" content="(.*?)"/>', |
0f97c9a0 PH |
172 | r'<h4 class="headline">(.*?)</h4>'], |
173 | webpage, 'title') | |
f9b85496 | 174 | description = self._html_search_meta( |
29546b34 PH |
175 | 'dcterms.abstract', webpage, 'description', default=None) |
176 | if description is None: | |
177 | description = self._html_search_meta( | |
178 | 'description', webpage, 'meta description') | |
179 | ||
180 | # Thumbnail is sometimes not present. | |
181 | # It is in the mobile version, but that seems to use a different URL | |
182 | # structure altogether. | |
183 | thumbnail = self._og_search_thumbnail(webpage, default=None) | |
184 | ||
185 | media_streams = re.findall(r'''(?x) | |
186 | mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s* | |
187 | "([^"]+)"''', webpage) | |
188 | ||
189 | if media_streams: | |
190 | QUALITIES = qualities(['lo', 'hi', 'hq']) | |
191 | formats = [] | |
192 | for furl in set(media_streams): | |
193 | if furl.endswith('.f4m'): | |
194 | fid = 'f4m' | |
195 | else: | |
196 | fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl) | |
197 | fid = fid_m.group(1) if fid_m else None | |
198 | formats.append({ | |
199 | 'quality': QUALITIES(fid), | |
200 | 'format_id': fid, | |
201 | 'url': furl, | |
202 | }) | |
e37c92ec S |
203 | self._sort_formats(formats) |
204 | info = { | |
205 | 'formats': formats, | |
206 | } | |
29546b34 | 207 | else: # request JSON file |
e37c92ec S |
208 | info = self._extract_media_info( |
209 | 'http://www.ardmediathek.de/play/media/%s' % video_id, webpage, video_id) | |
f9b85496 | 210 | |
e37c92ec | 211 | info.update({ |
f9b85496 PH |
212 | 'id': video_id, |
213 | 'title': title, | |
214 | 'description': description, | |
f9b85496 | 215 | 'thumbnail': thumbnail, |
e37c92ec S |
216 | }) |
217 | ||
218 | return info | |
6d3d3fc0 PH |
219 | |
220 | ||
221 | class ARDIE(InfoExtractor): | |
222 | _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html' | |
223 | _TEST = { | |
224 | 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html', | |
225 | 'md5': 'd216c3a86493f9322545e045ddc3eb35', | |
226 | 'info_dict': { | |
227 | 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge', | |
228 | 'id': '100', | |
229 | 'ext': 'mp4', | |
230 | 'duration': 2600, | |
231 | 'title': 'Die Story im Ersten: Mission unter falscher Flagge', | |
232 | 'upload_date': '20140804', | |
233 | 'thumbnail': 're:^https?://.*\.jpg$', | |
234 | } | |
235 | } | |
236 | ||
237 | def _real_extract(self, url): | |
238 | mobj = re.match(self._VALID_URL, url) | |
239 | display_id = mobj.group('display_id') | |
240 | ||
241 | player_url = mobj.group('mainurl') + '~playerXml.xml' | |
242 | doc = self._download_xml(player_url, display_id) | |
243 | video_node = doc.find('./video') | |
bf0ff932 PH |
244 | upload_date = unified_strdate(xpath_text( |
245 | video_node, './broadcastDate')) | |
246 | thumbnail = xpath_text(video_node, './/teaserImage//variant/url') | |
6d3d3fc0 PH |
247 | |
248 | formats = [] | |
249 | for a in video_node.findall('.//asset'): | |
250 | f = { | |
251 | 'format_id': a.attrib['type'], | |
252 | 'width': int_or_none(a.find('./frameWidth').text), | |
253 | 'height': int_or_none(a.find('./frameHeight').text), | |
254 | 'vbr': int_or_none(a.find('./bitrateVideo').text), | |
255 | 'abr': int_or_none(a.find('./bitrateAudio').text), | |
256 | 'vcodec': a.find('./codecVideo').text, | |
257 | 'tbr': int_or_none(a.find('./totalBitrate').text), | |
258 | } | |
259 | if a.find('./serverPrefix').text: | |
260 | f['url'] = a.find('./serverPrefix').text | |
261 | f['playpath'] = a.find('./fileName').text | |
262 | else: | |
263 | f['url'] = a.find('./fileName').text | |
264 | formats.append(f) | |
265 | self._sort_formats(formats) | |
266 | ||
267 | return { | |
268 | 'id': mobj.group('id'), | |
269 | 'formats': formats, | |
270 | 'display_id': display_id, | |
271 | 'title': video_node.find('./title').text, | |
272 | 'duration': parse_duration(video_node.find('./duration').text), | |
273 | 'upload_date': upload_date, | |
274 | 'thumbnail': thumbnail, | |
275 | } |