2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from .generic import GenericIE
11 get_element_by_attribute,
21 class ARDMediathekIE(InfoExtractor):
22 IE_NAME = 'ARD:mediathek'
23 _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.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,
40 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
41 'md5': '219d94d8980b4f538c7fcb0865eb7f2c',
45 'title': 'Tod eines Fußballers',
46 'description': 'md5:f6e39f3461f0e1f54bfa48c8875c86ef',
50 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
51 'only_matching': True,
54 def _extract_media_info(self, media_info_url, webpage, video_id):
55 media_info = self._download_json(
56 media_info_url, video_id, 'Downloading media JSON')
58 formats = self._extract_formats(media_info, video_id)
61 if '"fsk"' in webpage:
63 'This video is only available after 20:00', expected=True)
64 elif media_info.get('_geoblocked'):
65 raise ExtractorError('This video is not available due to geo restriction', expected=True)
67 self._sort_formats(formats)
69 duration = int_or_none(media_info.get('_duration'))
70 thumbnail = media_info.get('_previewImage')
73 subtitle_url = media_info.get('_subtitleUrl')
83 'thumbnail': thumbnail,
85 'subtitles': subtitles,
88 def _extract_formats(self, media_info, video_id):
89 type_ = media_info.get('_type')
90 media_array = media_info.get('_mediaArray', [])
92 for num, media in enumerate(media_array):
93 for stream in media.get('_mediaStreamArray', []):
94 stream_urls = stream.get('_stream')
97 if not isinstance(stream_urls, list):
98 stream_urls = [stream_urls]
99 quality = stream.get('_quality')
100 server = stream.get('_server')
101 for stream_url in stream_urls:
102 ext = determine_ext(stream_url)
104 formats.extend(self._extract_f4m_formats(
105 stream_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124',
106 video_id, preference=-1, f4m_id='hds'))
108 formats.extend(self._extract_m3u8_formats(
109 stream_url, video_id, 'mp4', preference=1, m3u8_id='hls'))
111 if server and server.startswith('rtmp'):
114 'play_path': stream_url,
115 'format_id': 'a%s-rtmp-%s' % (num, quality),
117 elif stream_url.startswith('http'):
120 'format_id': 'a%s-%s-%s' % (num, ext, quality)
124 m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url)
127 'width': int(m.group('width')),
128 'height': int(m.group('height')),
135 def _real_extract(self, url):
136 # determine video id from url
137 m = re.match(self._VALID_URL, url)
139 numid = re.search(r'documentId=([0-9]+)', url)
141 video_id = numid.group(1)
143 video_id = m.group('video_id')
145 webpage = self._download_webpage(url, video_id)
147 if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
148 raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
150 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:
151 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)
153 if re.search(r'[\?&]rss($|[=&])', url):
154 doc = parse_xml(webpage)
156 return GenericIE()._extract_rss(url, video_id, doc)
158 title = self._html_search_regex(
159 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
160 r'<meta name="dcterms.title" content="(.*?)"/>',
161 r'<h4 class="headline">(.*?)</h4>'],
163 description = self._html_search_meta(
164 'dcterms.abstract', webpage, 'description', default=None)
165 if description is None:
166 description = self._html_search_meta(
167 'description', webpage, 'meta description')
169 # Thumbnail is sometimes not present.
170 # It is in the mobile version, but that seems to use a different URL
171 # structure altogether.
172 thumbnail = self._og_search_thumbnail(webpage, default=None)
174 media_streams = re.findall(r'''(?x)
175 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
176 "([^"]+)"''', webpage)
179 QUALITIES = qualities(['lo', 'hi', 'hq'])
181 for furl in set(media_streams):
182 if furl.endswith('.f4m'):
185 fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
186 fid = fid_m.group(1) if fid_m else None
188 'quality': QUALITIES(fid),
192 self._sort_formats(formats)
196 else: # request JSON file
197 info = self._extract_media_info(
198 'http://www.ardmediathek.de/play/media/%s' % video_id, webpage, video_id)
203 'description': description,
204 'thumbnail': thumbnail,
210 class ARDIE(InfoExtractor):
211 _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
213 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
214 'md5': 'd216c3a86493f9322545e045ddc3eb35',
216 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
220 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
221 'upload_date': '20140804',
222 'thumbnail': 're:^https?://.*\.jpg$',
226 def _real_extract(self, url):
227 mobj = re.match(self._VALID_URL, url)
228 display_id = mobj.group('display_id')
230 player_url = mobj.group('mainurl') + '~playerXml.xml'
231 doc = self._download_xml(player_url, display_id)
232 video_node = doc.find('./video')
233 upload_date = unified_strdate(xpath_text(
234 video_node, './broadcastDate'))
235 thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
238 for a in video_node.findall('.//asset'):
240 'format_id': a.attrib['type'],
241 'width': int_or_none(a.find('./frameWidth').text),
242 'height': int_or_none(a.find('./frameHeight').text),
243 'vbr': int_or_none(a.find('./bitrateVideo').text),
244 'abr': int_or_none(a.find('./bitrateAudio').text),
245 'vcodec': a.find('./codecVideo').text,
246 'tbr': int_or_none(a.find('./totalBitrate').text),
248 if a.find('./serverPrefix').text:
249 f['url'] = a.find('./serverPrefix').text
250 f['playpath'] = a.find('./fileName').text
252 f['url'] = a.find('./fileName').text
254 self._sort_formats(formats)
257 'id': mobj.group('id'),
259 'display_id': display_id,
260 'title': video_node.find('./title').text,
261 'duration': parse_duration(video_node.find('./duration').text),
262 'upload_date': upload_date,
263 'thumbnail': thumbnail,
267 class SportschauIE(ARDMediathekIE):
268 IE_NAME = 'Sportschau'
269 _VALID_URL = r'(?P<baseurl>https?://(?:www\.)?sportschau\.de/(?:[^/]+/)+video(?P<id>[^/#?]+))\.html'
271 'url': 'http://www.sportschau.de/tourdefrance/videoseppeltkokainhatnichtsmitklassischemdopingzutun100.html',
273 'id': 'seppeltkokainhatnichtsmitklassischemdopingzutun100',
275 'title': 'Seppelt: "Kokain hat nichts mit klassischem Doping zu tun"',
276 'thumbnail': 're:^https?://.*\.jpg$',
277 'description': 'Der ARD-Doping Experte Hajo Seppelt gibt seine Einschätzung zum ersten Dopingfall der diesjährigen Tour de France um den Italiener Luca Paolini ab.',
281 'skip_download': True,
285 def _real_extract(self, url):
286 mobj = re.match(self._VALID_URL, url)
287 video_id = mobj.group('id')
288 base_url = mobj.group('baseurl')
290 webpage = self._download_webpage(url, video_id)
291 title = get_element_by_attribute('class', 'headline', webpage)
292 description = self._html_search_meta('description', webpage, 'description')
294 info = self._extract_media_info(
295 base_url + '-mc_defaultQuality-h.json', webpage, video_id)
299 'description': description,