2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from .generic import GenericIE
18 from ..compat import compat_etree_fromstring
21 class ARDMediathekIE(InfoExtractor):
22 IE_NAME = 'ARD:mediathek'
23 _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
26 'url': 'http://www.ardmediathek.de/tv/Dokumentation-und-Reportage/Ich-liebe-das-Leben-trotzdem/rbb-Fernsehen/Video?documentId=29582122&bcastId=3822114',
30 'title': 'Ich liebe das Leben trotzdem',
31 'description': 'md5:45e4c225c72b27993314b31a84a5261c',
36 'skip_download': True,
38 'skip': 'HTTP Error 404: Not Found',
40 'url': 'http://www.ardmediathek.de/tv/Tatort/Tatort-Scheinwelten-H%C3%B6rfassung-Video/Das-Erste/Video?documentId=29522730&bcastId=602916',
41 'md5': 'f4d98b10759ac06c0072bbcd1f0b9e3e',
45 'title': 'Tatort: Scheinwelten - Hörfassung (Video tgl. ab 20 Uhr)',
46 'description': 'md5:196392e79876d0ac94c94e8cdb2875f1',
49 'skip': 'HTTP Error 404: Not Found',
52 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
53 'md5': '219d94d8980b4f538c7fcb0865eb7f2c',
57 'title': 'Tod eines Fußballers',
58 'description': 'md5:f6e39f3461f0e1f54bfa48c8875c86ef',
61 'skip': 'HTTP Error 404: Not Found',
63 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
64 'only_matching': True,
67 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
68 'md5': '4e8f00631aac0395fee17368ac0e9867',
72 'title': 'Vor dem Fest',
73 'description': 'md5:c0c1c8048514deaed2a73b3a60eecacb',
78 def _extract_media_info(self, media_info_url, webpage, video_id):
79 media_info = self._download_json(
80 media_info_url, video_id, 'Downloading media JSON')
82 formats = self._extract_formats(media_info, video_id)
85 if '"fsk"' in webpage:
87 'This video is only available after 20:00', expected=True)
88 elif media_info.get('_geoblocked'):
89 raise ExtractorError('This video is not available due to geo restriction', expected=True)
91 self._sort_formats(formats)
93 duration = int_or_none(media_info.get('_duration'))
94 thumbnail = media_info.get('_previewImage')
97 subtitle_url = media_info.get('_subtitleUrl')
106 'duration': duration,
107 'thumbnail': thumbnail,
109 'subtitles': subtitles,
112 def _extract_formats(self, media_info, video_id):
113 type_ = media_info.get('_type')
114 media_array = media_info.get('_mediaArray', [])
116 for num, media in enumerate(media_array):
117 for stream in media.get('_mediaStreamArray', []):
118 stream_urls = stream.get('_stream')
121 if not isinstance(stream_urls, list):
122 stream_urls = [stream_urls]
123 quality = stream.get('_quality')
124 server = stream.get('_server')
125 for stream_url in stream_urls:
126 ext = determine_ext(stream_url)
127 if quality != 'auto' and ext in ('f4m', 'm3u8'):
130 formats.extend(self._extract_f4m_formats(
131 update_url_query(stream_url, {
133 'plugin': 'aasp-3.1.1.69.124'
135 video_id, f4m_id='hds', fatal=False))
137 formats.extend(self._extract_m3u8_formats(
138 stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
140 if server and server.startswith('rtmp'):
143 'play_path': stream_url,
144 'format_id': 'a%s-rtmp-%s' % (num, quality),
146 elif stream_url.startswith('http'):
149 'format_id': 'a%s-%s-%s' % (num, ext, quality)
153 m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url)
156 'width': int(m.group('width')),
157 'height': int(m.group('height')),
164 def _real_extract(self, url):
165 # determine video id from url
166 m = re.match(self._VALID_URL, url)
168 numid = re.search(r'documentId=([0-9]+)', url)
170 video_id = numid.group(1)
172 video_id = m.group('video_id')
174 webpage = self._download_webpage(url, video_id)
176 if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
177 raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
179 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:
180 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)
182 if re.search(r'[\?&]rss($|[=&])', url):
183 doc = compat_etree_fromstring(webpage.encode('utf-8'))
185 return GenericIE()._extract_rss(url, video_id, doc)
187 title = self._html_search_regex(
188 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
189 r'<meta name="dcterms.title" content="(.*?)"/>',
190 r'<h4 class="headline">(.*?)</h4>'],
192 description = self._html_search_meta(
193 'dcterms.abstract', webpage, 'description', default=None)
194 if description is None:
195 description = self._html_search_meta(
196 'description', webpage, 'meta description')
198 # Thumbnail is sometimes not present.
199 # It is in the mobile version, but that seems to use a different URL
200 # structure altogether.
201 thumbnail = self._og_search_thumbnail(webpage, default=None)
203 media_streams = re.findall(r'''(?x)
204 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
205 "([^"]+)"''', webpage)
208 QUALITIES = qualities(['lo', 'hi', 'hq'])
210 for furl in set(media_streams):
211 if furl.endswith('.f4m'):
214 fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
215 fid = fid_m.group(1) if fid_m else None
217 'quality': QUALITIES(fid),
221 self._sort_formats(formats)
225 else: # request JSON file
226 info = self._extract_media_info(
227 'http://www.ardmediathek.de/play/media/%s' % video_id, webpage, video_id)
232 'description': description,
233 'thumbnail': thumbnail,
239 class ARDIE(InfoExtractor):
240 _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
242 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
243 'md5': 'd216c3a86493f9322545e045ddc3eb35',
245 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
249 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
250 'upload_date': '20140804',
251 'thumbnail': 're:^https?://.*\.jpg$',
253 'skip': 'HTTP Error 404: Not Found',
256 def _real_extract(self, url):
257 mobj = re.match(self._VALID_URL, url)
258 display_id = mobj.group('display_id')
260 player_url = mobj.group('mainurl') + '~playerXml.xml'
261 doc = self._download_xml(player_url, display_id)
262 video_node = doc.find('./video')
263 upload_date = unified_strdate(xpath_text(
264 video_node, './broadcastDate'))
265 thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
268 for a in video_node.findall('.//asset'):
270 'format_id': a.attrib['type'],
271 'width': int_or_none(a.find('./frameWidth').text),
272 'height': int_or_none(a.find('./frameHeight').text),
273 'vbr': int_or_none(a.find('./bitrateVideo').text),
274 'abr': int_or_none(a.find('./bitrateAudio').text),
275 'vcodec': a.find('./codecVideo').text,
276 'tbr': int_or_none(a.find('./totalBitrate').text),
278 if a.find('./serverPrefix').text:
279 f['url'] = a.find('./serverPrefix').text
280 f['playpath'] = a.find('./fileName').text
282 f['url'] = a.find('./fileName').text
284 self._sort_formats(formats)
287 'id': mobj.group('id'),
289 'display_id': display_id,
290 'title': video_node.find('./title').text,
291 'duration': parse_duration(video_node.find('./duration').text),
292 'upload_date': upload_date,
293 'thumbnail': thumbnail,