]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ard.py
[youtube] Fix extraction of age gate videos (closes #3270)
[yt-dlp.git] / youtube_dl / extractor / ard.py
CommitLineData
f9b85496
PH
1# coding: utf-8
2from __future__ import unicode_literals
3
d5822b96
PH
4import re
5
6from .common import InfoExtractor
7from ..utils import (
f9b85496 8 determine_ext,
d5822b96
PH
9 ExtractorError,
10)
11
f9b85496 12
d5822b96 13class ARDIE(InfoExtractor):
f9b85496
PH
14 _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[^/\?]+)(?:\?.*)?'
15
6f5ac90c 16 _TEST = {
f9b85496
PH
17 'url': 'http://www.ardmediathek.de/das-erste/guenther-jauch/edward-snowden-im-interview-held-oder-verraeter?documentId=19288786',
18 'file': '19288786.mp4',
19 'md5': '515bf47ce209fb3f5a61b7aad364634c',
20 'info_dict': {
21 'title': 'Edward Snowden im Interview - Held oder Verräter?',
22 'description': 'Edward Snowden hat alles aufs Spiel gesetzt, um die weltweite \xdcberwachung durch die Geheimdienste zu enttarnen. Nun stellt sich der ehemalige NSA-Mitarbeiter erstmals weltweit in einem TV-Interview den Fragen eines NDR-Journalisten. Die Sendung vom Sonntagabend.',
23 'thumbnail': 'http://www.ardmediathek.de/ard/servlet/contentblob/19/28/87/90/19288790/bild/2250037',
6f5ac90c 24 },
f9b85496 25 'skip': 'Blocked outside of Germany',
6f5ac90c 26 }
d5822b96
PH
27
28 def _real_extract(self, url):
29 # determine video id from url
30 m = re.match(self._VALID_URL, url)
31
32 numid = re.search(r'documentId=([0-9]+)', url)
33 if numid:
34 video_id = numid.group(1)
35 else:
36 video_id = m.group('video_id')
37
f9b85496
PH
38 webpage = self._download_webpage(url, video_id)
39
40 title = self._html_search_regex(
0f97c9a0 41 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
6a3fa81f 42 r'<meta name="dcterms.title" content="(.*?)"/>',
0f97c9a0
PH
43 r'<h4 class="headline">(.*?)</h4>'],
44 webpage, 'title')
f9b85496
PH
45 description = self._html_search_meta(
46 'dcterms.abstract', webpage, 'description')
47 thumbnail = self._og_search_thumbnail(webpage)
48
6a3fa81f
JMF
49
50 media_info = self._download_json(
51 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
52 # The second element of the _mediaArray contains the standard http urls
53 streams = media_info['_mediaArray'][1]['_mediaStreamArray']
d5822b96 54 if not streams:
f9b85496
PH
55 if '"fsk"' in webpage:
56 raise ExtractorError('This video is only available after 20:00')
57
58 formats = []
e5da4021 59
f9b85496 60 for s in streams:
e5da4021 61 if type(s['_stream']) == list:
895ce482 62 for index, url in enumerate(s['_stream'][::-1]):
63 quality = s['_quality'] + index
e5da4021 64 formats.append({
65 'quality': quality,
895ce482 66 'url': url,
67 'format_id': '%s-%s' % (determine_ext(url), quality)
e5da4021 68 })
69 continue
70
f9b85496 71 format = {
6a3fa81f
JMF
72 'quality': s['_quality'],
73 'url': s['_stream'],
f9b85496 74 }
6a3fa81f
JMF
75
76 format['format_id'] = '%s-%s' % (
77 determine_ext(format['url']), format['quality'])
f9b85496
PH
78
79 formats.append(format)
80
81 self._sort_formats(formats)
82
83 return {
84 'id': video_id,
85 'title': title,
86 'description': description,
87 'formats': formats,
88 'thumbnail': thumbnail,
89 }