]>
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, |
aff2f4f4 | 16 | qualities, |
d5822b96 PH |
17 | ) |
18 | ||
5f6a1245 | 19 | # There are different sources of video in arte.tv, the extraction process |
c40f5cf4 JMF |
20 | # is different for each one. The videos usually expire in 7 days, so we can't |
21 | # add tests. | |
22 | ||
d5822b96 | 23 | |
515bbe4b | 24 | class ArteTvIE(InfoExtractor): |
878d11ec | 25 | _VALID_URL = r'http://videos\.arte\.tv/(?P<lang>fr|de)/.*-(?P<id>.*?)\.html' |
3798eadc | 26 | IE_NAME = 'arte.tv' |
d5822b96 | 27 | |
d5822b96 | 28 | def _real_extract(self, url): |
7a249480 PH |
29 | mobj = re.match(self._VALID_URL, url) |
30 | lang = mobj.group('lang') | |
31 | video_id = mobj.group('id') | |
32 | ||
8de64cac PH |
33 | ref_xml_url = url.replace('/videos/', '/do_delegate/videos/') |
34 | ref_xml_url = ref_xml_url.replace('.html', ',view,asPlayerXml.xml') | |
a4ff6c47 PH |
35 | ref_xml_doc = self._download_xml( |
36 | ref_xml_url, video_id, note='Downloading metadata') | |
df50a412 | 37 | config_node = find_xpath_attr(ref_xml_doc, './/video', 'lang', lang) |
8de64cac | 38 | config_xml_url = config_node.attrib['ref'] |
878d11ec | 39 | config = self._download_xml( |
a4ff6c47 | 40 | config_xml_url, video_id, note='Downloading configuration') |
37b6a661 | 41 | |
878d11ec | 42 | formats = [{ |
5a184030 | 43 | 'format_id': q.attrib['quality'], |
459af434 JMF |
44 | # The playpath starts at 'mp4:', if we don't manually |
45 | # split the url, rtmpdump will incorrectly parse them | |
46 | 'url': q.text.split('mp4:', 1)[0], | |
47 | 'play_path': 'mp4:' + q.text.split('mp4:', 1)[1], | |
b2799ff9 | 48 | 'ext': 'flv', |
878d11ec | 49 | 'quality': 2 if q.attrib['quality'] == 'hd' else 1, |
b2799ff9 | 50 | } for q in config.findall('./urls/url')] |
878d11ec PH |
51 | self._sort_formats(formats) |
52 | ||
53 | title = config.find('.//name').text | |
54 | thumbnail = config.find('.//firstThumbnailUrl').text | |
55 | return { | |
56 | 'id': video_id, | |
57 | 'title': title, | |
58 | 'thumbnail': thumbnail, | |
7a249480 | 59 | 'formats': formats, |
515bbe4b | 60 | } |
c40f5cf4 JMF |
61 | |
62 | ||
63 | class ArteTVPlus7IE(InfoExtractor): | |
3798eadc | 64 | IE_NAME = 'arte.tv:+7' |
f66ede43 | 65 | _VALID_URL = r'https?://(?:www\.)?arte\.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?' |
c40f5cf4 | 66 | |
69a0c470 JMF |
67 | @classmethod |
68 | def _extract_url_info(cls, url): | |
69 | mobj = re.match(cls._VALID_URL, url) | |
c40f5cf4 | 70 | lang = mobj.group('lang') |
a8f1d167 JMF |
71 | query = compat_parse_qs(compat_urllib_parse_urlparse(url).query) |
72 | if 'vid' in query: | |
73 | video_id = query['vid'][0] | |
74 | else: | |
75 | # This is not a real id, it can be for example AJT for the news | |
76 | # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal | |
77 | video_id = mobj.group('id') | |
69a0c470 | 78 | return video_id, lang |
c40f5cf4 | 79 | |
69a0c470 JMF |
80 | def _real_extract(self, url): |
81 | video_id, lang = self._extract_url_info(url) | |
c40f5cf4 | 82 | webpage = self._download_webpage(url, video_id) |
69a0c470 JMF |
83 | return self._extract_from_webpage(webpage, video_id, lang) |
84 | ||
85 | def _extract_from_webpage(self, webpage, video_id, lang): | |
a8f1d167 JMF |
86 | patterns_templates = (r'arte_vp_url=["\'](.*?%s.*?)["\']', r'data-url=["\']([^"]+%s[^"]+)["\']') |
87 | ids = (video_id, '') | |
88 | # some pages contain multiple videos (like | |
89 | # http://www.arte.tv/guide/de/sendungen/XEN/xenius/?vid=055918-015_PLUS7-D), | |
90 | # so we first try to look for json URLs that contain the video id from | |
91 | # the 'vid' parameter. | |
92 | patterns = [t % re.escape(_id) for _id in ids for t in patterns_templates] | |
88ce273d | 93 | json_url = self._html_search_regex( |
a8f1d167 | 94 | patterns, webpage, 'json vp url', default=None) |
393ca8c9 S |
95 | if not json_url: |
96 | iframe_url = self._html_search_regex( | |
97 | r'<iframe[^>]+src=(["\'])(?P<url>.+\bjson_url=.+?)\1', | |
5e39123b | 98 | webpage, 'iframe url', group='url') |
393ca8c9 S |
99 | json_url = compat_parse_qs( |
100 | compat_urllib_parse_urlparse(iframe_url).query)['json_url'][0] | |
56a8ab7d | 101 | return self._extract_from_json_url(json_url, video_id, lang) |
c40f5cf4 | 102 | |
56a8ab7d | 103 | def _extract_from_json_url(self, json_url, video_id, lang): |
893f8832 | 104 | info = self._download_json(json_url, video_id) |
c40f5cf4 JMF |
105 | player_info = info['videoJsonPlayer'] |
106 | ||
99b67fec PH |
107 | upload_date_str = player_info.get('shootingDate') |
108 | if not upload_date_str: | |
109 | upload_date_str = player_info.get('VDA', '').split(' ')[0] | |
110 | ||
74214d35 S |
111 | title = player_info['VTI'].strip() |
112 | subtitle = player_info.get('VSU', '').strip() | |
113 | if subtitle: | |
114 | title += ' - %s' % subtitle | |
115 | ||
c40f5cf4 JMF |
116 | info_dict = { |
117 | 'id': player_info['VID'], | |
74214d35 | 118 | 'title': title, |
c40f5cf4 | 119 | 'description': player_info.get('VDE'), |
99b67fec | 120 | 'upload_date': unified_strdate(upload_date_str), |
c40f5cf4 JMF |
121 | 'thumbnail': player_info.get('programImage') or player_info.get('VTU', {}).get('IUR'), |
122 | } | |
aff2f4f4 | 123 | qfunc = qualities(['HQ', 'MQ', 'EQ', 'SQ']) |
c40f5cf4 | 124 | |
aff2f4f4 | 125 | formats = [] |
d24a2b20 | 126 | for format_id, format_dict in player_info['VSR'].items(): |
aff2f4f4 PH |
127 | f = dict(format_dict) |
128 | versionCode = f.get('versionCode') | |
129 | ||
130 | langcode = { | |
131 | 'fr': 'F', | |
132 | 'de': 'A', | |
133 | }.get(lang, lang) | |
134 | lang_rexs = [r'VO?%s' % langcode, r'VO?.-ST%s' % langcode] | |
135 | lang_pref = ( | |
136 | None if versionCode is None else ( | |
137 | 10 if any(re.match(r, versionCode) for r in lang_rexs) | |
138 | else -10)) | |
139 | source_pref = 0 | |
140 | if versionCode is not None: | |
141 | # The original version with subtitles has lower relevance | |
142 | if re.match(r'VO-ST(F|A)', versionCode): | |
143 | source_pref -= 10 | |
144 | # The version with sourds/mal subtitles has also lower relevance | |
145 | elif re.match(r'VO?(F|A)-STM\1', versionCode): | |
146 | source_pref -= 9 | |
147 | format = { | |
148 | 'format_id': format_id, | |
149 | 'preference': -10 if f.get('videoFormat') == 'M3U8' else None, | |
150 | 'language_preference': lang_pref, | |
151 | 'format_note': '%s, %s' % (f.get('versionCode'), f.get('versionLibelle')), | |
152 | 'width': int_or_none(f.get('width')), | |
153 | 'height': int_or_none(f.get('height')), | |
154 | 'tbr': int_or_none(f.get('bitrate')), | |
1b7b1d6e | 155 | 'quality': qfunc(f.get('quality')), |
aff2f4f4 | 156 | 'source_preference': source_pref, |
c40f5cf4 | 157 | } |
aff2f4f4 PH |
158 | |
159 | if f.get('mediaType') == 'rtmp': | |
160 | format['url'] = f['streamer'] | |
161 | format['play_path'] = 'mp4:' + f['url'] | |
162 | format['ext'] = 'flv' | |
c40f5cf4 | 163 | else: |
aff2f4f4 PH |
164 | format['url'] = f['url'] |
165 | ||
166 | formats.append(format) | |
167 | ||
c06a9f87 | 168 | self._check_formats(formats, video_id) |
aff2f4f4 | 169 | self._sort_formats(formats) |
c40f5cf4 | 170 | |
aff2f4f4 | 171 | info_dict['formats'] = formats |
c40f5cf4 JMF |
172 | return info_dict |
173 | ||
174 | ||
175 | # It also uses the arte_vp_url url from the webpage to extract the information | |
176 | class ArteTVCreativeIE(ArteTVPlus7IE): | |
3798eadc | 177 | IE_NAME = 'arte.tv:creative' |
01d906ff | 178 | _VALID_URL = r'https?://creative\.arte\.tv/(?P<lang>fr|de)/(?:magazine?/)?(?P<id>[^?#]+)' |
c40f5cf4 | 179 | |
01d906ff | 180 | _TESTS = [{ |
3798eadc | 181 | 'url': 'http://creative.arte.tv/de/magazin/agentur-amateur-corporate-design', |
3798eadc | 182 | 'info_dict': { |
01d906ff | 183 | 'id': '72176', |
39a743fb | 184 | 'ext': 'mp4', |
01d906ff PH |
185 | 'title': 'Folge 2 - Corporate Design', |
186 | 'upload_date': '20131004', | |
c40f5cf4 | 187 | }, |
01d906ff PH |
188 | }, { |
189 | 'url': 'http://creative.arte.tv/fr/Monty-Python-Reunion', | |
190 | 'info_dict': { | |
191 | 'id': '160676', | |
192 | 'ext': 'mp4', | |
193 | 'title': 'Monty Python live (mostly)', | |
b5f4775b PH |
194 | 'description': 'Événement ! Quarante-cinq ans après leurs premiers succès, les légendaires Monty Python remontent sur scène.\n', |
195 | 'upload_date': '20140805', | |
01d906ff PH |
196 | } |
197 | }] | |
c40f5cf4 | 198 | |
69a0c470 JMF |
199 | |
200 | class ArteTVFutureIE(ArteTVPlus7IE): | |
3798eadc | 201 | IE_NAME = 'arte.tv:future' |
69a0c470 JMF |
202 | _VALID_URL = r'https?://future\.arte\.tv/(?P<lang>fr|de)/(thema|sujet)/.*?#article-anchor-(?P<id>\d+)' |
203 | ||
204 | _TEST = { | |
3798eadc | 205 | 'url': 'http://future.arte.tv/fr/sujet/info-sciences#article-anchor-7081', |
3798eadc | 206 | 'info_dict': { |
458ade63 | 207 | 'id': '5201', |
39a743fb | 208 | 'ext': 'mp4', |
3798eadc | 209 | 'title': 'Les champignons au secours de la planète', |
458ade63 | 210 | 'upload_date': '20131101', |
69a0c470 JMF |
211 | }, |
212 | } | |
213 | ||
214 | def _real_extract(self, url): | |
215 | anchor_id, lang = self._extract_url_info(url) | |
216 | webpage = self._download_webpage(url, anchor_id) | |
2ad5708c S |
217 | row = self._search_regex( |
218 | r'(?s)id="%s"[^>]*>.+?(<div[^>]*arte_vp_url[^>]*>)' % anchor_id, | |
219 | webpage, 'row') | |
69a0c470 | 220 | return self._extract_from_webpage(row, anchor_id, lang) |
56a8ab7d | 221 | |
ac5118bc | 222 | |
56a8ab7d | 223 | class ArteTVDDCIE(ArteTVPlus7IE): |
3798eadc | 224 | IE_NAME = 'arte.tv:ddc' |
39a743fb | 225 | _VALID_URL = r'https?://ddc\.arte\.tv/(?P<lang>emission|folge)/(?P<id>.+)' |
56a8ab7d | 226 | |
56a8ab7d CD |
227 | def _real_extract(self, url): |
228 | video_id, lang = self._extract_url_info(url) | |
229 | if lang == 'folge': | |
230 | lang = 'de' | |
231 | elif lang == 'emission': | |
232 | lang = 'fr' | |
233 | webpage = self._download_webpage(url, video_id) | |
234 | scriptElement = get_element_by_attribute('class', 'visu_video_block', webpage) | |
235 | script_url = self._html_search_regex(r'src="(.*?)"', scriptElement, 'script url') | |
236 | javascriptPlayerGenerator = self._download_webpage(script_url, video_id, 'Download javascript player generator') | |
237 | json_url = self._search_regex(r"json_url=(.*)&rendering_place.*", javascriptPlayerGenerator, 'json url') | |
238 | return self._extract_from_json_url(json_url, video_id, lang) | |
4966a0b2 JMF |
239 | |
240 | ||
241 | class ArteTVConcertIE(ArteTVPlus7IE): | |
242 | IE_NAME = 'arte.tv:concert' | |
243 | _VALID_URL = r'https?://concert\.arte\.tv/(?P<lang>de|fr)/(?P<id>.+)' | |
244 | ||
245 | _TEST = { | |
246 | 'url': 'http://concert.arte.tv/de/notwist-im-pariser-konzertclub-divan-du-monde', | |
247 | 'md5': '9ea035b7bd69696b67aa2ccaaa218161', | |
248 | 'info_dict': { | |
249 | 'id': '186', | |
250 | 'ext': 'mp4', | |
251 | 'title': 'The Notwist im Pariser Konzertclub "Divan du Monde"', | |
252 | 'upload_date': '20140128', | |
a9c2896e | 253 | 'description': 'md5:486eb08f991552ade77439fe6d82c305', |
4966a0b2 JMF |
254 | }, |
255 | } | |
893f8832 PH |
256 | |
257 | ||
258 | class ArteTVEmbedIE(ArteTVPlus7IE): | |
259 | IE_NAME = 'arte.tv:embed' | |
260 | _VALID_URL = r'''(?x) | |
261 | http://www\.arte\.tv | |
262 | /playerv2/embed\.php\?json_url= | |
263 | (?P<json_url> | |
264 | http://arte\.tv/papi/tvguide/videos/stream/player/ | |
265 | (?P<lang>[^/]+)/(?P<id>[^/]+)[^&]* | |
266 | ) | |
267 | ''' | |
268 | ||
269 | def _real_extract(self, url): | |
270 | mobj = re.match(self._VALID_URL, url) | |
271 | video_id = mobj.group('id') | |
272 | lang = mobj.group('lang') | |
273 | json_url = mobj.group('json_url') | |
274 | return self._extract_from_json_url(json_url, video_id, lang) |