]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ard.py
3f248b14728ab3655a2e17f7b38a95184042d770
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .generic
import GenericIE
18 from ..compat
import compat_etree_fromstring
21 class ARDMediathekIE(InfoExtractor
):
22 IE_NAME
= 'ARD:mediathek'
23 _VALID_URL
= r
'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.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,
38 'skip': 'HTTP Error 404: Not Found',
40 'url': 'http://www.ardmediathek.de/tv/Tatort/Tatort-Scheinwelten-H%C3%B6rfassung-Video/Das-Erste/Video?documentId=29522730&bcastId=602916',
41 'md5': 'f4d98b10759ac06c0072bbcd1f0b9e3e',
45 'title': 'Tatort: Scheinwelten - Hörfassung (Video tgl. ab 20 Uhr)',
46 'description': 'md5:196392e79876d0ac94c94e8cdb2875f1',
49 'skip': 'HTTP Error 404: Not Found',
52 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
53 'md5': '219d94d8980b4f538c7fcb0865eb7f2c',
57 'title': 'Tod eines Fußballers',
58 'description': 'md5:f6e39f3461f0e1f54bfa48c8875c86ef',
61 'skip': 'HTTP Error 404: Not Found',
63 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
64 'only_matching': True,
67 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
68 'md5': '4e8f00631aac0395fee17368ac0e9867',
72 'title': 'Vor dem Fest',
73 'description': 'md5:c0c1c8048514deaed2a73b3a60eecacb',
76 'skip': 'Video is no longer available',
79 def _extract_media_info(self
, media_info_url
, webpage
, video_id
):
80 media_info
= self
._download
_json
(
81 media_info_url
, video_id
, 'Downloading media JSON')
83 formats
= self
._extract
_formats
(media_info
, video_id
)
86 if '"fsk"' in webpage
:
88 'This video is only available after 20:00', expected
=True)
89 elif media_info
.get('_geoblocked'):
90 raise ExtractorError('This video is not available due to geo restriction', expected
=True)
92 self
._sort
_formats
(formats
)
94 duration
= int_or_none(media_info
.get('_duration'))
95 thumbnail
= media_info
.get('_previewImage')
96 is_live
= media_info
.get('_isLive') is True
99 subtitle_url
= media_info
.get('_subtitleUrl')
108 'duration': duration
,
109 'thumbnail': thumbnail
,
112 'subtitles': subtitles
,
115 def _extract_formats(self
, media_info
, video_id
):
116 type_
= media_info
.get('_type')
117 media_array
= media_info
.get('_mediaArray', [])
119 for num
, media
in enumerate(media_array
):
120 for stream
in media
.get('_mediaStreamArray', []):
121 stream_urls
= stream
.get('_stream')
124 if not isinstance(stream_urls
, list):
125 stream_urls
= [stream_urls
]
126 quality
= stream
.get('_quality')
127 server
= stream
.get('_server')
128 for stream_url
in stream_urls
:
129 ext
= determine_ext(stream_url
)
130 if quality
!= 'auto' and ext
in ('f4m', 'm3u8'):
133 formats
.extend(self
._extract
_f
4m
_formats
(
134 update_url_query(stream_url
, {
136 'plugin': 'aasp-3.1.1.69.124'
138 video_id
, f4m_id
='hds', fatal
=False))
140 formats
.extend(self
._extract
_m
3u8_formats
(
141 stream_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
143 if server
and server
.startswith('rtmp'):
146 'play_path': stream_url
,
147 'format_id': 'a%s-rtmp-%s' % (num
, quality
),
149 elif stream_url
.startswith('http'):
152 'format_id': 'a%s-%s-%s' % (num
, ext
, quality
)
156 m
= re
.search(r
'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url
)
159 'width': int(m
.group('width')),
160 'height': int(m
.group('height')),
167 def _real_extract(self
, url
):
168 # determine video id from url
169 m
= re
.match(self
._VALID
_URL
, url
)
173 numid
= re
.search(r
'documentId=([0-9]+)', url
)
175 document_id
= video_id
= numid
.group(1)
177 video_id
= m
.group('video_id')
179 webpage
= self
._download
_webpage
(url
, video_id
)
182 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
183 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
184 'Video %s is no longer available'),
187 for pattern
, message
in ERRORS
:
188 if pattern
in webpage
:
189 raise ExtractorError(message
% video_id
, expected
=True)
191 if re
.search(r
'[\?&]rss($|[=&])', url
):
192 doc
= compat_etree_fromstring(webpage
.encode('utf-8'))
194 return GenericIE()._extract
_rss
(url
, video_id
, doc
)
196 title
= self
._html
_search
_regex
(
197 [r
'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
198 r
'<meta name="dcterms.title" content="(.*?)"/>',
199 r
'<h4 class="headline">(.*?)</h4>'],
201 description
= self
._html
_search
_meta
(
202 'dcterms.abstract', webpage
, 'description', default
=None)
203 if description
is None:
204 description
= self
._html
_search
_meta
(
205 'description', webpage
, 'meta description')
207 # Thumbnail is sometimes not present.
208 # It is in the mobile version, but that seems to use a different URL
209 # structure altogether.
210 thumbnail
= self
._og
_search
_thumbnail
(webpage
, default
=None)
212 media_streams
= re
.findall(r
'''(?x)
213 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
214 "([^"]+)"''', webpage
)
217 QUALITIES
= qualities(['lo', 'hi', 'hq'])
219 for furl
in set(media_streams
):
220 if furl
.endswith('.f4m'):
223 fid_m
= re
.match(r
'.*\.([^.]+)\.[^.]+$', furl
)
224 fid
= fid_m
.group(1) if fid_m
else None
226 'quality': QUALITIES(fid
),
230 self
._sort
_formats
(formats
)
234 else: # request JSON file
236 video_id
= self
._search
_regex
(
237 r
'/play/(?:config|media)/(\d+)', webpage
, 'media id')
238 info
= self
._extract
_media
_info
(
239 'http://www.ardmediathek.de/play/media/%s' % video_id
,
244 'title': self
._live
_title
(title
) if info
.get('is_live') else title
,
245 'description': description
,
246 'thumbnail': thumbnail
,
252 class ARDIE(InfoExtractor
):
253 _VALID_URL
= r
'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
255 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
256 'md5': 'd216c3a86493f9322545e045ddc3eb35',
258 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
262 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
263 'upload_date': '20140804',
264 'thumbnail': r
're:^https?://.*\.jpg$',
266 'skip': 'HTTP Error 404: Not Found',
269 def _real_extract(self
, url
):
270 mobj
= re
.match(self
._VALID
_URL
, url
)
271 display_id
= mobj
.group('display_id')
273 player_url
= mobj
.group('mainurl') + '~playerXml.xml'
274 doc
= self
._download
_xml
(player_url
, display_id
)
275 video_node
= doc
.find('./video')
276 upload_date
= unified_strdate(xpath_text(
277 video_node
, './broadcastDate'))
278 thumbnail
= xpath_text(video_node
, './/teaserImage//variant/url')
281 for a
in video_node
.findall('.//asset'):
283 'format_id': a
.attrib
['type'],
284 'width': int_or_none(a
.find('./frameWidth').text
),
285 'height': int_or_none(a
.find('./frameHeight').text
),
286 'vbr': int_or_none(a
.find('./bitrateVideo').text
),
287 'abr': int_or_none(a
.find('./bitrateAudio').text
),
288 'vcodec': a
.find('./codecVideo').text
,
289 'tbr': int_or_none(a
.find('./totalBitrate').text
),
291 if a
.find('./serverPrefix').text
:
292 f
['url'] = a
.find('./serverPrefix').text
293 f
['playpath'] = a
.find('./fileName').text
295 f
['url'] = a
.find('./fileName').text
297 self
._sort
_formats
(formats
)
300 'id': mobj
.group('id'),
302 'display_id': display_id
,
303 'title': video_node
.find('./title').text
,
304 'duration': parse_duration(video_node
.find('./duration').text
),
305 'upload_date': upload_date
,
306 'thumbnail': thumbnail
,