]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/francetv.py
Merge branch 'pr-twitter' of https://github.com/atomicdryad/youtube-dl into atomicdry...
[yt-dlp.git] / youtube_dl / extractor / francetv.py
1 # encoding: utf-8
2
3 from __future__ import unicode_literals
4
5 import re
6 import json
7
8 from .common import InfoExtractor
9 from ..compat import compat_urlparse
10 from ..utils import (
11 clean_html,
12 ExtractorError,
13 int_or_none,
14 parse_duration,
15 determine_ext,
16 )
17 from .dailymotion import DailymotionCloudIE
18
19
20 class FranceTVBaseInfoExtractor(InfoExtractor):
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)
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
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']
52 ext = determine_ext(video_url)
53 if ext == 'f4m':
54 if georestricted:
55 # See https://github.com/rg3/youtube-dl/issues/3963
56 # m3u8 urls work fine
57 continue
58 f4m_url = self._download_webpage(
59 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url,
60 video_id, 'Downloading f4m manifest token', fatal=False)
61 if f4m_url:
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))
64 elif ext == 'm3u8':
65 formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4', m3u8_id=format_id))
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,
77 'preference': -1,
78 })
79 self._sort_formats(formats)
80
81 title = info['titre']
82 subtitle = info.get('sous_titre')
83 if subtitle:
84 title += ' - %s' % subtitle
85
86 return {
87 'id': video_id,
88 'title': title,
89 'description': clean_html(info['synopsis']),
90 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
91 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
92 'timestamp': int_or_none(info['diffusion']['timestamp']),
93 'formats': formats,
94 }
95
96
97 class PluzzIE(FranceTVBaseInfoExtractor):
98 IE_NAME = 'pluzz.francetv.fr'
99 _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
100
101 # Can't use tests, videos expire in 7 days
102
103 def _real_extract(self, url):
104 title = re.match(self._VALID_URL, url).group(1)
105 webpage = self._download_webpage(url, title)
106 video_id = self._search_regex(
107 r'data-diffusion="(\d+)"', webpage, 'ID')
108 return self._extract_video(video_id, 'Pluzz')
109
110
111 class FranceTvInfoIE(FranceTVBaseInfoExtractor):
112 IE_NAME = 'francetvinfo.fr'
113 _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
114
115 _TESTS = [{
116 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
117 'info_dict': {
118 'id': '84981923',
119 'ext': 'flv',
120 'title': 'Soir 3',
121 'upload_date': '20130826',
122 'timestamp': 1377548400,
123 },
124 }, {
125 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
126 'info_dict': {
127 'id': 'EV_20019',
128 'ext': 'mp4',
129 'title': 'Débat des candidats à la Commission européenne',
130 'description': 'Débat des candidats à la Commission européenne',
131 },
132 'params': {
133 'skip_download': 'HLS (reqires ffmpeg)'
134 },
135 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
136 }, {
137 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
138 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
139 'info_dict': {
140 'id': '556e03339473995ee145930c',
141 'ext': 'mp4',
142 'title': 'Les entreprises familiales : le secret de la réussite',
143 'thumbnail': 're:^https?://.*\.jpe?g$',
144 }
145 }]
146
147 def _real_extract(self, url):
148 mobj = re.match(self._VALID_URL, url)
149 page_title = mobj.group('title')
150 webpage = self._download_webpage(url, page_title)
151
152 dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
153 if dmcloud_url:
154 return self.url_result(dmcloud_url, 'DailymotionCloud')
155
156 video_id, catalogue = self._search_regex(
157 r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
158 return self._extract_video(video_id, catalogue)
159
160
161 class FranceTVIE(FranceTVBaseInfoExtractor):
162 IE_NAME = 'francetv'
163 IE_DESC = 'France 2, 3, 4, 5 and Ô'
164 _VALID_URL = r'''(?x)
165 https?://
166 (?:
167 (?:www\.)?france[2345o]\.fr/
168 (?:
169 emissions/[^/]+/(?:videos|diffusions)|
170 emission/[^/]+|
171 videos|
172 jt
173 )
174 /|
175 embed\.francetv\.fr/\?ue=
176 )
177 (?P<id>[^/?]+)
178 '''
179
180 _TESTS = [
181 # france2
182 {
183 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
184 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
185 'info_dict': {
186 'id': '109169362',
187 'ext': 'flv',
188 'title': '13h15, le dimanche...',
189 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
190 'upload_date': '20140914',
191 'timestamp': 1410693600,
192 },
193 },
194 # france3
195 {
196 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
197 'md5': '679bb8f8921f8623bd658fa2f8364da0',
198 'info_dict': {
199 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
200 'ext': 'mp4',
201 'title': 'Le scandale du prix des médicaments',
202 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
203 'upload_date': '20131113',
204 'timestamp': 1384380000,
205 },
206 },
207 # france4
208 {
209 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
210 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
211 'info_dict': {
212 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
213 'ext': 'mp4',
214 'title': 'Hero Corp Making of - Extrait 1',
215 'description': 'md5:c87d54871b1790679aec1197e73d650a',
216 'upload_date': '20131106',
217 'timestamp': 1383766500,
218 },
219 },
220 # france5
221 {
222 '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',
223 'md5': 'f6c577df3806e26471b3d21631241fd0',
224 'info_dict': {
225 'id': '123327454',
226 'ext': 'flv',
227 'title': 'C à dire ?! - Quels sont les enjeux de cette rentrée politique ?',
228 'description': 'md5:4a0d5cb5dce89d353522a84462bae5a4',
229 'upload_date': '20150831',
230 'timestamp': 1441035120,
231 },
232 },
233 # franceo
234 {
235 'url': 'http://www.franceo.fr/jt/info-soir/18-07-2015',
236 'md5': '47d5816d3b24351cdce512ad7ab31da8',
237 'info_dict': {
238 'id': '125377621',
239 'ext': 'flv',
240 'title': 'Infô soir',
241 'description': 'md5:01b8c6915a3d93d8bbbd692651714309',
242 'upload_date': '20150718',
243 'timestamp': 1437241200,
244 'duration': 414,
245 },
246 },
247 {
248 # francetv embed
249 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87',
250 'info_dict': {
251 'id': 'EV_30231',
252 'ext': 'flv',
253 'title': 'Alcaline, le concert avec Calogero',
254 'description': 'md5:61f08036dcc8f47e9cfc33aed08ffaff',
255 'upload_date': '20150226',
256 'timestamp': 1424989860,
257 'duration': 5400,
258 },
259 },
260 {
261 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05',
262 'only_matching': True,
263 },
264 {
265 'url': 'http://www.franceo.fr/videos/125377617',
266 'only_matching': True,
267 }
268 ]
269
270 def _real_extract(self, url):
271 video_id = self._match_id(url)
272 webpage = self._download_webpage(url, video_id)
273 video_id, catalogue = self._html_search_regex(
274 r'href="http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
275 webpage, 'video ID').split('@')
276 return self._extract_video(video_id, catalogue)
277
278
279 class GenerationQuoiIE(InfoExtractor):
280 IE_NAME = 'france2.fr:generation-quoi'
281 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
282
283 _TEST = {
284 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
285 'info_dict': {
286 'id': 'k7FJX8VBcvvLmX4wA5Q',
287 'ext': 'mp4',
288 'title': 'Génération Quoi - Garde à Vous',
289 'uploader': 'Génération Quoi',
290 },
291 'params': {
292 # It uses Dailymotion
293 'skip_download': True,
294 },
295 }
296
297 def _real_extract(self, url):
298 display_id = self._match_id(url)
299 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
300 info_json = self._download_webpage(info_url, display_id)
301 info = json.loads(info_json)
302 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
303 ie='Dailymotion')
304
305
306 class CultureboxIE(FranceTVBaseInfoExtractor):
307 IE_NAME = 'culturebox.francetvinfo.fr'
308 _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
309
310 _TEST = {
311 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
312 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
313 'info_dict': {
314 'id': 'EV_50111',
315 'ext': 'flv',
316 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
317 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
318 'upload_date': '20150320',
319 'timestamp': 1426892400,
320 'duration': 2760.9,
321 },
322 }
323
324 def _real_extract(self, url):
325 mobj = re.match(self._VALID_URL, url)
326 name = mobj.group('name')
327
328 webpage = self._download_webpage(url, name)
329
330 if ">Ce live n'est plus disponible en replay<" in webpage:
331 raise ExtractorError('Video %s is not available' % name, expected=True)
332
333 video_id, catalogue = self._search_regex(
334 r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
335
336 return self._extract_video(video_id, catalogue)