]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
3c1b4669 PH |
2 | |
3 | from __future__ import unicode_literals | |
4 | ||
5d8afe69 | 5 | import re |
5b333c1c | 6 | import json |
5d8afe69 PR |
7 | |
8 | from .common import InfoExtractor | |
1d18e26e | 9 | from ..compat import compat_urlparse |
1cc79574 | 10 | from ..utils import ( |
64892c0b | 11 | clean_html, |
1cc79574 | 12 | ExtractorError, |
64892c0b | 13 | int_or_none, |
1cc79574 | 14 | parse_duration, |
bc03228a | 15 | determine_ext, |
5d8afe69 | 16 | ) |
ad213a1d YCH |
17 | from .dailymotion import ( |
18 | DailymotionIE, | |
19 | DailymotionCloudIE, | |
20 | ) | |
5d8afe69 PR |
21 | |
22 | ||
648d25d4 | 23 | class FranceTVBaseInfoExtractor(InfoExtractor): |
6d1ded75 | 24 | def _extract_video(self, video_id, catalogue=None): |
64892c0b | 25 | info = self._download_json( |
6d1ded75 S |
26 | 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/', |
27 | video_id, 'Downloading video JSON', query={ | |
28 | 'idDiffusion': video_id, | |
29 | 'catalogue': catalogue or '', | |
30 | }) | |
64892c0b S |
31 | |
32 | if info.get('status') == 'NOK': | |
33 | raise ExtractorError( | |
34 | '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True) | |
00e9d396 JMF |
35 | allowed_countries = info['videos'][0].get('geoblocage') |
36 | if allowed_countries: | |
37 | georestricted = True | |
38 | geo_info = self._download_json( | |
39 | 'http://geo.francetv.fr/ws/edgescape.json', video_id, | |
40 | 'Downloading geo restriction info') | |
41 | country = geo_info['reponse']['geo_info']['country_code'] | |
42 | if country not in allowed_countries: | |
43 | raise ExtractorError( | |
44 | 'The video is not available from your location', | |
45 | expected=True) | |
46 | else: | |
47 | georestricted = False | |
48 | ||
64892c0b S |
49 | formats = [] |
50 | for video in info['videos']: | |
51 | if video['statut'] != 'ONLINE': | |
52 | continue | |
53 | video_url = video['url'] | |
54 | if not video_url: | |
55 | continue | |
56 | format_id = video['format'] | |
bc03228a S |
57 | ext = determine_ext(video_url) |
58 | if ext == 'f4m': | |
00e9d396 JMF |
59 | if georestricted: |
60 | # See https://github.com/rg3/youtube-dl/issues/3963 | |
61 | # m3u8 urls work fine | |
62 | continue | |
64892c0b | 63 | f4m_url = self._download_webpage( |
ecdbe09e | 64 | 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url, |
64892c0b S |
65 | video_id, 'Downloading f4m manifest token', fatal=False) |
66 | if f4m_url: | |
632cbb8e | 67 | formats.extend(self._extract_f4m_formats( |
3c20208e S |
68 | f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44', |
69 | video_id, f4m_id=format_id, fatal=False)) | |
bc03228a | 70 | elif ext == 'm3u8': |
3c20208e S |
71 | formats.extend(self._extract_m3u8_formats( |
72 | video_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
73 | m3u8_id=format_id, fatal=False)) | |
64892c0b S |
74 | elif video_url.startswith('rtmp'): |
75 | formats.append({ | |
76 | 'url': video_url, | |
77 | 'format_id': 'rtmp-%s' % format_id, | |
78 | 'ext': 'flv', | |
64892c0b S |
79 | }) |
80 | else: | |
3c20208e S |
81 | if self._is_valid_url(video_url, video_id, format_id): |
82 | formats.append({ | |
83 | 'url': video_url, | |
84 | 'format_id': format_id, | |
85 | }) | |
64892c0b | 86 | self._sort_formats(formats) |
648d25d4 | 87 | |
36c15522 S |
88 | title = info['titre'] |
89 | subtitle = info.get('sous_titre') | |
90 | if subtitle: | |
91 | title += ' - %s' % subtitle | |
db264e3c | 92 | title = title.strip() |
36c15522 | 93 | |
5dadae07 | 94 | subtitles = {} |
6e4b8b28 | 95 | subtitles_list = [{ |
7ccb2b84 JMF |
96 | 'url': subformat['url'], |
97 | 'ext': subformat.get('format'), | |
98 | } for subformat in info.get('subtitles', []) if subformat.get('url')] | |
6e4b8b28 S |
99 | if subtitles_list: |
100 | subtitles['fr'] = subtitles_list | |
5dadae07 | 101 | |
7e8d73c1 JMF |
102 | return { |
103 | 'id': video_id, | |
36c15522 | 104 | 'title': title, |
64892c0b S |
105 | 'description': clean_html(info['synopsis']), |
106 | 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']), | |
5705ee6e | 107 | 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']), |
64892c0b | 108 | 'timestamp': int_or_none(info['diffusion']['timestamp']), |
7e8d73c1 | 109 | 'formats': formats, |
5dadae07 | 110 | 'subtitles': subtitles, |
7e8d73c1 | 111 | } |
648d25d4 JMF |
112 | |
113 | ||
6d1ded75 | 114 | class FranceTVIE(FranceTVBaseInfoExtractor): |
12f01118 | 115 | _VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)+(?P<id>[^/]+)\.html' |
5d8afe69 | 116 | |
6d1ded75 S |
117 | _TESTS = [{ |
118 | 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html', | |
119 | 'info_dict': { | |
120 | 'id': '157550144', | |
121 | 'ext': 'mp4', | |
122 | 'title': '13h15, le dimanche... - Les mystères de Jésus', | |
123 | 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42', | |
124 | 'timestamp': 1494156300, | |
125 | 'upload_date': '20170507', | |
126 | }, | |
127 | 'params': { | |
128 | # m3u8 downloads | |
129 | 'skip_download': True, | |
130 | }, | |
131 | }, { | |
132 | # france3 | |
133 | 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html', | |
134 | 'only_matching': True, | |
135 | }, { | |
136 | # france4 | |
137 | 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html', | |
138 | 'only_matching': True, | |
139 | }, { | |
140 | # france5 | |
141 | 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html', | |
142 | 'only_matching': True, | |
143 | }, { | |
144 | # franceo | |
145 | 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html', | |
146 | 'only_matching': True, | |
147 | }, { | |
148 | # france2 live | |
149 | 'url': 'https://www.france.tv/france-2/direct.html', | |
150 | 'only_matching': True, | |
151 | }, { | |
152 | 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html', | |
153 | 'only_matching': True, | |
154 | }, { | |
155 | 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html', | |
156 | 'only_matching': True, | |
12f01118 S |
157 | }, { |
158 | 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html', | |
159 | 'only_matching': True, | |
6d1ded75 | 160 | }] |
5d8afe69 PR |
161 | |
162 | def _real_extract(self, url): | |
0a192fbe S |
163 | display_id = self._match_id(url) |
164 | ||
165 | webpage = self._download_webpage(url, display_id) | |
166 | ||
6d1ded75 S |
167 | catalogue = None |
168 | video_id = self._search_regex( | |
169 | r'data-main-video=(["\'])(?P<id>(?:(?!\1).)+)\1', | |
170 | webpage, 'video id', default=None, group='id') | |
171 | ||
0a192fbe | 172 | if not video_id: |
6d1ded75 S |
173 | video_id, catalogue = self._html_search_regex( |
174 | r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"', | |
175 | webpage, 'video ID').split('@') | |
176 | return self._extract_video(video_id, catalogue) | |
177 | ||
178 | ||
179 | class FranceTVEmbedIE(FranceTVBaseInfoExtractor): | |
180 | _VALID_URL = r'https?://embed\.francetv\.fr/*\?.*?\bue=(?P<id>[^&]+)' | |
181 | ||
182 | _TEST = { | |
183 | 'url': 'http://embed.francetv.fr/?ue=7fd581a2ccf59d2fc5719c5c13cf6961', | |
184 | 'info_dict': { | |
185 | 'id': 'NI_983319', | |
186 | 'ext': 'mp4', | |
187 | 'title': 'Le Pen Reims', | |
188 | 'upload_date': '20170505', | |
189 | 'timestamp': 1493981780, | |
190 | 'duration': 16, | |
191 | }, | |
192 | } | |
0a192fbe | 193 | |
6d1ded75 S |
194 | def _real_extract(self, url): |
195 | video_id = self._match_id(url) | |
196 | ||
197 | video = self._download_json( | |
198 | 'http://api-embed.webservices.francetelevisions.fr/key/%s' % video_id, | |
199 | video_id) | |
5d8afe69 | 200 | |
6d1ded75 | 201 | return self._extract_video(video['video_id'], video.get('catalog')) |
5d8afe69 | 202 | |
6d1ded75 S |
203 | |
204 | class FranceTVInfoIE(FranceTVBaseInfoExtractor): | |
3c1b4669 | 205 | IE_NAME = 'francetvinfo.fr' |
30b25d38 | 206 | _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<title>[^/?#&.]+)' |
5d8afe69 | 207 | |
5c30b268 | 208 | _TESTS = [{ |
3c1b4669 | 209 | 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html', |
3c1b4669 | 210 | 'info_dict': { |
5c30b268 | 211 | 'id': '84981923', |
3c20208e | 212 | 'ext': 'mp4', |
3c1b4669 | 213 | 'title': 'Soir 3', |
64892c0b S |
214 | 'upload_date': '20130826', |
215 | 'timestamp': 1377548400, | |
c137cc0d S |
216 | 'subtitles': { |
217 | 'fr': 'mincount:2', | |
218 | }, | |
648d25d4 | 219 | }, |
3c20208e S |
220 | 'params': { |
221 | # m3u8 downloads | |
222 | 'skip_download': True, | |
223 | }, | |
5c30b268 PH |
224 | }, { |
225 | 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html', | |
226 | 'info_dict': { | |
227 | 'id': 'EV_20019', | |
228 | 'ext': 'mp4', | |
229 | 'title': 'Débat des candidats à la Commission européenne', | |
230 | 'description': 'Débat des candidats à la Commission européenne', | |
231 | }, | |
232 | 'params': { | |
233 | 'skip_download': 'HLS (reqires ffmpeg)' | |
64892c0b S |
234 | }, |
235 | 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.', | |
6f96e308 YCH |
236 | }, { |
237 | 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html', | |
238 | 'md5': 'f485bda6e185e7d15dbc69b72bae993e', | |
239 | 'info_dict': { | |
3c20208e | 240 | 'id': 'NI_173343', |
6f96e308 YCH |
241 | 'ext': 'mp4', |
242 | 'title': 'Les entreprises familiales : le secret de la réussite', | |
ec85ded8 | 243 | 'thumbnail': r're:^https?://.*\.jpe?g$', |
3c20208e S |
244 | 'timestamp': 1433273139, |
245 | 'upload_date': '20150602', | |
246 | }, | |
247 | 'params': { | |
248 | # m3u8 downloads | |
249 | 'skip_download': True, | |
250 | }, | |
db264e3c S |
251 | }, { |
252 | 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html', | |
253 | 'md5': 'f485bda6e185e7d15dbc69b72bae993e', | |
254 | 'info_dict': { | |
255 | 'id': 'NI_657393', | |
3c20208e | 256 | 'ext': 'mp4', |
db264e3c S |
257 | 'title': 'Olivier Monthus, réalisateur de "Bretagne, le choix de l’Armor"', |
258 | 'description': 'md5:a3264114c9d29aeca11ced113c37b16c', | |
ec85ded8 | 259 | 'thumbnail': r're:^https?://.*\.jpe?g$', |
db264e3c S |
260 | 'timestamp': 1458300695, |
261 | 'upload_date': '20160318', | |
262 | }, | |
263 | 'params': { | |
264 | 'skip_download': True, | |
265 | }, | |
ad213a1d YCH |
266 | }, { |
267 | # Dailymotion embed | |
268 | 'url': 'http://www.francetvinfo.fr/politique/notre-dame-des-landes/video-sur-france-inter-cecile-duflot-denonce-le-regard-meprisant-de-patrick-cohen_1520091.html', | |
269 | 'md5': 'ee7f1828f25a648addc90cb2687b1f12', | |
270 | 'info_dict': { | |
271 | 'id': 'x4iiko0', | |
272 | 'ext': 'mp4', | |
273 | 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen', | |
274 | 'description': 'Au lendemain de la victoire du "oui" au référendum sur l\'aéroport de Notre-Dame-des-Landes, l\'ancienne ministre écologiste est l\'invitée de Patrick Cohen. Plus d\'info : https://www.franceinter.fr/emissions/le-7-9/le-7-9-27-juin-2016', | |
275 | 'timestamp': 1467011958, | |
276 | 'upload_date': '20160627', | |
277 | 'uploader': 'France Inter', | |
278 | 'uploader_id': 'x2q2ez', | |
279 | }, | |
280 | 'add_ie': ['Dailymotion'], | |
30b25d38 S |
281 | }, { |
282 | 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin', | |
283 | 'only_matching': True, | |
5c30b268 | 284 | }] |
648d25d4 JMF |
285 | |
286 | def _real_extract(self, url): | |
287 | mobj = re.match(self._VALID_URL, url) | |
288 | page_title = mobj.group('title') | |
289 | webpage = self._download_webpage(url, page_title) | |
6f96e308 YCH |
290 | |
291 | dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage) | |
292 | if dmcloud_url: | |
ad213a1d YCH |
293 | return self.url_result(dmcloud_url, DailymotionCloudIE.ie_key()) |
294 | ||
295 | dailymotion_urls = DailymotionIE._extract_urls(webpage) | |
296 | if dailymotion_urls: | |
297 | return self.playlist_result([ | |
298 | self.url_result(dailymotion_url, DailymotionIE.ie_key()) | |
299 | for dailymotion_url in dailymotion_urls]) | |
6f96e308 | 300 | |
64892c0b | 301 | video_id, catalogue = self._search_regex( |
db264e3c S |
302 | (r'id-video=([^@]+@[^"]+)', |
303 | r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"'), | |
304 | webpage, 'video id').split('@') | |
64892c0b | 305 | return self._extract_video(video_id, catalogue) |
a825f330 JMF |
306 | |
307 | ||
5b333c1c | 308 | class GenerationQuoiIE(InfoExtractor): |
3c1b4669 | 309 | IE_NAME = 'france2.fr:generation-quoi' |
c4e817ce | 310 | _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)' |
5b333c1c JMF |
311 | |
312 | _TEST = { | |
3c1b4669 | 313 | 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous', |
3c1b4669 | 314 | 'info_dict': { |
c4e817ce PH |
315 | 'id': 'k7FJX8VBcvvLmX4wA5Q', |
316 | 'ext': 'mp4', | |
3c1b4669 PH |
317 | 'title': 'Génération Quoi - Garde à Vous', |
318 | 'uploader': 'Génération Quoi', | |
5b333c1c | 319 | }, |
3c1b4669 | 320 | 'params': { |
5b333c1c | 321 | # It uses Dailymotion |
3c1b4669 | 322 | 'skip_download': True, |
5b333c1c JMF |
323 | }, |
324 | } | |
325 | ||
326 | def _real_extract(self, url): | |
c4e817ce PH |
327 | display_id = self._match_id(url) |
328 | info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id) | |
329 | info_json = self._download_webpage(info_url, display_id) | |
5b333c1c JMF |
330 | info = json.loads(info_json) |
331 | return self.url_result('http://www.dailymotion.com/video/%s' % info['id'], | |
9e1a5b84 | 332 | ie='Dailymotion') |
469ec941 JMF |
333 | |
334 | ||
335 | class CultureboxIE(FranceTVBaseInfoExtractor): | |
3c1b4669 | 336 | IE_NAME = 'culturebox.francetvinfo.fr' |
23d3c422 | 337 | _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)' |
469ec941 JMF |
338 | |
339 | _TEST = { | |
aed2d4b3 | 340 | 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511', |
ac651e97 | 341 | 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6', |
3c1b4669 | 342 | 'info_dict': { |
aed2d4b3 | 343 | 'id': 'EV_50111', |
ac651e97 | 344 | 'ext': 'flv', |
aed2d4b3 S |
345 | 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne", |
346 | 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9', | |
347 | 'upload_date': '20150320', | |
348 | 'timestamp': 1426892400, | |
349 | 'duration': 2760.9, | |
350 | }, | |
469ec941 JMF |
351 | } |
352 | ||
353 | def _real_extract(self, url): | |
354 | mobj = re.match(self._VALID_URL, url) | |
355 | name = mobj.group('name') | |
184a1974 | 356 | |
469ec941 | 357 | webpage = self._download_webpage(url, name) |
184a1974 S |
358 | |
359 | if ">Ce live n'est plus disponible en replay<" in webpage: | |
360 | raise ExtractorError('Video %s is not available' % name, expected=True) | |
361 | ||
64892c0b S |
362 | video_id, catalogue = self._search_regex( |
363 | r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@') | |
364 | ||
365 | return self._extract_video(video_id, catalogue) |