2 from __future__ import unicode_literals
6 from .common import InfoExtractor
11 compat_urllib_parse_urlparse,
16 class ARDIE(InfoExtractor):
17 _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
20 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
21 'file': '22429276.mp4',
22 'md5': '469751912f1de0816a9fc9df8336476c',
24 'title': 'Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?',
25 'description': 'Das Erste Mediathek [ARD]: Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?, Anne Will, Über die Spionage-Affäre diskutieren Clemens Binninger, Katrin Göring-Eckardt, Georg Mascolo, Andrew B. Denison und Constanze Kurz.. Das Video zur Sendung Anne Will am Mittwoch, 16.07.2014',
27 'skip': 'Blocked outside of Germany',
29 'url': 'http://www.ardmediathek.de/tv/Tatort/Das-Wunder-von-Wolbeck-Video-tgl-ab-20/Das-Erste/Video?documentId=22490580&bcastId=602916',
33 'title': 'Das Wunder von Wolbeck (Video tgl. ab 20 Uhr)',
34 'description': 'Auf einem restaurierten Hof bei Wolbeck wird der Heilpraktiker Raffael Lembeck eines morgens von seiner Frau Stella tot aufgefunden. Das Opfer war offensichtlich in seiner Praxis zu Fall gekommen und ist dann verblutet, erklärt Prof. Boerne am Tatort.',
36 'skip': 'Blocked outside of Germany',
39 def _real_extract(self, url):
40 # determine video id from url
41 m = re.match(self._VALID_URL, url)
43 numid = re.search(r'documentId=([0-9]+)', url)
45 video_id = numid.group(1)
47 video_id = m.group('video_id')
49 urlp = compat_urllib_parse_urlparse(url)
50 url = urlp._replace(path=compat_urllib_parse.quote(urlp.path.encode('utf-8'))).geturl()
52 webpage = self._download_webpage(url, video_id)
54 title = self._html_search_regex(
55 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
56 r'<meta name="dcterms.title" content="(.*?)"/>',
57 r'<h4 class="headline">(.*?)</h4>'],
59 description = self._html_search_meta(
60 'dcterms.abstract', webpage, 'description', default=None)
61 if description is None:
62 description = self._html_search_meta(
63 'description', webpage, 'meta description')
65 # Thumbnail is sometimes not present.
66 # It is in the mobile version, but that seems to use a different URL
67 # structure altogether.
68 thumbnail = self._og_search_thumbnail(webpage, default=None)
70 media_streams = re.findall(r'''(?x)
71 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
72 "([^"]+)"''', webpage)
75 QUALITIES = qualities(['lo', 'hi', 'hq'])
77 for furl in set(media_streams):
78 if furl.endswith('.f4m'):
81 fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
82 fid = fid_m.group(1) if fid_m else None
84 'quality': QUALITIES(fid),
88 else: # request JSON file
89 media_info = self._download_json(
90 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
91 # The second element of the _mediaArray contains the standard http urls
92 streams = media_info['_mediaArray'][1]['_mediaStreamArray']
94 if '"fsk"' in webpage:
95 raise ExtractorError('This video is only available after 20:00')
99 if type(s['_stream']) == list:
100 for index, url in enumerate(s['_stream'][::-1]):
101 quality = s['_quality'] + index
105 'format_id': '%s-%s' % (determine_ext(url), quality)
110 'quality': s['_quality'],
114 format['format_id'] = '%s-%s' % (
115 determine_ext(format['url']), format['quality'])
117 formats.append(format)
119 self._sort_formats(formats)
124 'description': description,
126 'thumbnail': thumbnail,