]>
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 |
91328f26 | 8 | from ..compat import compat_str |
d5822b96 | 9 | from ..utils import ( |
f9b85496 | 10 | determine_ext, |
d5822b96 | 11 | ExtractorError, |
29546b34 | 12 | qualities, |
6d3d3fc0 PH |
13 | int_or_none, |
14 | parse_duration, | |
15 | unified_strdate, | |
bf0ff932 | 16 | xpath_text, |
31eeab9f | 17 | update_url_query, |
d5822b96 | 18 | ) |
f7854627 | 19 | from ..compat import compat_etree_fromstring |
d5822b96 | 20 | |
f9b85496 | 21 | |
6d3d3fc0 PH |
22 | class ARDMediathekIE(InfoExtractor): |
23 | IE_NAME = 'ARD:mediathek' | |
af21f56f | 24 | _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?' |
f9b85496 | 25 | |
29546b34 | 26 | _TESTS = [{ |
d6a03502 | 27 | # available till 26.07.2022 |
ad29ef04 W |
28 | 'url': 'http://www.ardmediathek.de/tv/S%C3%9CDLICHT/Was-ist-die-Kunst-der-Zukunft-liebe-Ann/BR-Fernsehen/Video?bcastId=34633636&documentId=44726822', |
29 | 'info_dict': { | |
30 | 'id': '44726822', | |
31 | 'ext': 'mp4', | |
32 | 'title': 'Was ist die Kunst der Zukunft, liebe Anna McCarthy?', | |
33 | 'description': 'md5:4ada28b3e3b5df01647310e41f3a62f5', | |
34 | 'duration': 1740, | |
35 | }, | |
36 | 'params': { | |
37 | # m3u8 download | |
38 | 'skip_download': True, | |
39 | } | |
86b4e98a S |
40 | }, { |
41 | # audio | |
42 | 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086', | |
d6a03502 | 43 | 'only_matching': True, |
769efa16 S |
44 | }, { |
45 | 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht', | |
46 | 'only_matching': True, | |
a66a73ee S |
47 | }, { |
48 | # audio | |
49 | 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158', | |
d6a03502 | 50 | 'only_matching': True, |
29546b34 | 51 | }] |
d5822b96 | 52 | |
e37c92ec S |
53 | def _extract_media_info(self, media_info_url, webpage, video_id): |
54 | media_info = self._download_json( | |
55 | media_info_url, video_id, 'Downloading media JSON') | |
56 | ||
57 | formats = self._extract_formats(media_info, video_id) | |
58 | ||
59 | if not formats: | |
60 | if '"fsk"' in webpage: | |
61 | raise ExtractorError( | |
62 | 'This video is only available after 20:00', expected=True) | |
63 | elif media_info.get('_geoblocked'): | |
64 | raise ExtractorError('This video is not available due to geo restriction', expected=True) | |
65 | ||
66 | self._sort_formats(formats) | |
67 | ||
68 | duration = int_or_none(media_info.get('_duration')) | |
69 | thumbnail = media_info.get('_previewImage') | |
ca127ab2 | 70 | is_live = media_info.get('_isLive') is True |
e37c92ec S |
71 | |
72 | subtitles = {} | |
73 | subtitle_url = media_info.get('_subtitleUrl') | |
74 | if subtitle_url: | |
75 | subtitles['de'] = [{ | |
ffa2cecf | 76 | 'ext': 'ttml', |
e37c92ec S |
77 | 'url': subtitle_url, |
78 | }] | |
79 | ||
80 | return { | |
81 | 'id': video_id, | |
82 | 'duration': duration, | |
83 | 'thumbnail': thumbnail, | |
ca127ab2 | 84 | 'is_live': is_live, |
e37c92ec S |
85 | 'formats': formats, |
86 | 'subtitles': subtitles, | |
87 | } | |
88 | ||
89 | def _extract_formats(self, media_info, video_id): | |
90 | type_ = media_info.get('_type') | |
91 | media_array = media_info.get('_mediaArray', []) | |
92 | formats = [] | |
93 | for num, media in enumerate(media_array): | |
94 | for stream in media.get('_mediaStreamArray', []): | |
95 | stream_urls = stream.get('_stream') | |
96 | if not stream_urls: | |
97 | continue | |
98 | if not isinstance(stream_urls, list): | |
99 | stream_urls = [stream_urls] | |
100 | quality = stream.get('_quality') | |
101 | server = stream.get('_server') | |
102 | for stream_url in stream_urls: | |
91328f26 S |
103 | if not isinstance(stream_url, compat_str) or '//' not in stream_url: |
104 | continue | |
e37c92ec | 105 | ext = determine_ext(stream_url) |
1fc0b47f | 106 | if quality != 'auto' and ext in ('f4m', 'm3u8'): |
107 | continue | |
e37c92ec | 108 | if ext == 'f4m': |
7e5edcfd | 109 | formats.extend(self._extract_f4m_formats( |
31eeab9f RA |
110 | update_url_query(stream_url, { |
111 | 'hdcore': '3.1.1', | |
112 | 'plugin': 'aasp-3.1.1.69.124' | |
113 | }), | |
114 | video_id, f4m_id='hds', fatal=False)) | |
e37c92ec | 115 | elif ext == 'm3u8': |
7e5edcfd | 116 | formats.extend(self._extract_m3u8_formats( |
31eeab9f | 117 | stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) |
e37c92ec S |
118 | else: |
119 | if server and server.startswith('rtmp'): | |
120 | f = { | |
121 | 'url': server, | |
122 | 'play_path': stream_url, | |
123 | 'format_id': 'a%s-rtmp-%s' % (num, quality), | |
124 | } | |
91328f26 | 125 | else: |
e37c92ec S |
126 | f = { |
127 | 'url': stream_url, | |
128 | 'format_id': 'a%s-%s-%s' % (num, ext, quality) | |
129 | } | |
e37c92ec S |
130 | m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url) |
131 | if m: | |
132 | f.update({ | |
133 | 'width': int(m.group('width')), | |
134 | 'height': int(m.group('height')), | |
135 | }) | |
136 | if type_ == 'audio': | |
137 | f['vcodec'] = 'none' | |
138 | formats.append(f) | |
139 | return formats | |
140 | ||
d5822b96 PH |
141 | def _real_extract(self, url): |
142 | # determine video id from url | |
143 | m = re.match(self._VALID_URL, url) | |
144 | ||
ca127ab2 S |
145 | document_id = None |
146 | ||
d5822b96 PH |
147 | numid = re.search(r'documentId=([0-9]+)', url) |
148 | if numid: | |
ca127ab2 | 149 | document_id = video_id = numid.group(1) |
d5822b96 PH |
150 | else: |
151 | video_id = m.group('video_id') | |
152 | ||
5622f29a | 153 | webpage = self._download_webpage(url, video_id) |
f9b85496 | 154 | |
3791d84a S |
155 | ERRORS = ( |
156 | ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'), | |
157 | ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<', | |
158 | 'Video %s is no longer available'), | |
3791d84a S |
159 | ) |
160 | ||
161 | for pattern, message in ERRORS: | |
162 | if pattern in webpage: | |
163 | raise ExtractorError(message % video_id, expected=True) | |
39aa42ff | 164 | |
bfd91588 | 165 | if re.search(r'[\?&]rss($|[=&])', url): |
f7854627 | 166 | doc = compat_etree_fromstring(webpage.encode('utf-8')) |
3741302a OE |
167 | if doc.tag == 'rss': |
168 | return GenericIE()._extract_rss(url, video_id, doc) | |
169 | ||
f9b85496 | 170 | title = self._html_search_regex( |
0f97c9a0 | 171 | [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>', |
197224b7 | 172 | r'<meta name="dcterms\.title" content="(.*?)"/>', |
0f97c9a0 PH |
173 | r'<h4 class="headline">(.*?)</h4>'], |
174 | webpage, 'title') | |
f9b85496 | 175 | description = self._html_search_meta( |
29546b34 PH |
176 | 'dcterms.abstract', webpage, 'description', default=None) |
177 | if description is None: | |
178 | description = self._html_search_meta( | |
179 | 'description', webpage, 'meta description') | |
180 | ||
181 | # Thumbnail is sometimes not present. | |
182 | # It is in the mobile version, but that seems to use a different URL | |
183 | # structure altogether. | |
184 | thumbnail = self._og_search_thumbnail(webpage, default=None) | |
185 | ||
186 | media_streams = re.findall(r'''(?x) | |
187 | mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s* | |
188 | "([^"]+)"''', webpage) | |
189 | ||
190 | if media_streams: | |
191 | QUALITIES = qualities(['lo', 'hi', 'hq']) | |
192 | formats = [] | |
193 | for furl in set(media_streams): | |
194 | if furl.endswith('.f4m'): | |
195 | fid = 'f4m' | |
196 | else: | |
197 | fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl) | |
198 | fid = fid_m.group(1) if fid_m else None | |
199 | formats.append({ | |
200 | 'quality': QUALITIES(fid), | |
201 | 'format_id': fid, | |
202 | 'url': furl, | |
203 | }) | |
e37c92ec S |
204 | self._sort_formats(formats) |
205 | info = { | |
206 | 'formats': formats, | |
207 | } | |
29546b34 | 208 | else: # request JSON file |
ca127ab2 S |
209 | if not document_id: |
210 | video_id = self._search_regex( | |
211 | r'/play/(?:config|media)/(\d+)', webpage, 'media id') | |
e37c92ec | 212 | info = self._extract_media_info( |
ca127ab2 S |
213 | 'http://www.ardmediathek.de/play/media/%s' % video_id, |
214 | webpage, video_id) | |
f9b85496 | 215 | |
e37c92ec | 216 | info.update({ |
f9b85496 | 217 | 'id': video_id, |
ca127ab2 | 218 | 'title': self._live_title(title) if info.get('is_live') else title, |
f9b85496 | 219 | 'description': description, |
f9b85496 | 220 | 'thumbnail': thumbnail, |
e37c92ec S |
221 | }) |
222 | ||
223 | return info | |
6d3d3fc0 PH |
224 | |
225 | ||
226 | class ARDIE(InfoExtractor): | |
25042f73 | 227 | _VALID_URL = r'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html' |
ad29ef04 | 228 | _TESTS = [{ |
d6a03502 | 229 | # available till 14.02.2019 |
ad29ef04 W |
230 | 'url': 'http://www.daserste.de/information/talk/maischberger/videos/das-groko-drama-zerlegen-sich-die-volksparteien-video-102.html', |
231 | 'md5': '8e4ec85f31be7c7fc08a26cdbc5a1f49', | |
232 | 'info_dict': { | |
233 | 'display_id': 'das-groko-drama-zerlegen-sich-die-volksparteien-video', | |
234 | 'id': '102', | |
235 | 'ext': 'mp4', | |
236 | 'duration': 4435.0, | |
237 | 'title': 'Das GroKo-Drama: Zerlegen sich die Volksparteien?', | |
238 | 'upload_date': '20180214', | |
239 | 'thumbnail': r're:^https?://.*\.jpg$', | |
240 | }, | |
d6a03502 | 241 | }, { |
6d3d3fc0 | 242 | 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html', |
d6a03502 | 243 | 'only_matching': True, |
ad29ef04 | 244 | }] |
6d3d3fc0 PH |
245 | |
246 | def _real_extract(self, url): | |
247 | mobj = re.match(self._VALID_URL, url) | |
248 | display_id = mobj.group('display_id') | |
249 | ||
250 | player_url = mobj.group('mainurl') + '~playerXml.xml' | |
251 | doc = self._download_xml(player_url, display_id) | |
252 | video_node = doc.find('./video') | |
bf0ff932 PH |
253 | upload_date = unified_strdate(xpath_text( |
254 | video_node, './broadcastDate')) | |
255 | thumbnail = xpath_text(video_node, './/teaserImage//variant/url') | |
6d3d3fc0 PH |
256 | |
257 | formats = [] | |
258 | for a in video_node.findall('.//asset'): | |
259 | f = { | |
260 | 'format_id': a.attrib['type'], | |
261 | 'width': int_or_none(a.find('./frameWidth').text), | |
262 | 'height': int_or_none(a.find('./frameHeight').text), | |
263 | 'vbr': int_or_none(a.find('./bitrateVideo').text), | |
264 | 'abr': int_or_none(a.find('./bitrateAudio').text), | |
265 | 'vcodec': a.find('./codecVideo').text, | |
266 | 'tbr': int_or_none(a.find('./totalBitrate').text), | |
267 | } | |
268 | if a.find('./serverPrefix').text: | |
269 | f['url'] = a.find('./serverPrefix').text | |
270 | f['playpath'] = a.find('./fileName').text | |
271 | else: | |
272 | f['url'] = a.find('./fileName').text | |
273 | formats.append(f) | |
274 | self._sort_formats(formats) | |
275 | ||
276 | return { | |
277 | 'id': mobj.group('id'), | |
278 | 'formats': formats, | |
279 | 'display_id': display_id, | |
280 | 'title': video_node.find('./title').text, | |
281 | 'duration': parse_duration(video_node.find('./duration').text), | |
282 | 'upload_date': upload_date, | |
283 | 'thumbnail': thumbnail, | |
284 | } |