]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ard.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .generic
import GenericIE
22 from ..compat
import compat_etree_fromstring
25 class ARDMediathekIE(InfoExtractor
):
26 IE_NAME
= 'ARD:mediathek'
27 _VALID_URL
= r
'^https?://(?:(?:(?:www|classic)\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de|one\.ard\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
30 # available till 26.07.2022
31 'url': 'http://www.ardmediathek.de/tv/S%C3%9CDLICHT/Was-ist-die-Kunst-der-Zukunft-liebe-Ann/BR-Fernsehen/Video?bcastId=34633636&documentId=44726822',
35 'title': 'Was ist die Kunst der Zukunft, liebe Anna McCarthy?',
36 'description': 'md5:4ada28b3e3b5df01647310e41f3a62f5',
41 'skip_download': True,
44 'url': 'https://one.ard.de/tv/Mord-mit-Aussicht/Mord-mit-Aussicht-6-39-T%C3%B6dliche-Nach/ONE/Video?bcastId=46384294&documentId=55586872',
45 'only_matching': True,
48 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
49 'only_matching': True,
51 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
52 'only_matching': True,
55 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
56 'only_matching': True,
58 'url': 'https://classic.ardmediathek.de/tv/Panda-Gorilla-Co/Panda-Gorilla-Co-Folge-274/Das-Erste/Video?bcastId=16355486&documentId=58234698',
59 'only_matching': True,
63 def suitable(cls
, url
):
64 return False if ARDBetaMediathekIE
.suitable(url
) else super(ARDMediathekIE
, cls
).suitable(url
)
66 def _extract_media_info(self
, media_info_url
, webpage
, video_id
):
67 media_info
= self
._download
_json
(
68 media_info_url
, video_id
, 'Downloading media JSON')
70 formats
= self
._extract
_formats
(media_info
, video_id
)
73 if '"fsk"' in webpage
:
75 'This video is only available after 20:00', expected
=True)
76 elif media_info
.get('_geoblocked'):
77 raise ExtractorError('This video is not available due to geo restriction', expected
=True)
79 self
._sort
_formats
(formats
)
81 duration
= int_or_none(media_info
.get('_duration'))
82 thumbnail
= media_info
.get('_previewImage')
83 is_live
= media_info
.get('_isLive') is True
86 subtitle_url
= media_info
.get('_subtitleUrl')
96 'thumbnail': thumbnail
,
99 'subtitles': subtitles
,
102 def _extract_formats(self
, media_info
, video_id
):
103 type_
= media_info
.get('_type')
104 media_array
= media_info
.get('_mediaArray', [])
106 for num
, media
in enumerate(media_array
):
107 for stream
in media
.get('_mediaStreamArray', []):
108 stream_urls
= stream
.get('_stream')
111 if not isinstance(stream_urls
, list):
112 stream_urls
= [stream_urls
]
113 quality
= stream
.get('_quality')
114 server
= stream
.get('_server')
115 for stream_url
in stream_urls
:
116 if not url_or_none(stream_url
):
118 ext
= determine_ext(stream_url
)
119 if quality
!= 'auto' and ext
in ('f4m', 'm3u8'):
122 formats
.extend(self
._extract
_f
4m
_formats
(
123 update_url_query(stream_url
, {
125 'plugin': 'aasp-3.1.1.69.124'
127 video_id
, f4m_id
='hds', fatal
=False))
129 formats
.extend(self
._extract
_m
3u8_formats
(
130 stream_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
132 if server
and server
.startswith('rtmp'):
135 'play_path': stream_url
,
136 'format_id': 'a%s-rtmp-%s' % (num
, quality
),
141 'format_id': 'a%s-%s-%s' % (num
, ext
, quality
)
143 m
= re
.search(r
'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url
)
146 'width': int(m
.group('width')),
147 'height': int(m
.group('height')),
154 def _real_extract(self
, url
):
155 # determine video id from url
156 m
= re
.match(self
._VALID
_URL
, url
)
160 numid
= re
.search(r
'documentId=([0-9]+)', url
)
162 document_id
= video_id
= numid
.group(1)
164 video_id
= m
.group('video_id')
166 webpage
= self
._download
_webpage
(url
, video_id
)
169 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
170 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
171 'Video %s is no longer available'),
174 for pattern
, message
in ERRORS
:
175 if pattern
in webpage
:
176 raise ExtractorError(message
% video_id
, expected
=True)
178 if re
.search(r
'[\?&]rss($|[=&])', url
):
179 doc
= compat_etree_fromstring(webpage
.encode('utf-8'))
181 return GenericIE()._extract
_rss
(url
, video_id
, doc
)
183 title
= self
._html
_search
_regex
(
184 [r
'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
185 r
'<meta name="dcterms\.title" content="(.*?)"/>',
186 r
'<h4 class="headline">(.*?)</h4>',
187 r
'<title[^>]*>(.*?)</title>'],
189 description
= self
._html
_search
_meta
(
190 'dcterms.abstract', webpage
, 'description', default
=None)
191 if description
is None:
192 description
= self
._html
_search
_meta
(
193 'description', webpage
, 'meta description', default
=None)
194 if description
is None:
195 description
= self
._html
_search
_regex
(
196 r
'<p\s+class="teasertext">(.+?)</p>',
197 webpage
, 'teaser text', default
=None)
199 # Thumbnail is sometimes not present.
200 # It is in the mobile version, but that seems to use a different URL
201 # structure altogether.
202 thumbnail
= self
._og
_search
_thumbnail
(webpage
, default
=None)
204 media_streams
= re
.findall(r
'''(?x)
205 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
206 "([^"]+)"''', webpage
)
209 QUALITIES
= qualities(['lo', 'hi', 'hq'])
211 for furl
in set(media_streams
):
212 if furl
.endswith('.f4m'):
215 fid_m
= re
.match(r
'.*\.([^.]+)\.[^.]+$', furl
)
216 fid
= fid_m
.group(1) if fid_m
else None
218 'quality': QUALITIES(fid
),
222 self
._sort
_formats
(formats
)
226 else: # request JSON file
228 video_id
= self
._search
_regex
(
229 r
'/play/(?:config|media)/(\d+)', webpage
, 'media id')
230 info
= self
._extract
_media
_info
(
231 'http://www.ardmediathek.de/play/media/%s' % video_id
,
236 'title': self
._live
_title
(title
) if info
.get('is_live') else title
,
237 'description': description
,
238 'thumbnail': thumbnail
,
244 class ARDIE(InfoExtractor
):
245 _VALID_URL
= r
'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
247 # available till 14.02.2019
248 'url': 'http://www.daserste.de/information/talk/maischberger/videos/das-groko-drama-zerlegen-sich-die-volksparteien-video-102.html',
249 'md5': '8e4ec85f31be7c7fc08a26cdbc5a1f49',
251 'display_id': 'das-groko-drama-zerlegen-sich-die-volksparteien-video',
255 'title': 'Das GroKo-Drama: Zerlegen sich die Volksparteien?',
256 'upload_date': '20180214',
257 'thumbnail': r
're:^https?://.*\.jpg$',
260 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
261 'only_matching': True,
264 def _real_extract(self
, url
):
265 mobj
= re
.match(self
._VALID
_URL
, url
)
266 display_id
= mobj
.group('display_id')
268 player_url
= mobj
.group('mainurl') + '~playerXml.xml'
269 doc
= self
._download
_xml
(player_url
, display_id
)
270 video_node
= doc
.find('./video')
271 upload_date
= unified_strdate(xpath_text(
272 video_node
, './broadcastDate'))
273 thumbnail
= xpath_text(video_node
, './/teaserImage//variant/url')
276 for a
in video_node
.findall('.//asset'):
278 'format_id': a
.attrib
['type'],
279 'width': int_or_none(a
.find('./frameWidth').text
),
280 'height': int_or_none(a
.find('./frameHeight').text
),
281 'vbr': int_or_none(a
.find('./bitrateVideo').text
),
282 'abr': int_or_none(a
.find('./bitrateAudio').text
),
283 'vcodec': a
.find('./codecVideo').text
,
284 'tbr': int_or_none(a
.find('./totalBitrate').text
),
286 if a
.find('./serverPrefix').text
:
287 f
['url'] = a
.find('./serverPrefix').text
288 f
['playpath'] = a
.find('./fileName').text
290 f
['url'] = a
.find('./fileName').text
292 self
._sort
_formats
(formats
)
295 'id': mobj
.group('id'),
297 'display_id': display_id
,
298 'title': video_node
.find('./title').text
,
299 'duration': parse_duration(video_node
.find('./duration').text
),
300 'upload_date': upload_date
,
301 'thumbnail': thumbnail
,
305 class ARDBetaMediathekIE(InfoExtractor
):
306 _VALID_URL
= r
'https://(?:beta|www)\.ardmediathek\.de/[^/]+/(?:player|live)/(?P<video_id>[a-zA-Z0-9]+)(?:/(?P<display_id>[^/?#]+))?'
308 'url': 'https://beta.ardmediathek.de/ard/player/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE/die-robuste-roswita',
309 'md5': '2d02d996156ea3c397cfc5036b5d7f8f',
311 'display_id': 'die-robuste-roswita',
312 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
313 'title': 'Tatort: Die robuste Roswita',
314 'description': r
're:^Der Mord.*trüber ist als die Ilm.',
316 'thumbnail': 'https://img.ardmediathek.de/standard/00/55/43/59/34/-1774185891/16x9/960?mandant=ard',
317 'upload_date': '20180826',
321 'url': 'https://www.ardmediathek.de/ard/player/Y3JpZDovL3N3ci5kZS9hZXgvbzEwNzE5MTU/',
322 'only_matching': True,
324 'url': 'https://www.ardmediathek.de/swr/live/Y3JpZDovL3N3ci5kZS8xMzQ4MTA0Mg',
325 'only_matching': True,
328 def _real_extract(self
, url
):
329 mobj
= re
.match(self
._VALID
_URL
, url
)
330 video_id
= mobj
.group('video_id')
331 display_id
= mobj
.group('display_id') or video_id
333 webpage
= self
._download
_webpage
(url
, display_id
)
334 data_json
= self
._search
_regex
(r
'window\.__APOLLO_STATE__\s*=\s*(\{.*);\n', webpage
, 'json')
335 data
= self
._parse
_json
(data_json
, display_id
)
339 'display_id': display_id
,
344 for widget
in data
.values():
345 if widget
.get('_geoblocked') is True:
347 if '_duration' in widget
:
348 res
['duration'] = int_or_none(widget
['_duration'])
349 if 'clipTitle' in widget
:
350 res
['title'] = widget
['clipTitle']
351 if '_previewImage' in widget
:
352 res
['thumbnail'] = widget
['_previewImage']
353 if 'broadcastedOn' in widget
:
354 res
['timestamp'] = unified_timestamp(widget
['broadcastedOn'])
355 if 'synopsis' in widget
:
356 res
['description'] = widget
['synopsis']
357 subtitle_url
= url_or_none(widget
.get('_subtitleUrl'))
359 subtitles
.setdefault('de', []).append({
363 if '_quality' in widget
:
364 format_url
= url_or_none(try_get(
365 widget
, lambda x
: x
['_stream']['json'][0]))
368 ext
= determine_ext(format_url
)
370 formats
.extend(self
._extract
_f
4m
_formats
(
371 format_url
+ '?hdcore=3.11.0',
372 video_id
, f4m_id
='hds', fatal
=False))
374 formats
.extend(self
._extract
_m
3u8_formats
(
375 format_url
, video_id
, 'mp4', m3u8_id
='hls',
378 # HTTP formats are not available when geoblocked is True,
379 # other formats are fine though
382 quality
= str_or_none(widget
.get('_quality'))
384 'format_id': ('http-' + quality
) if quality
else 'http',
386 'preference': 10, # Plain HTTP, that's nice
389 if not formats
and geoblocked
:
390 self
.raise_geo_restricted(
391 msg
='This video is not available due to geoblocking',
394 self
._sort
_formats
(formats
)
396 'subtitles': subtitles
,