]>
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
19 from ..compat
import compat_etree_fromstring
22 class ARDMediathekIE(InfoExtractor
):
23 IE_NAME
= 'ARD:mediathek'
24 _VALID_URL
= r
'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de|one\.ard\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
27 # available till 26.07.2022
28 'url': 'http://www.ardmediathek.de/tv/S%C3%9CDLICHT/Was-ist-die-Kunst-der-Zukunft-liebe-Ann/BR-Fernsehen/Video?bcastId=34633636&documentId=44726822',
32 'title': 'Was ist die Kunst der Zukunft, liebe Anna McCarthy?',
33 'description': 'md5:4ada28b3e3b5df01647310e41f3a62f5',
38 'skip_download': True,
41 'url': 'https://one.ard.de/tv/Mord-mit-Aussicht/Mord-mit-Aussicht-6-39-T%C3%B6dliche-Nach/ONE/Video?bcastId=46384294&documentId=55586872',
42 'only_matching': True,
45 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
46 'only_matching': True,
48 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
49 'only_matching': True,
52 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
53 'only_matching': True,
56 def _extract_media_info(self
, media_info_url
, webpage
, video_id
):
57 media_info
= self
._download
_json
(
58 media_info_url
, video_id
, 'Downloading media JSON')
60 formats
= self
._extract
_formats
(media_info
, video_id
)
63 if '"fsk"' in webpage
:
65 'This video is only available after 20:00', expected
=True)
66 elif media_info
.get('_geoblocked'):
67 raise ExtractorError('This video is not available due to geo restriction', expected
=True)
69 self
._sort
_formats
(formats
)
71 duration
= int_or_none(media_info
.get('_duration'))
72 thumbnail
= media_info
.get('_previewImage')
73 is_live
= media_info
.get('_isLive') is True
76 subtitle_url
= media_info
.get('_subtitleUrl')
86 'thumbnail': thumbnail
,
89 'subtitles': subtitles
,
92 def _extract_formats(self
, media_info
, video_id
):
93 type_
= media_info
.get('_type')
94 media_array
= media_info
.get('_mediaArray', [])
96 for num
, media
in enumerate(media_array
):
97 for stream
in media
.get('_mediaStreamArray', []):
98 stream_urls
= stream
.get('_stream')
101 if not isinstance(stream_urls
, list):
102 stream_urls
= [stream_urls
]
103 quality
= stream
.get('_quality')
104 server
= stream
.get('_server')
105 for stream_url
in stream_urls
:
106 if not url_or_none(stream_url
):
108 ext
= determine_ext(stream_url
)
109 if quality
!= 'auto' and ext
in ('f4m', 'm3u8'):
112 formats
.extend(self
._extract
_f
4m
_formats
(
113 update_url_query(stream_url
, {
115 'plugin': 'aasp-3.1.1.69.124'
117 video_id
, f4m_id
='hds', fatal
=False))
119 formats
.extend(self
._extract
_m
3u8_formats
(
120 stream_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
122 if server
and server
.startswith('rtmp'):
125 'play_path': stream_url
,
126 'format_id': 'a%s-rtmp-%s' % (num
, quality
),
131 'format_id': 'a%s-%s-%s' % (num
, ext
, quality
)
133 m
= re
.search(r
'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url
)
136 'width': int(m
.group('width')),
137 'height': int(m
.group('height')),
144 def _real_extract(self
, url
):
145 # determine video id from url
146 m
= re
.match(self
._VALID
_URL
, url
)
150 numid
= re
.search(r
'documentId=([0-9]+)', url
)
152 document_id
= video_id
= numid
.group(1)
154 video_id
= m
.group('video_id')
156 webpage
= self
._download
_webpage
(url
, video_id
)
159 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
160 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
161 'Video %s is no longer available'),
164 for pattern
, message
in ERRORS
:
165 if pattern
in webpage
:
166 raise ExtractorError(message
% video_id
, expected
=True)
168 if re
.search(r
'[\?&]rss($|[=&])', url
):
169 doc
= compat_etree_fromstring(webpage
.encode('utf-8'))
171 return GenericIE()._extract
_rss
(url
, video_id
, doc
)
173 title
= self
._html
_search
_regex
(
174 [r
'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
175 r
'<meta name="dcterms\.title" content="(.*?)"/>',
176 r
'<h4 class="headline">(.*?)</h4>'],
178 description
= self
._html
_search
_meta
(
179 'dcterms.abstract', webpage
, 'description', default
=None)
180 if description
is None:
181 description
= self
._html
_search
_meta
(
182 'description', webpage
, 'meta description')
184 # Thumbnail is sometimes not present.
185 # It is in the mobile version, but that seems to use a different URL
186 # structure altogether.
187 thumbnail
= self
._og
_search
_thumbnail
(webpage
, default
=None)
189 media_streams
= re
.findall(r
'''(?x)
190 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
191 "([^"]+)"''', webpage
)
194 QUALITIES
= qualities(['lo', 'hi', 'hq'])
196 for furl
in set(media_streams
):
197 if furl
.endswith('.f4m'):
200 fid_m
= re
.match(r
'.*\.([^.]+)\.[^.]+$', furl
)
201 fid
= fid_m
.group(1) if fid_m
else None
203 'quality': QUALITIES(fid
),
207 self
._sort
_formats
(formats
)
211 else: # request JSON file
213 video_id
= self
._search
_regex
(
214 r
'/play/(?:config|media)/(\d+)', webpage
, 'media id')
215 info
= self
._extract
_media
_info
(
216 'http://www.ardmediathek.de/play/media/%s' % video_id
,
221 'title': self
._live
_title
(title
) if info
.get('is_live') else title
,
222 'description': description
,
223 'thumbnail': thumbnail
,
229 class ARDIE(InfoExtractor
):
230 _VALID_URL
= r
'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
232 # available till 14.02.2019
233 'url': 'http://www.daserste.de/information/talk/maischberger/videos/das-groko-drama-zerlegen-sich-die-volksparteien-video-102.html',
234 'md5': '8e4ec85f31be7c7fc08a26cdbc5a1f49',
236 'display_id': 'das-groko-drama-zerlegen-sich-die-volksparteien-video',
240 'title': 'Das GroKo-Drama: Zerlegen sich die Volksparteien?',
241 'upload_date': '20180214',
242 'thumbnail': r
're:^https?://.*\.jpg$',
245 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
246 'only_matching': True,
249 def _real_extract(self
, url
):
250 mobj
= re
.match(self
._VALID
_URL
, url
)
251 display_id
= mobj
.group('display_id')
253 player_url
= mobj
.group('mainurl') + '~playerXml.xml'
254 doc
= self
._download
_xml
(player_url
, display_id
)
255 video_node
= doc
.find('./video')
256 upload_date
= unified_strdate(xpath_text(
257 video_node
, './broadcastDate'))
258 thumbnail
= xpath_text(video_node
, './/teaserImage//variant/url')
261 for a
in video_node
.findall('.//asset'):
263 'format_id': a
.attrib
['type'],
264 'width': int_or_none(a
.find('./frameWidth').text
),
265 'height': int_or_none(a
.find('./frameHeight').text
),
266 'vbr': int_or_none(a
.find('./bitrateVideo').text
),
267 'abr': int_or_none(a
.find('./bitrateAudio').text
),
268 'vcodec': a
.find('./codecVideo').text
,
269 'tbr': int_or_none(a
.find('./totalBitrate').text
),
271 if a
.find('./serverPrefix').text
:
272 f
['url'] = a
.find('./serverPrefix').text
273 f
['playpath'] = a
.find('./fileName').text
275 f
['url'] = a
.find('./fileName').text
277 self
._sort
_formats
(formats
)
280 'id': mobj
.group('id'),
282 'display_id': display_id
,
283 'title': video_node
.find('./title').text
,
284 'duration': parse_duration(video_node
.find('./duration').text
),
285 'upload_date': upload_date
,
286 'thumbnail': thumbnail
,
290 class ARDBetaMediathekIE(InfoExtractor
):
291 _VALID_URL
= r
'https://beta\.ardmediathek\.de/[a-z]+/player/(?P<video_id>[a-zA-Z0-9]+)/(?P<display_id>[^/?#]+)'
293 'url': 'https://beta.ardmediathek.de/ard/player/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE/die-robuste-roswita',
294 'md5': '2d02d996156ea3c397cfc5036b5d7f8f',
296 'display_id': 'die-robuste-roswita',
297 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
298 'title': 'Tatort: Die robuste Roswita',
299 'description': r
're:^Der Mord.*trüber ist als die Ilm.',
301 'thumbnail': 'https://img.ardmediathek.de/standard/00/55/43/59/34/-1774185891/16x9/960?mandant=ard',
302 'upload_date': '20180826',
307 def _real_extract(self
, url
):
308 mobj
= re
.match(self
._VALID
_URL
, url
)
309 video_id
= mobj
.group('video_id')
310 display_id
= mobj
.group('display_id')
312 webpage
= self
._download
_webpage
(url
, display_id
)
313 data_json
= self
._search
_regex
(r
'window\.__APOLLO_STATE__\s*=\s*(\{.*);\n', webpage
, 'json')
314 data
= self
._parse
_json
(data_json
, display_id
)
318 'display_id': display_id
,
321 for widget
in data
.values():
322 if widget
.get('_geoblocked'):
323 raise ExtractorError('This video is not available due to geoblocking', expected
=True)
325 if '_duration' in widget
:
326 res
['duration'] = widget
['_duration']
327 if 'clipTitle' in widget
:
328 res
['title'] = widget
['clipTitle']
329 if '_previewImage' in widget
:
330 res
['thumbnail'] = widget
['_previewImage']
331 if 'broadcastedOn' in widget
:
332 res
['upload_date'] = unified_strdate(widget
['broadcastedOn'])
333 if 'synopsis' in widget
:
334 res
['description'] = widget
['synopsis']
335 if '_subtitleUrl' in widget
:
336 res
['subtitles'] = {'de': [{
338 'url': widget
['_subtitleUrl'],
340 if '_quality' in widget
:
341 format_url
= widget
['_stream']['json'][0]
343 if format_url
.endswith('.f4m'):
344 formats
.extend(self
._extract
_f
4m
_formats
(
345 format_url
+ '?hdcore=3.11.0',
346 video_id
, f4m_id
='hds', fatal
=False))
347 elif format_url
.endswith('m3u8'):
348 formats
.extend(self
._extract
_m
3u8_formats
(
349 format_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
352 'format_id': 'http-' + widget
['_quality'],
354 'preference': 10, # Plain HTTP, that's nice
357 self
._sort
_formats
(formats
)
358 res
['formats'] = formats