]>
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
8 from ..compat
import compat_str
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)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
27 'url': 'http://www.ardmediathek.de/tv/Dokumentation-und-Reportage/Ich-liebe-das-Leben-trotzdem/rbb-Fernsehen/Video?documentId=29582122&bcastId=3822114',
31 'title': 'Ich liebe das Leben trotzdem',
32 'description': 'md5:45e4c225c72b27993314b31a84a5261c',
37 'skip_download': True,
39 'skip': 'HTTP Error 404: Not Found',
41 'url': 'http://www.ardmediathek.de/tv/Tatort/Tatort-Scheinwelten-H%C3%B6rfassung-Video/Das-Erste/Video?documentId=29522730&bcastId=602916',
42 'md5': 'f4d98b10759ac06c0072bbcd1f0b9e3e',
46 'title': 'Tatort: Scheinwelten - Hörfassung (Video tgl. ab 20 Uhr)',
47 'description': 'md5:196392e79876d0ac94c94e8cdb2875f1',
50 'skip': 'HTTP Error 404: Not Found',
53 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
54 'md5': '219d94d8980b4f538c7fcb0865eb7f2c',
58 'title': 'Tod eines Fußballers',
59 'description': 'md5:f6e39f3461f0e1f54bfa48c8875c86ef',
62 'skip': 'HTTP Error 404: Not Found',
64 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
65 'only_matching': True,
68 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
69 'md5': '4e8f00631aac0395fee17368ac0e9867',
73 'title': 'Vor dem Fest',
74 'description': 'md5:c0c1c8048514deaed2a73b3a60eecacb',
77 'skip': 'Video is no longer available',
80 def _extract_media_info(self
, media_info_url
, webpage
, video_id
):
81 media_info
= self
._download
_json
(
82 media_info_url
, video_id
, 'Downloading media JSON')
84 formats
= self
._extract
_formats
(media_info
, video_id
)
87 if '"fsk"' in webpage
:
89 'This video is only available after 20:00', expected
=True)
90 elif media_info
.get('_geoblocked'):
91 raise ExtractorError('This video is not available due to geo restriction', expected
=True)
93 self
._sort
_formats
(formats
)
95 duration
= int_or_none(media_info
.get('_duration'))
96 thumbnail
= media_info
.get('_previewImage')
97 is_live
= media_info
.get('_isLive') is True
100 subtitle_url
= media_info
.get('_subtitleUrl')
109 'duration': duration
,
110 'thumbnail': thumbnail
,
113 'subtitles': subtitles
,
116 def _extract_formats(self
, media_info
, video_id
):
117 type_
= media_info
.get('_type')
118 media_array
= media_info
.get('_mediaArray', [])
120 for num
, media
in enumerate(media_array
):
121 for stream
in media
.get('_mediaStreamArray', []):
122 stream_urls
= stream
.get('_stream')
125 if not isinstance(stream_urls
, list):
126 stream_urls
= [stream_urls
]
127 quality
= stream
.get('_quality')
128 server
= stream
.get('_server')
129 for stream_url
in stream_urls
:
130 if not isinstance(stream_url
, compat_str
) or '//' not in stream_url
:
132 ext
= determine_ext(stream_url
)
133 if quality
!= 'auto' and ext
in ('f4m', 'm3u8'):
136 formats
.extend(self
._extract
_f
4m
_formats
(
137 update_url_query(stream_url
, {
139 'plugin': 'aasp-3.1.1.69.124'
141 video_id
, f4m_id
='hds', fatal
=False))
143 formats
.extend(self
._extract
_m
3u8_formats
(
144 stream_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
146 if server
and server
.startswith('rtmp'):
149 'play_path': stream_url
,
150 'format_id': 'a%s-rtmp-%s' % (num
, quality
),
155 'format_id': 'a%s-%s-%s' % (num
, ext
, quality
)
157 m
= re
.search(r
'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url
)
160 'width': int(m
.group('width')),
161 'height': int(m
.group('height')),
168 def _real_extract(self
, url
):
169 # determine video id from url
170 m
= re
.match(self
._VALID
_URL
, url
)
174 numid
= re
.search(r
'documentId=([0-9]+)', url
)
176 document_id
= video_id
= numid
.group(1)
178 video_id
= m
.group('video_id')
180 webpage
= self
._download
_webpage
(url
, video_id
)
183 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
184 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
185 'Video %s is no longer available'),
188 for pattern
, message
in ERRORS
:
189 if pattern
in webpage
:
190 raise ExtractorError(message
% video_id
, expected
=True)
192 if re
.search(r
'[\?&]rss($|[=&])', url
):
193 doc
= compat_etree_fromstring(webpage
.encode('utf-8'))
195 return GenericIE()._extract
_rss
(url
, video_id
, doc
)
197 title
= self
._html
_search
_regex
(
198 [r
'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
199 r
'<meta name="dcterms\.title" content="(.*?)"/>',
200 r
'<h4 class="headline">(.*?)</h4>'],
202 description
= self
._html
_search
_meta
(
203 'dcterms.abstract', webpage
, 'description', default
=None)
204 if description
is None:
205 description
= self
._html
_search
_meta
(
206 'description', webpage
, 'meta description')
208 # Thumbnail is sometimes not present.
209 # It is in the mobile version, but that seems to use a different URL
210 # structure altogether.
211 thumbnail
= self
._og
_search
_thumbnail
(webpage
, default
=None)
213 media_streams
= re
.findall(r
'''(?x)
214 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
215 "([^"]+)"''', webpage
)
218 QUALITIES
= qualities(['lo', 'hi', 'hq'])
220 for furl
in set(media_streams
):
221 if furl
.endswith('.f4m'):
224 fid_m
= re
.match(r
'.*\.([^.]+)\.[^.]+$', furl
)
225 fid
= fid_m
.group(1) if fid_m
else None
227 'quality': QUALITIES(fid
),
231 self
._sort
_formats
(formats
)
235 else: # request JSON file
237 video_id
= self
._search
_regex
(
238 r
'/play/(?:config|media)/(\d+)', webpage
, 'media id')
239 info
= self
._extract
_media
_info
(
240 'http://www.ardmediathek.de/play/media/%s' % video_id
,
245 'title': self
._live
_title
(title
) if info
.get('is_live') else title
,
246 'description': description
,
247 'thumbnail': thumbnail
,
253 class ARDIE(InfoExtractor
):
254 _VALID_URL
= r
'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
256 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
257 'md5': 'd216c3a86493f9322545e045ddc3eb35',
259 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
263 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
264 'upload_date': '20140804',
265 'thumbnail': r
're:^https?://.*\.jpg$',
267 'skip': 'HTTP Error 404: Not Found',
270 def _real_extract(self
, url
):
271 mobj
= re
.match(self
._VALID
_URL
, url
)
272 display_id
= mobj
.group('display_id')
274 player_url
= mobj
.group('mainurl') + '~playerXml.xml'
275 doc
= self
._download
_xml
(player_url
, display_id
)
276 video_node
= doc
.find('./video')
277 upload_date
= unified_strdate(xpath_text(
278 video_node
, './broadcastDate'))
279 thumbnail
= xpath_text(video_node
, './/teaserImage//variant/url')
282 for a
in video_node
.findall('.//asset'):
284 'format_id': a
.attrib
['type'],
285 'width': int_or_none(a
.find('./frameWidth').text
),
286 'height': int_or_none(a
.find('./frameHeight').text
),
287 'vbr': int_or_none(a
.find('./bitrateVideo').text
),
288 'abr': int_or_none(a
.find('./bitrateAudio').text
),
289 'vcodec': a
.find('./codecVideo').text
,
290 'tbr': int_or_none(a
.find('./totalBitrate').text
),
292 if a
.find('./serverPrefix').text
:
293 f
['url'] = a
.find('./serverPrefix').text
294 f
['playpath'] = a
.find('./fileName').text
296 f
['url'] = a
.find('./fileName').text
298 self
._sort
_formats
(formats
)
301 'id': mobj
.group('id'),
303 'display_id': display_id
,
304 'title': video_node
.find('./title').text
,
305 'duration': parse_duration(video_node
.find('./duration').text
),
306 'upload_date': upload_date
,
307 'thumbnail': thumbnail
,