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