]>
Commit | Line | Data |
---|---|---|
69a0c470 | 1 | # encoding: utf-8 |
3798eadc PH |
2 | from __future__ import unicode_literals |
3 | ||
d5822b96 | 4 | import re |
d5822b96 PH |
5 | |
6 | from .common import InfoExtractor | |
393ca8c9 S |
7 | from ..compat import ( |
8 | compat_parse_qs, | |
9 | compat_urllib_parse_urlparse, | |
10 | ) | |
d5822b96 | 11 | from ..utils import ( |
df50a412 | 12 | find_xpath_attr, |
d5822b96 | 13 | unified_strdate, |
56a8ab7d | 14 | get_element_by_attribute, |
d24a2b20 | 15 | int_or_none, |
3f7e8750 | 16 | NO_DEFAULT, |
aff2f4f4 | 17 | qualities, |
d5822b96 PH |
18 | ) |
19 | ||
5f6a1245 | 20 | # There are different sources of video in arte.tv, the extraction process |
c40f5cf4 JMF |
21 | # is different for each one. The videos usually expire in 7 days, so we can't |
22 | # add tests. | |
23 | ||
d5822b96 | 24 | |
515bbe4b | 25 | class ArteTvIE(InfoExtractor): |
44b97450 | 26 | _VALID_URL = r'http://videos\.arte\.tv/(?P<lang>fr|de|en|es)/.*-(?P<id>.*?)\.html' |
3798eadc | 27 | IE_NAME = 'arte.tv' |
d5822b96 | 28 | |
d5822b96 | 29 | def _real_extract(self, url): |
7a249480 PH |
30 | mobj = re.match(self._VALID_URL, url) |
31 | lang = mobj.group('lang') | |
32 | video_id = mobj.group('id') | |
33 | ||
8de64cac PH |
34 | ref_xml_url = url.replace('/videos/', '/do_delegate/videos/') |
35 | ref_xml_url = ref_xml_url.replace('.html', ',view,asPlayerXml.xml') | |
a4ff6c47 PH |
36 | ref_xml_doc = self._download_xml( |
37 | ref_xml_url, video_id, note='Downloading metadata') | |
df50a412 | 38 | config_node = find_xpath_attr(ref_xml_doc, './/video', 'lang', lang) |
8de64cac | 39 | config_xml_url = config_node.attrib['ref'] |
878d11ec | 40 | config = self._download_xml( |
a4ff6c47 | 41 | config_xml_url, video_id, note='Downloading configuration') |
37b6a661 | 42 | |
878d11ec | 43 | formats = [{ |
5a184030 | 44 | 'format_id': q.attrib['quality'], |
459af434 JMF |
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], | |
b2799ff9 | 49 | 'ext': 'flv', |
878d11ec | 50 | 'quality': 2 if q.attrib['quality'] == 'hd' else 1, |
b2799ff9 | 51 | } for q in config.findall('./urls/url')] |
878d11ec PH |
52 | self._sort_formats(formats) |
53 | ||
54 | title = config.find('.//name').text | |
55 | thumbnail = config.find('.//firstThumbnailUrl').text | |
56 | return { | |
57 | 'id': video_id, | |
58 | 'title': title, | |
59 | 'thumbnail': thumbnail, | |
7a249480 | 60 | 'formats': formats, |
515bbe4b | 61 | } |
c40f5cf4 JMF |
62 | |
63 | ||
64 | class ArteTVPlus7IE(InfoExtractor): | |
3798eadc | 65 | IE_NAME = 'arte.tv:+7' |
b72f6163 | 66 | _VALID_URL = r'https?://(?:www\.)?arte\.tv/guide/(?P<lang>fr|de|en|es)/(?:(?:sendungen|emissions|embed)/)?(?P<id>[^/]+)/(?P<name>[^/?#&+])' |
c40f5cf4 | 67 | |
69a0c470 JMF |
68 | @classmethod |
69 | def _extract_url_info(cls, url): | |
70 | mobj = re.match(cls._VALID_URL, url) | |
c40f5cf4 | 71 | lang = mobj.group('lang') |
a8f1d167 JMF |
72 | query = compat_parse_qs(compat_urllib_parse_urlparse(url).query) |
73 | if 'vid' in query: | |
74 | video_id = query['vid'][0] | |
75 | else: | |
76 | # This is not a real id, it can be for example AJT for the news | |
77 | # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal | |
78 | video_id = mobj.group('id') | |
69a0c470 | 79 | return video_id, lang |
c40f5cf4 | 80 | |
69a0c470 JMF |
81 | def _real_extract(self, url): |
82 | video_id, lang = self._extract_url_info(url) | |
c40f5cf4 | 83 | webpage = self._download_webpage(url, video_id) |
69a0c470 JMF |
84 | return self._extract_from_webpage(webpage, video_id, lang) |
85 | ||
86 | def _extract_from_webpage(self, webpage, video_id, lang): | |
a8f1d167 JMF |
87 | patterns_templates = (r'arte_vp_url=["\'](.*?%s.*?)["\']', r'data-url=["\']([^"]+%s[^"]+)["\']') |
88 | ids = (video_id, '') | |
89 | # some pages contain multiple videos (like | |
90 | # http://www.arte.tv/guide/de/sendungen/XEN/xenius/?vid=055918-015_PLUS7-D), | |
91 | # so we first try to look for json URLs that contain the video id from | |
92 | # the 'vid' parameter. | |
93 | patterns = [t % re.escape(_id) for _id in ids for t in patterns_templates] | |
88ce273d | 94 | json_url = self._html_search_regex( |
a8f1d167 | 95 | patterns, webpage, 'json vp url', default=None) |
393ca8c9 | 96 | if not json_url: |
3f7e8750 JMF |
97 | def find_iframe_url(webpage, default=NO_DEFAULT): |
98 | return self._html_search_regex( | |
99 | r'<iframe[^>]+src=(["\'])(?P<url>.+\bjson_url=.+?)\1', | |
100 | webpage, 'iframe url', group='url', default=default) | |
101 | ||
102 | iframe_url = find_iframe_url(webpage, None) | |
103 | if not iframe_url: | |
104 | embed_url = self._html_search_regex( | |
9654fc87 S |
105 | r'arte_vp_url_oembed=\'([^\']+?)\'', webpage, 'embed url', default=None) |
106 | if embed_url: | |
107 | player = self._download_json( | |
108 | embed_url, video_id, 'Downloading player page') | |
109 | iframe_url = find_iframe_url(player['html']) | |
110 | # en and es URLs produce react-based pages with different layout (e.g. | |
111 | # http://www.arte.tv/guide/en/053330-002-A/carnival-italy?zone=world) | |
112 | if not iframe_url: | |
305168ca S |
113 | program = self._search_regex( |
114 | r'program\s*:\s*({.+?["\']embed_html["\'].+?}),?\s*\n', | |
115 | webpage, 'program', default=None) | |
116 | if program: | |
117 | embed_html = self._parse_json(program,video_id) | |
118 | if embed_html: | |
119 | iframe_url = find_iframe_url(embed_html['embed_html']) | |
120 | if iframe_url: | |
121 | json_url = compat_parse_qs( | |
122 | compat_urllib_parse_urlparse(iframe_url).query)['json_url'][0] | |
123 | if json_url: | |
124 | return self._extract_from_json_url(json_url, video_id, lang) | |
125 | # Differend kind of embed URL (e.g. | |
126 | # http://www.arte.tv/magazine/trepalium/fr/episode-0406-replay-trepalium) | |
127 | embed_url = self._search_regex( | |
128 | r'<iframe[^>]+src=(["\'])(?P<url>.+?)\1', | |
129 | webpage, 'embed url', group='url') | |
130 | return self.url_result(embed_url) | |
131 | ||
c40f5cf4 | 132 | |
56a8ab7d | 133 | def _extract_from_json_url(self, json_url, video_id, lang): |
893f8832 | 134 | info = self._download_json(json_url, video_id) |
c40f5cf4 JMF |
135 | player_info = info['videoJsonPlayer'] |
136 | ||
99b67fec PH |
137 | upload_date_str = player_info.get('shootingDate') |
138 | if not upload_date_str: | |
8bbd3d14 | 139 | upload_date_str = (player_info.get('VRA') or player_info.get('VDA') or '').split(' ')[0] |
99b67fec | 140 | |
74214d35 S |
141 | title = player_info['VTI'].strip() |
142 | subtitle = player_info.get('VSU', '').strip() | |
143 | if subtitle: | |
144 | title += ' - %s' % subtitle | |
145 | ||
c40f5cf4 JMF |
146 | info_dict = { |
147 | 'id': player_info['VID'], | |
74214d35 | 148 | 'title': title, |
c40f5cf4 | 149 | 'description': player_info.get('VDE'), |
99b67fec | 150 | 'upload_date': unified_strdate(upload_date_str), |
c40f5cf4 JMF |
151 | 'thumbnail': player_info.get('programImage') or player_info.get('VTU', {}).get('IUR'), |
152 | } | |
aff2f4f4 | 153 | qfunc = qualities(['HQ', 'MQ', 'EQ', 'SQ']) |
c40f5cf4 | 154 | |
08d65046 S |
155 | LANGS = { |
156 | 'fr': 'F', | |
157 | 'de': 'A', | |
158 | 'en': 'E[ANG]', | |
159 | 'es': 'E[ESP]', | |
160 | } | |
161 | ||
aff2f4f4 | 162 | formats = [] |
d24a2b20 | 163 | for format_id, format_dict in player_info['VSR'].items(): |
aff2f4f4 PH |
164 | f = dict(format_dict) |
165 | versionCode = f.get('versionCode') | |
08d65046 S |
166 | langcode = LANGS.get(lang, lang) |
167 | lang_rexs = [r'VO?%s-' % re.escape(langcode), r'VO?.-ST%s$' % re.escape(langcode)] | |
168 | lang_pref = None | |
169 | if versionCode: | |
170 | matched_lang_rexs = [r for r in lang_rexs if re.match(r, versionCode)] | |
171 | lang_pref = -10 if not matched_lang_rexs else 10 * len(matched_lang_rexs) | |
aff2f4f4 PH |
172 | source_pref = 0 |
173 | if versionCode is not None: | |
174 | # The original version with subtitles has lower relevance | |
08d65046 | 175 | if re.match(r'VO-ST(F|A|E)', versionCode): |
aff2f4f4 PH |
176 | source_pref -= 10 |
177 | # The version with sourds/mal subtitles has also lower relevance | |
08d65046 | 178 | elif re.match(r'VO?(F|A|E)-STM\1', versionCode): |
aff2f4f4 PH |
179 | source_pref -= 9 |
180 | format = { | |
181 | 'format_id': format_id, | |
182 | 'preference': -10 if f.get('videoFormat') == 'M3U8' else None, | |
183 | 'language_preference': lang_pref, | |
184 | 'format_note': '%s, %s' % (f.get('versionCode'), f.get('versionLibelle')), | |
185 | 'width': int_or_none(f.get('width')), | |
186 | 'height': int_or_none(f.get('height')), | |
187 | 'tbr': int_or_none(f.get('bitrate')), | |
1b7b1d6e | 188 | 'quality': qfunc(f.get('quality')), |
aff2f4f4 | 189 | 'source_preference': source_pref, |
c40f5cf4 | 190 | } |
aff2f4f4 PH |
191 | |
192 | if f.get('mediaType') == 'rtmp': | |
193 | format['url'] = f['streamer'] | |
194 | format['play_path'] = 'mp4:' + f['url'] | |
195 | format['ext'] = 'flv' | |
c40f5cf4 | 196 | else: |
aff2f4f4 PH |
197 | format['url'] = f['url'] |
198 | ||
199 | formats.append(format) | |
200 | ||
c06a9f87 | 201 | self._check_formats(formats, video_id) |
aff2f4f4 | 202 | self._sort_formats(formats) |
c40f5cf4 | 203 | |
aff2f4f4 | 204 | info_dict['formats'] = formats |
c40f5cf4 JMF |
205 | return info_dict |
206 | ||
207 | ||
208 | # It also uses the arte_vp_url url from the webpage to extract the information | |
209 | class ArteTVCreativeIE(ArteTVPlus7IE): | |
3798eadc | 210 | IE_NAME = 'arte.tv:creative' |
d48502b8 | 211 | _VALID_URL = r'https?://creative\.arte\.tv/(?P<lang>fr|de|en|es)/(?:magazine?/)?(?P<id>[^/?#&]+)' |
c40f5cf4 | 212 | |
01d906ff | 213 | _TESTS = [{ |
3798eadc | 214 | 'url': 'http://creative.arte.tv/de/magazin/agentur-amateur-corporate-design', |
3798eadc | 215 | 'info_dict': { |
01d906ff | 216 | 'id': '72176', |
39a743fb | 217 | 'ext': 'mp4', |
01d906ff PH |
218 | 'title': 'Folge 2 - Corporate Design', |
219 | 'upload_date': '20131004', | |
c40f5cf4 | 220 | }, |
01d906ff PH |
221 | }, { |
222 | 'url': 'http://creative.arte.tv/fr/Monty-Python-Reunion', | |
223 | 'info_dict': { | |
224 | 'id': '160676', | |
225 | 'ext': 'mp4', | |
226 | 'title': 'Monty Python live (mostly)', | |
b5f4775b PH |
227 | 'description': 'Événement ! Quarante-cinq ans après leurs premiers succès, les légendaires Monty Python remontent sur scène.\n', |
228 | 'upload_date': '20140805', | |
01d906ff PH |
229 | } |
230 | }] | |
c40f5cf4 | 231 | |
69a0c470 JMF |
232 | |
233 | class ArteTVFutureIE(ArteTVPlus7IE): | |
3798eadc | 234 | IE_NAME = 'arte.tv:future' |
d48502b8 | 235 | _VALID_URL = r'https?://future\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)' |
24114fee | 236 | |
9c54ae33 S |
237 | _TESTS = [{ |
238 | 'url': 'http://future.arte.tv/fr/info-sciences/les-ecrevisses-aussi-sont-anxieuses', | |
239 | 'info_dict': { | |
240 | 'id': '050940-028-A', | |
241 | 'ext': 'mp4', | |
242 | 'title': 'Les écrevisses aussi peuvent être anxieuses', | |
92c5e11b | 243 | 'upload_date': '20140902', |
69a0c470 | 244 | }, |
9c54ae33 S |
245 | }, { |
246 | 'url': 'http://future.arte.tv/fr/la-science-est-elle-responsable', | |
247 | 'only_matching': True, | |
248 | }] | |
56a8ab7d | 249 | |
ac5118bc | 250 | |
56a8ab7d | 251 | class ArteTVDDCIE(ArteTVPlus7IE): |
3798eadc | 252 | IE_NAME = 'arte.tv:ddc' |
d48502b8 | 253 | _VALID_URL = r'https?://ddc\.arte\.tv/(?P<lang>emission|folge)/(?P<id>[^/?#&]+)' |
56a8ab7d | 254 | |
56a8ab7d CD |
255 | def _real_extract(self, url): |
256 | video_id, lang = self._extract_url_info(url) | |
257 | if lang == 'folge': | |
258 | lang = 'de' | |
259 | elif lang == 'emission': | |
260 | lang = 'fr' | |
261 | webpage = self._download_webpage(url, video_id) | |
262 | scriptElement = get_element_by_attribute('class', 'visu_video_block', webpage) | |
263 | script_url = self._html_search_regex(r'src="(.*?)"', scriptElement, 'script url') | |
264 | javascriptPlayerGenerator = self._download_webpage(script_url, video_id, 'Download javascript player generator') | |
265 | json_url = self._search_regex(r"json_url=(.*)&rendering_place.*", javascriptPlayerGenerator, 'json url') | |
266 | return self._extract_from_json_url(json_url, video_id, lang) | |
4966a0b2 JMF |
267 | |
268 | ||
269 | class ArteTVConcertIE(ArteTVPlus7IE): | |
270 | IE_NAME = 'arte.tv:concert' | |
d48502b8 | 271 | _VALID_URL = r'https?://concert\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)' |
4966a0b2 JMF |
272 | |
273 | _TEST = { | |
274 | 'url': 'http://concert.arte.tv/de/notwist-im-pariser-konzertclub-divan-du-monde', | |
275 | 'md5': '9ea035b7bd69696b67aa2ccaaa218161', | |
276 | 'info_dict': { | |
277 | 'id': '186', | |
278 | 'ext': 'mp4', | |
279 | 'title': 'The Notwist im Pariser Konzertclub "Divan du Monde"', | |
280 | 'upload_date': '20140128', | |
a9c2896e | 281 | 'description': 'md5:486eb08f991552ade77439fe6d82c305', |
4966a0b2 JMF |
282 | }, |
283 | } | |
893f8832 PH |
284 | |
285 | ||
4fcd9d14 S |
286 | class ArteTVCinemaIE(ArteTVPlus7IE): |
287 | IE_NAME = 'arte.tv:cinema' | |
44b97450 | 288 | _VALID_URL = r'https?://cinema\.arte\.tv/(?P<lang>fr|de|en|es)/(?P<id>.+)' |
4fcd9d14 S |
289 | |
290 | _TEST = { | |
291 | 'url': 'http://cinema.arte.tv/de/node/38291', | |
292 | 'md5': '6b275511a5107c60bacbeeda368c3aa1', | |
293 | 'info_dict': { | |
294 | 'id': '055876-000_PWA12025-D', | |
295 | 'ext': 'mp4', | |
296 | 'title': 'Tod auf dem Nil', | |
297 | 'upload_date': '20160122', | |
298 | 'description': 'md5:7f749bbb77d800ef2be11d54529b96bc', | |
299 | }, | |
300 | } | |
301 | ||
302 | ||
49625662 TJ |
303 | class ArteTVMagazineIE(ArteTVPlus7IE): |
304 | IE_NAME = 'arte.tv:magazine' | |
479ec54a | 305 | _VALID_URL = r'https?://(?:www\.)?arte\.tv/magazine/[^/]+/(?P<lang>fr|de|en|es)/(?P<id>[^/?#&]+)' |
49625662 TJ |
306 | |
307 | _TESTS = [{ | |
305168ca | 308 | # Embedded via <iframe src="http://www.arte.tv/arte_vp/index.php?json_url=..." |
49625662 | 309 | 'url': 'http://www.arte.tv/magazine/trepalium/fr/entretien-avec-le-realisateur-vincent-lannoo-trepalium', |
0dd046c1 | 310 | 'md5': '2a9369bcccf847d1c741e51416299f25', |
49625662 TJ |
311 | 'info_dict': { |
312 | 'id': '065965-000-A', | |
313 | 'ext': 'mp4', | |
314 | 'title': 'Trepalium - Extrait Ep.01', | |
0dd046c1 | 315 | 'upload_date': '20160121', |
49625662 | 316 | }, |
305168ca S |
317 | }, { |
318 | # Embedded via <iframe src="http://www.arte.tv/guide/fr/embed/054813-004-A/medium" | |
319 | 'url': 'http://www.arte.tv/magazine/trepalium/fr/episode-0406-replay-trepalium', | |
320 | 'md5': 'fedc64fc7a946110fe311634e79782ca', | |
321 | 'info_dict': { | |
322 | 'id': '054813-004_PLUS7-F', | |
323 | 'ext': 'mp4', | |
324 | 'title': 'Trepalium (4/6)', | |
325 | 'description': 'md5:10057003c34d54e95350be4f9b05cb40', | |
326 | 'upload_date': '20160218', | |
327 | }, | |
49625662 TJ |
328 | }, { |
329 | 'url': 'http://www.arte.tv/magazine/metropolis/de/frank-woeste-german-paris-metropolis', | |
479ec54a | 330 | 'only_matching': True, |
49625662 TJ |
331 | }] |
332 | ||
333 | ||
893f8832 PH |
334 | class ArteTVEmbedIE(ArteTVPlus7IE): |
335 | IE_NAME = 'arte.tv:embed' | |
336 | _VALID_URL = r'''(?x) | |
337 | http://www\.arte\.tv | |
338 | /playerv2/embed\.php\?json_url= | |
339 | (?P<json_url> | |
340 | http://arte\.tv/papi/tvguide/videos/stream/player/ | |
341 | (?P<lang>[^/]+)/(?P<id>[^/]+)[^&]* | |
342 | ) | |
343 | ''' | |
344 | ||
345 | def _real_extract(self, url): | |
346 | mobj = re.match(self._VALID_URL, url) | |
347 | video_id = mobj.group('id') | |
348 | lang = mobj.group('lang') | |
349 | json_url = mobj.group('json_url') | |
350 | return self._extract_from_json_url(json_url, video_id, lang) |