2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_urlparse
,
14 get_element_by_attribute
,
20 # There are different sources of video in arte.tv, the extraction process
21 # is different for each one. The videos usually expire in 7 days, so we can't
25 class ArteTvIE(InfoExtractor
):
26 _VALID_URL
= r
'https?://videos\.arte\.tv/(?P<lang>fr|de|en|es)/.*-(?P<id>.*?)\.html'
29 def _real_extract(self
, url
):
30 mobj
= re
.match(self
._VALID
_URL
, url
)
31 lang
= mobj
.group('lang')
32 video_id
= mobj
.group('id')
34 ref_xml_url
= url
.replace('/videos/', '/do_delegate/videos/')
35 ref_xml_url
= ref_xml_url
.replace('.html', ',view,asPlayerXml.xml')
36 ref_xml_doc
= self
._download
_xml
(
37 ref_xml_url
, video_id
, note
='Downloading metadata')
38 config_node
= find_xpath_attr(ref_xml_doc
, './/video', 'lang', lang
)
39 config_xml_url
= config_node
.attrib
['ref']
40 config
= self
._download
_xml
(
41 config_xml_url
, video_id
, note
='Downloading configuration')
44 'format_id': q
.attrib
['quality'],
45 # The playpath starts at 'mp4:', if we don't manually
46 # split the url, rtmpdump will incorrectly parse them
47 'url': q
.text
.split('mp4:', 1)[0],
48 'play_path': 'mp4:' + q
.text
.split('mp4:', 1)[1],
50 'quality': 2 if q
.attrib
['quality'] == 'hd' else 1,
51 } for q
in config
.findall('./urls/url')]
52 self
._sort
_formats
(formats
)
54 title
= config
.find('.//name').text
55 thumbnail
= config
.find('.//firstThumbnailUrl').text
59 'thumbnail': thumbnail
,
64 class ArteTVBaseIE(InfoExtractor
):
66 def _extract_url_info(cls
, url
):
67 mobj
= re
.match(cls
._VALID
_URL
, url
)
68 lang
= mobj
.group('lang')
69 query
= compat_parse_qs(compat_urllib_parse_urlparse(url
).query
)
71 video_id
= query
['vid'][0]
73 # This is not a real id, it can be for example AJT for the news
74 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
75 video_id
= mobj
.group('id')
78 def _extract_from_json_url(self
, json_url
, video_id
, lang
, title
=None):
79 info
= self
._download
_json
(json_url
, video_id
)
80 player_info
= info
['videoJsonPlayer']
82 upload_date_str
= player_info
.get('shootingDate')
83 if not upload_date_str
:
84 upload_date_str
= (player_info
.get('VRA') or player_info
.get('VDA') or '').split(' ')[0]
86 title
= (player_info
.get('VTI') or title
or player_info
['VID']).strip()
87 subtitle
= player_info
.get('VSU', '').strip()
89 title
+= ' - %s' % subtitle
92 'id': player_info
['VID'],
94 'description': player_info
.get('VDE'),
95 'upload_date': unified_strdate(upload_date_str
),
96 'thumbnail': player_info
.get('programImage') or player_info
.get('VTU', {}).get('IUR'),
98 qfunc
= qualities(['HQ', 'MQ', 'EQ', 'SQ'])
107 langcode
= LANGS
.get(lang
, lang
)
110 for format_id
, format_dict
in player_info
['VSR'].items():
111 f
= dict(format_dict
)
112 versionCode
= f
.get('versionCode')
113 l
= re
.escape(langcode
)
115 # Language preference from most to least priority
116 # Reference: section 5.6.3 of
117 # http://www.arte.tv/sites/en/corporate/files/complete-technical-guidelines-arte-geie-v1-05.pdf
119 # original version in requested language, without subtitles
121 # original version in requested language, with partial subtitles in requested language
122 r
'VO{0}-ST{0}$'.format(l
),
123 # original version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
124 r
'VO{0}-STM{0}$'.format(l
),
125 # non-original (dubbed) version in requested language, without subtitles
127 # non-original (dubbed) version in requested language, with subtitles partial subtitles in requested language
128 r
'V{0}-ST{0}$'.format(l
),
129 # non-original (dubbed) version in requested language, with subtitles for the deaf and hard-of-hearing in requested language
130 r
'V{0}-STM{0}$'.format(l
),
131 # original version in requested language, with partial subtitles in different language
132 r
'VO{0}-ST(?!{0}).+?$'.format(l
),
133 # original version in requested language, with subtitles for the deaf and hard-of-hearing in different language
134 r
'VO{0}-STM(?!{0}).+?$'.format(l
),
135 # original version in different language, with partial subtitles in requested language
136 r
'VO(?:(?!{0}).+?)?-ST{0}$'.format(l
),
137 # original version in different language, with subtitles for the deaf and hard-of-hearing in requested language
138 r
'VO(?:(?!{0}).+?)?-STM{0}$'.format(l
),
139 # original version in different language, without subtitles
140 r
'VO(?:(?!{0}))?$'.format(l
),
141 # original version in different language, with partial subtitles in different language
142 r
'VO(?:(?!{0}).+?)?-ST(?!{0}).+?$'.format(l
),
143 # original version in different language, with subtitles for the deaf and hard-of-hearing in different language
144 r
'VO(?:(?!{0}).+?)?-STM(?!{0}).+?$'.format(l
),
147 for pref
, p
in enumerate(PREFERENCES
):
148 if re
.match(p
, versionCode
):
149 lang_pref
= len(PREFERENCES
) - pref
155 'format_id': format_id
,
156 'preference': -10 if f
.get('videoFormat') == 'M3U8' else None,
157 'language_preference': lang_pref
,
158 'format_note': '%s, %s' % (f
.get('versionCode'), f
.get('versionLibelle')),
159 'width': int_or_none(f
.get('width')),
160 'height': int_or_none(f
.get('height')),
161 'tbr': int_or_none(f
.get('bitrate')),
162 'quality': qfunc(f
.get('quality')),
165 if f
.get('mediaType') == 'rtmp':
166 format
['url'] = f
['streamer']
167 format
['play_path'] = 'mp4:' + f
['url']
168 format
['ext'] = 'flv'
170 format
['url'] = f
['url']
172 formats
.append(format
)
174 self
._check
_formats
(formats
, video_id
)
175 self
._sort
_formats
(formats
)
177 info_dict
['formats'] = formats
181 class ArteTVPlus7IE(ArteTVBaseIE
):
182 IE_NAME
= 'arte.tv:+7'
183 _VALID_URL
= r
'https?://(?:(?:www|sites)\.)?arte\.tv/(?:[^/]+/)?(?P<lang>fr|de|en|es)/(?:videos/)?(?:[^/]+/)*(?P<id>[^/?#&]+)'
186 'url': 'http://www.arte.tv/guide/de/sendungen/XEN/xenius/?vid=055918-015_PLUS7-D',
187 'only_matching': True,
189 'url': 'http://sites.arte.tv/karambolage/de/video/karambolage-22',
190 'only_matching': True,
192 'url': 'http://www.arte.tv/de/videos/048696-000-A/der-kluge-bauch-unser-zweites-gehirn',
193 'only_matching': True,
197 def suitable(cls
, url
):
198 return False if ArteTVPlaylistIE
.suitable(url
) else super(ArteTVPlus7IE
, cls
).suitable(url
)
200 def _real_extract(self
, url
):
201 video_id
, lang
= self
._extract
_url
_info
(url
)
202 webpage
= self
._download
_webpage
(url
, video_id
)
203 return self
._extract
_from
_webpage
(webpage
, video_id
, lang
)
205 def _extract_from_webpage(self
, webpage
, video_id
, lang
):
206 patterns_templates
= (r
'arte_vp_url=["\'](.*?
%s.*?
)["\']', r'data-url=["\']([^
"]+%s[^"]+)["\']')
208 # some pages contain multiple videos (like
209 # http://www.arte.tv/guide/de/sendungen/XEN/xenius/?vid=055918-015_PLUS7-D),
210 # so we first try to look for json URLs that contain the video id from
211 # the 'vid' parameter.
212 patterns = [t % re.escape(_id) for _id in ids for t in patterns_templates]
213 json_url = self._html_search_regex(
214 patterns, webpage, 'json vp url', default=None)
216 def find_iframe_url(webpage, default=NO_DEFAULT):
217 return self._html_search_regex(
218 r'<iframe[^>]+src=(["\'])(?P
<url
>.+\bjson
_url
=.+?
)\
1',
219 webpage, 'iframe url
', group='url
', default=default)
221 iframe_url = find_iframe_url(webpage, None)
223 embed_url = self._html_search_regex(
224 r'arte_vp_url_oembed
=\'([^
\']+?
)\'', webpage, 'embed url
', default=None)
226 player = self._download_json(
227 embed_url, video_id, 'Downloading player page
')
228 iframe_url = find_iframe_url(player['html
'])
229 # en and es URLs produce react-based pages with different layout (e.g.
230 # http://www.arte.tv/guide/en/053330-002-A/carnival-italy?zone=world)
232 program = self._search_regex(
233 r'program\s
*:\s
*({.+?
["\']embed_html["\'].+?
}),?\s
*\n',
234 webpage, 'program
', default=None)
236 embed_html = self._parse_json(program, video_id)
238 iframe_url = find_iframe_url(embed_html['embed_html
'])
240 json_url = compat_parse_qs(
241 compat_urllib_parse_urlparse(iframe_url).query)['json_url
'][0]
243 title = self._search_regex(
244 r'<h3
[^
>]+title
=(["\'])(?P<title>.+?)\1',
245 webpage, 'title', default=None, group='title')
246 return self._extract_from_json_url(json_url, video_id, lang, title=title)
247 # Different kind of embed URL (e.g.
248 # http://www.arte.tv/magazine/trepalium/fr/episode-0406-replay-trepalium)
251 for _, url in re.findall(r'<iframe[^>]+src=(["\'])(?P
<url
>.+?
)\
1', webpage)]
252 return self.playlist_result(entries)
255 # It also uses the arte_vp_url url from the webpage to extract the information
256 class ArteTVCreativeIE(ArteTVPlus7IE):
257 IE_NAME = 'arte
.tv
:creative
'
258 _VALID_URL = r'https?
://creative\
.arte\
.tv
/(?P
<lang
>fr|de|en|es
)/(?
:[^
/]+/)*(?P
<id>[^
/?
#&]+)'
261 'url': 'http://creative.arte.tv/fr/episode/osmosis-episode-1',
263 'id': '057405-001-A',
265 'title': 'OSMOSIS - N\'AYEZ PLUS PEUR D\'AIMER (1)',
266 'upload_date': '20150716',
269 'url': 'http://creative.arte.tv/fr/Monty-Python-Reunion',
270 'playlist_count': 11,
271 'add_ie': ['Youtube'],
273 'url': 'http://creative.arte.tv/de/episode/agentur-amateur-4-der-erste-kunde',
274 'only_matching': True,
278 class ArteTVInfoIE(ArteTVPlus7IE
):
279 IE_NAME
= 'arte.tv:info'
280 _VALID_URL
= r
'https?://info\.arte\.tv/(?P<lang>fr|de|en|es)/(?:[^/]+/)*(?P<id>[^/?#&]+)'
283 'url': 'http://info.arte.tv/fr/service-civique-un-cache-misere',
285 'id': '067528-000-A',
287 'title': 'Service civique, un cache misère ?',
288 'upload_date': '20160403',
293 class ArteTVFutureIE(ArteTVPlus7IE
):
294 IE_NAME
= 'arte.tv:future'
295 _VALID_URL
= r
'https?://future\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)'
298 'url': 'http://future.arte.tv/fr/info-sciences/les-ecrevisses-aussi-sont-anxieuses',
300 'id': '050940-028-A',
302 'title': 'Les écrevisses aussi peuvent être anxieuses',
303 'upload_date': '20140902',
306 'url': 'http://future.arte.tv/fr/la-science-est-elle-responsable',
307 'only_matching': True,
311 class ArteTVDDCIE(ArteTVPlus7IE
):
312 IE_NAME
= 'arte.tv:ddc'
313 _VALID_URL
= r
'https?://ddc\.arte\.tv/(?P<lang>emission|folge)/(?P<id>[^/?#&]+)'
317 def _real_extract(self
, url
):
318 video_id
, lang
= self
._extract
_url
_info
(url
)
321 elif lang
== 'emission':
323 webpage
= self
._download
_webpage
(url
, video_id
)
324 scriptElement
= get_element_by_attribute('class', 'visu_video_block', webpage
)
325 script_url
= self
._html
_search
_regex
(r
'src="(.*?)"', scriptElement
, 'script url')
326 javascriptPlayerGenerator
= self
._download
_webpage
(script_url
, video_id
, 'Download javascript player generator')
327 json_url
= self
._search
_regex
(r
"json_url=(.*)&rendering_place.*", javascriptPlayerGenerator
, 'json url')
328 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)
331 class ArteTVConcertIE(ArteTVPlus7IE
):
332 IE_NAME
= 'arte.tv:concert'
333 _VALID_URL
= r
'https?://concert\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)'
336 'url': 'http://concert.arte.tv/de/notwist-im-pariser-konzertclub-divan-du-monde',
337 'md5': '9ea035b7bd69696b67aa2ccaaa218161',
341 'title': 'The Notwist im Pariser Konzertclub "Divan du Monde"',
342 'upload_date': '20140128',
343 'description': 'md5:486eb08f991552ade77439fe6d82c305',
348 class ArteTVCinemaIE(ArteTVPlus7IE
):
349 IE_NAME
= 'arte.tv:cinema'
350 _VALID_URL
= r
'https?://cinema\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>.+)'
353 'url': 'http://cinema.arte.tv/fr/article/les-ailes-du-desir-de-julia-reck',
354 'md5': 'a5b9dd5575a11d93daf0e3f404f45438',
356 'id': '062494-000-A',
358 'title': 'Film lauréat du concours web - "Les ailes du désir" de Julia Reck',
359 'upload_date': '20150807',
364 class ArteTVMagazineIE(ArteTVPlus7IE
):
365 IE_NAME
= 'arte.tv:magazine'
366 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/magazine/[^/]+/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)'
369 # Embedded via <iframe src="http://www.arte.tv/arte_vp/index.php?json_url=..."
370 'url': 'http://www.arte.tv/magazine/trepalium/fr/entretien-avec-le-realisateur-vincent-lannoo-trepalium',
371 'md5': '2a9369bcccf847d1c741e51416299f25',
373 'id': '065965-000-A',
375 'title': 'Trepalium - Extrait Ep.01',
376 'upload_date': '20160121',
379 # Embedded via <iframe src="http://www.arte.tv/guide/fr/embed/054813-004-A/medium"
380 'url': 'http://www.arte.tv/magazine/trepalium/fr/episode-0406-replay-trepalium',
381 'md5': 'fedc64fc7a946110fe311634e79782ca',
383 'id': '054813-004_PLUS7-F',
385 'title': 'Trepalium (4/6)',
386 'description': 'md5:10057003c34d54e95350be4f9b05cb40',
387 'upload_date': '20160218',
390 'url': 'http://www.arte.tv/magazine/metropolis/de/frank-woeste-german-paris-metropolis',
391 'only_matching': True,
395 class ArteTVEmbedIE(ArteTVPlus7IE
):
396 IE_NAME
= 'arte.tv:embed'
397 _VALID_URL
= r
'''(?x)
399 /(?:playerv2/embed|arte_vp/index)\.php\?json_url=
401 http://arte\.tv/papi/tvguide/videos/stream/player/
402 (?P<lang>[^/]+)/(?P<id>[^/]+)[^&]*
408 def _real_extract(self
, url
):
409 mobj
= re
.match(self
._VALID
_URL
, url
)
410 video_id
= mobj
.group('id')
411 lang
= mobj
.group('lang')
412 json_url
= mobj
.group('json_url')
413 return self
._extract
_from
_json
_url
(json_url
, video_id
, lang
)
416 class TheOperaPlatformIE(ArteTVPlus7IE
):
417 IE_NAME
= 'theoperaplatform'
418 _VALID_URL
= r
'https?://(?:www\.)?theoperaplatform\.eu/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)'
421 'url': 'http://www.theoperaplatform.eu/de/opera/verdi-otello',
422 'md5': '970655901fa2e82e04c00b955e9afe7b',
424 'id': '060338-009-A',
426 'title': 'Verdi - OTELLO',
427 'upload_date': '20160927',
432 class ArteTVPlaylistIE(ArteTVBaseIE
):
433 IE_NAME
= 'arte.tv:playlist'
434 _VALID_URL
= r
'https?://(?:www\.)?arte\.tv/guide/(?P<lang>fr|de|en|es)/[^#]*#collection/(?P<id>PL-\d+)'
437 'url': 'http://www.arte.tv/guide/de/plus7/?country=DE#collection/PL-013263/ARTETV',
440 'title': 'Areva & Uramin',
441 'description': 'md5:a1dc0312ce357c262259139cfd48c9bf',
443 'playlist_mincount': 6,
445 'url': 'http://www.arte.tv/guide/de/playlists?country=DE#collection/PL-013190/ARTETV',
446 'only_matching': True,
449 def _real_extract(self
, url
):
450 playlist_id
, lang
= self
._extract
_url
_info
(url
)
451 collection
= self
._download
_json
(
452 'https://api.arte.tv/api/player/v1/collectionData/%s/%s?source=videos'
453 % (lang
, playlist_id
), playlist_id
)
454 title
= collection
.get('title')
455 description
= collection
.get('shortDescription') or collection
.get('teaserText')
457 self
._extract
_from
_json
_url
(
458 video
['jsonUrl'], video
.get('programId') or playlist_id
, lang
)
459 for video
in collection
['videos'] if video
.get('jsonUrl')]
460 return self
.playlist_result(entries
, playlist_id
, title
, description
)