]>
Commit | Line | Data |
---|---|---|
5d8afe69 | 1 | # encoding: 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 | ) |
6f96e308 | 17 | from .dailymotion import DailymotionCloudIE |
5d8afe69 PR |
18 | |
19 | ||
648d25d4 | 20 | class FranceTVBaseInfoExtractor(InfoExtractor): |
64892c0b S |
21 | def _extract_video(self, video_id, catalogue): |
22 | info = self._download_json( | |
23 | 'http://webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=%s&catalogue=%s' | |
24 | % (video_id, catalogue), | |
25 | video_id, 'Downloading video JSON') | |
26 | ||
27 | if info.get('status') == 'NOK': | |
28 | raise ExtractorError( | |
29 | '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True) | |
00e9d396 JMF |
30 | allowed_countries = info['videos'][0].get('geoblocage') |
31 | if allowed_countries: | |
32 | georestricted = True | |
33 | geo_info = self._download_json( | |
34 | 'http://geo.francetv.fr/ws/edgescape.json', video_id, | |
35 | 'Downloading geo restriction info') | |
36 | country = geo_info['reponse']['geo_info']['country_code'] | |
37 | if country not in allowed_countries: | |
38 | raise ExtractorError( | |
39 | 'The video is not available from your location', | |
40 | expected=True) | |
41 | else: | |
42 | georestricted = False | |
43 | ||
64892c0b S |
44 | formats = [] |
45 | for video in info['videos']: | |
46 | if video['statut'] != 'ONLINE': | |
47 | continue | |
48 | video_url = video['url'] | |
49 | if not video_url: | |
50 | continue | |
51 | format_id = video['format'] | |
bc03228a S |
52 | ext = determine_ext(video_url) |
53 | if ext == 'f4m': | |
00e9d396 JMF |
54 | if georestricted: |
55 | # See https://github.com/rg3/youtube-dl/issues/3963 | |
56 | # m3u8 urls work fine | |
57 | continue | |
64892c0b | 58 | f4m_url = self._download_webpage( |
ecdbe09e | 59 | 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url, |
64892c0b S |
60 | video_id, 'Downloading f4m manifest token', fatal=False) |
61 | if f4m_url: | |
632cbb8e S |
62 | formats.extend(self._extract_f4m_formats( |
63 | f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id, 1, format_id)) | |
bc03228a S |
64 | elif ext == 'm3u8': |
65 | formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4', m3u8_id=format_id)) | |
64892c0b S |
66 | elif video_url.startswith('rtmp'): |
67 | formats.append({ | |
68 | 'url': video_url, | |
69 | 'format_id': 'rtmp-%s' % format_id, | |
70 | 'ext': 'flv', | |
71 | 'preference': 1, | |
72 | }) | |
73 | else: | |
74 | formats.append({ | |
75 | 'url': video_url, | |
76 | 'format_id': format_id, | |
2399535f | 77 | 'preference': -1, |
64892c0b S |
78 | }) |
79 | self._sort_formats(formats) | |
648d25d4 | 80 | |
36c15522 S |
81 | title = info['titre'] |
82 | subtitle = info.get('sous_titre') | |
83 | if subtitle: | |
84 | title += ' - %s' % subtitle | |
85 | ||
5dadae07 | 86 | subtitles = {} |
6e4b8b28 | 87 | subtitles_list = [{ |
7ccb2b84 JMF |
88 | 'url': subformat['url'], |
89 | 'ext': subformat.get('format'), | |
90 | } for subformat in info.get('subtitles', []) if subformat.get('url')] | |
6e4b8b28 S |
91 | if subtitles_list: |
92 | subtitles['fr'] = subtitles_list | |
5dadae07 | 93 | |
7e8d73c1 JMF |
94 | return { |
95 | 'id': video_id, | |
36c15522 | 96 | 'title': title, |
64892c0b S |
97 | 'description': clean_html(info['synopsis']), |
98 | 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']), | |
5705ee6e | 99 | 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']), |
64892c0b | 100 | 'timestamp': int_or_none(info['diffusion']['timestamp']), |
7e8d73c1 | 101 | 'formats': formats, |
5dadae07 | 102 | 'subtitles': subtitles, |
7e8d73c1 | 103 | } |
648d25d4 JMF |
104 | |
105 | ||
106 | class PluzzIE(FranceTVBaseInfoExtractor): | |
3c1b4669 | 107 | IE_NAME = 'pluzz.francetv.fr' |
0a192fbe | 108 | _VALID_URL = r'https?://(?:m\.)?pluzz\.francetv\.fr/videos/(?P<id>.+?)\.html' |
5d8afe69 | 109 | |
5d13df79 | 110 | # Can't use tests, videos expire in 7 days |
5d8afe69 PR |
111 | |
112 | def _real_extract(self, url): | |
0a192fbe S |
113 | display_id = self._match_id(url) |
114 | ||
115 | webpage = self._download_webpage(url, display_id) | |
116 | ||
117 | video_id = self._html_search_meta( | |
118 | 'id_video', webpage, 'video id', default=None) | |
119 | if not video_id: | |
120 | video_id = self._search_regex( | |
7ccb2b84 | 121 | r'data-diffusion=["\'](\d+)', webpage, 'video id') |
0a192fbe | 122 | |
64892c0b | 123 | return self._extract_video(video_id, 'Pluzz') |
5d8afe69 | 124 | |
5d8afe69 | 125 | |
648d25d4 | 126 | class FranceTvInfoIE(FranceTVBaseInfoExtractor): |
3c1b4669 | 127 | IE_NAME = 'francetvinfo.fr' |
23d3c422 | 128 | _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html' |
5d8afe69 | 129 | |
5c30b268 | 130 | _TESTS = [{ |
3c1b4669 | 131 | 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html', |
3c1b4669 | 132 | 'info_dict': { |
5c30b268 | 133 | 'id': '84981923', |
64892c0b | 134 | 'ext': 'flv', |
3c1b4669 | 135 | 'title': 'Soir 3', |
64892c0b S |
136 | 'upload_date': '20130826', |
137 | 'timestamp': 1377548400, | |
c137cc0d S |
138 | 'subtitles': { |
139 | 'fr': 'mincount:2', | |
140 | }, | |
648d25d4 | 141 | }, |
5c30b268 PH |
142 | }, { |
143 | 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html', | |
144 | 'info_dict': { | |
145 | 'id': 'EV_20019', | |
146 | 'ext': 'mp4', | |
147 | 'title': 'Débat des candidats à la Commission européenne', | |
148 | 'description': 'Débat des candidats à la Commission européenne', | |
149 | }, | |
150 | 'params': { | |
151 | 'skip_download': 'HLS (reqires ffmpeg)' | |
64892c0b S |
152 | }, |
153 | 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.', | |
6f96e308 YCH |
154 | }, { |
155 | 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html', | |
156 | 'md5': 'f485bda6e185e7d15dbc69b72bae993e', | |
157 | 'info_dict': { | |
158 | 'id': '556e03339473995ee145930c', | |
159 | 'ext': 'mp4', | |
160 | 'title': 'Les entreprises familiales : le secret de la réussite', | |
161 | 'thumbnail': 're:^https?://.*\.jpe?g$', | |
162 | } | |
5c30b268 | 163 | }] |
648d25d4 JMF |
164 | |
165 | def _real_extract(self, url): | |
166 | mobj = re.match(self._VALID_URL, url) | |
167 | page_title = mobj.group('title') | |
168 | webpage = self._download_webpage(url, page_title) | |
6f96e308 YCH |
169 | |
170 | dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage) | |
171 | if dmcloud_url: | |
172 | return self.url_result(dmcloud_url, 'DailymotionCloud') | |
173 | ||
64892c0b S |
174 | video_id, catalogue = self._search_regex( |
175 | r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@') | |
176 | return self._extract_video(video_id, catalogue) | |
a825f330 JMF |
177 | |
178 | ||
9e606020 | 179 | class FranceTVIE(FranceTVBaseInfoExtractor): |
3c1b4669 PH |
180 | IE_NAME = 'francetv' |
181 | IE_DESC = 'France 2, 3, 4, 5 and Ô' | |
3f5c6d0c S |
182 | _VALID_URL = r'''(?x) |
183 | https?:// | |
184 | (?: | |
185 | (?:www\.)?france[2345o]\.fr/ | |
186 | (?: | |
308c505c S |
187 | emissions/[^/]+/(?:videos|diffusions)| |
188 | emission/[^/]+| | |
789a12aa S |
189 | videos| |
190 | jt | |
3f5c6d0c S |
191 | ) |
192 | /| | |
193 | embed\.francetv\.fr/\?ue= | |
194 | ) | |
195 | (?P<id>[^/?]+) | |
196 | ''' | |
a825f330 | 197 | |
9e606020 JMF |
198 | _TESTS = [ |
199 | # france2 | |
200 | { | |
3c1b4669 | 201 | 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104', |
64892c0b | 202 | 'md5': 'c03fc87cb85429ffd55df32b9fc05523', |
3c1b4669 | 203 | 'info_dict': { |
64892c0b S |
204 | 'id': '109169362', |
205 | 'ext': 'flv', | |
206 | 'title': '13h15, le dimanche...', | |
207 | 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7', | |
208 | 'upload_date': '20140914', | |
209 | 'timestamp': 1410693600, | |
9e606020 | 210 | }, |
a825f330 | 211 | }, |
9e606020 JMF |
212 | # france3 |
213 | { | |
3c1b4669 | 214 | 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575', |
64892c0b | 215 | 'md5': '679bb8f8921f8623bd658fa2f8364da0', |
3c1b4669 PH |
216 | 'info_dict': { |
217 | 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au', | |
64892c0b | 218 | 'ext': 'mp4', |
3c1b4669 PH |
219 | 'title': 'Le scandale du prix des médicaments', |
220 | 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce', | |
64892c0b S |
221 | 'upload_date': '20131113', |
222 | 'timestamp': 1384380000, | |
9e606020 | 223 | }, |
a825f330 | 224 | }, |
9e606020 JMF |
225 | # france4 |
226 | { | |
3c1b4669 | 227 | 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', |
64892c0b | 228 | 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c', |
3c1b4669 PH |
229 | 'info_dict': { |
230 | 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4', | |
64892c0b | 231 | 'ext': 'mp4', |
3c1b4669 PH |
232 | 'title': 'Hero Corp Making of - Extrait 1', |
233 | 'description': 'md5:c87d54871b1790679aec1197e73d650a', | |
64892c0b S |
234 | 'upload_date': '20131106', |
235 | 'timestamp': 1383766500, | |
9e606020 JMF |
236 | }, |
237 | }, | |
238 | # france5 | |
239 | { | |
77306e8b S |
240 | 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/quels_sont_les_enjeux_de_cette_rentree_politique__31-08-2015_908948?onglet=tous&page=1', |
241 | 'md5': 'f6c577df3806e26471b3d21631241fd0', | |
3c1b4669 | 242 | 'info_dict': { |
77306e8b | 243 | 'id': '123327454', |
64892c0b | 244 | 'ext': 'flv', |
6917d2a2 | 245 | 'title': 'C à dire ?! - Quels sont les enjeux de cette rentrée politique ?', |
77306e8b S |
246 | 'description': 'md5:4a0d5cb5dce89d353522a84462bae5a4', |
247 | 'upload_date': '20150831', | |
248 | 'timestamp': 1441035120, | |
9e606020 JMF |
249 | }, |
250 | }, | |
251 | # franceo | |
252 | { | |
3bc9fb58 S |
253 | 'url': 'http://www.franceo.fr/jt/info-soir/18-07-2015', |
254 | 'md5': '47d5816d3b24351cdce512ad7ab31da8', | |
3c1b4669 | 255 | 'info_dict': { |
3bc9fb58 | 256 | 'id': '125377621', |
64892c0b | 257 | 'ext': 'flv', |
3bc9fb58 S |
258 | 'title': 'Infô soir', |
259 | 'description': 'md5:01b8c6915a3d93d8bbbd692651714309', | |
260 | 'upload_date': '20150718', | |
261 | 'timestamp': 1437241200, | |
262 | 'duration': 414, | |
9e606020 | 263 | }, |
9e606020 | 264 | }, |
3f5c6d0c S |
265 | { |
266 | # francetv embed | |
267 | 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87', | |
268 | 'info_dict': { | |
269 | 'id': 'EV_30231', | |
270 | 'ext': 'flv', | |
271 | 'title': 'Alcaline, le concert avec Calogero', | |
ac4b8df5 | 272 | 'description': 'md5:61f08036dcc8f47e9cfc33aed08ffaff', |
3f5c6d0c S |
273 | 'upload_date': '20150226', |
274 | 'timestamp': 1424989860, | |
5705ee6e | 275 | 'duration': 5400, |
3f5c6d0c S |
276 | }, |
277 | }, | |
278 | { | |
279 | 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05', | |
280 | 'only_matching': True, | |
281 | }, | |
282 | { | |
283 | 'url': 'http://www.franceo.fr/videos/125377617', | |
284 | 'only_matching': True, | |
285 | } | |
9e606020 | 286 | ] |
a825f330 JMF |
287 | |
288 | def _real_extract(self, url): | |
3f5c6d0c S |
289 | video_id = self._match_id(url) |
290 | webpage = self._download_webpage(url, video_id) | |
64892c0b | 291 | video_id, catalogue = self._html_search_regex( |
3f5c6d0c | 292 | r'href="http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"', |
64892c0b S |
293 | webpage, 'video ID').split('@') |
294 | return self._extract_video(video_id, catalogue) | |
5b333c1c JMF |
295 | |
296 | ||
297 | class GenerationQuoiIE(InfoExtractor): | |
3c1b4669 | 298 | IE_NAME = 'france2.fr:generation-quoi' |
c4e817ce | 299 | _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)' |
5b333c1c JMF |
300 | |
301 | _TEST = { | |
3c1b4669 | 302 | 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous', |
3c1b4669 | 303 | 'info_dict': { |
c4e817ce PH |
304 | 'id': 'k7FJX8VBcvvLmX4wA5Q', |
305 | 'ext': 'mp4', | |
3c1b4669 PH |
306 | 'title': 'Génération Quoi - Garde à Vous', |
307 | 'uploader': 'Génération Quoi', | |
5b333c1c | 308 | }, |
3c1b4669 | 309 | 'params': { |
5b333c1c | 310 | # It uses Dailymotion |
3c1b4669 | 311 | 'skip_download': True, |
5b333c1c JMF |
312 | }, |
313 | } | |
314 | ||
315 | def _real_extract(self, url): | |
c4e817ce PH |
316 | display_id = self._match_id(url) |
317 | info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id) | |
318 | info_json = self._download_webpage(info_url, display_id) | |
5b333c1c JMF |
319 | info = json.loads(info_json) |
320 | return self.url_result('http://www.dailymotion.com/video/%s' % info['id'], | |
9e1a5b84 | 321 | ie='Dailymotion') |
469ec941 JMF |
322 | |
323 | ||
324 | class CultureboxIE(FranceTVBaseInfoExtractor): | |
3c1b4669 | 325 | IE_NAME = 'culturebox.francetvinfo.fr' |
23d3c422 | 326 | _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)' |
469ec941 JMF |
327 | |
328 | _TEST = { | |
aed2d4b3 | 329 | 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511', |
ac651e97 | 330 | 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6', |
3c1b4669 | 331 | 'info_dict': { |
aed2d4b3 | 332 | 'id': 'EV_50111', |
ac651e97 | 333 | 'ext': 'flv', |
aed2d4b3 S |
334 | 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne", |
335 | 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9', | |
336 | 'upload_date': '20150320', | |
337 | 'timestamp': 1426892400, | |
338 | 'duration': 2760.9, | |
339 | }, | |
469ec941 JMF |
340 | } |
341 | ||
342 | def _real_extract(self, url): | |
343 | mobj = re.match(self._VALID_URL, url) | |
344 | name = mobj.group('name') | |
184a1974 | 345 | |
469ec941 | 346 | webpage = self._download_webpage(url, name) |
184a1974 S |
347 | |
348 | if ">Ce live n'est plus disponible en replay<" in webpage: | |
349 | raise ExtractorError('Video %s is not available' % name, expected=True) | |
350 | ||
64892c0b S |
351 | video_id, catalogue = self._search_regex( |
352 | r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@') | |
353 | ||
354 | return self._extract_video(video_id, catalogue) |