]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/francetv.py
[vk] Add age restricted video test for reference
[yt-dlp.git] / youtube_dl / extractor / francetv.py
CommitLineData
5d8afe69 1# encoding: utf-8
3c1b4669
PH
2
3from __future__ import unicode_literals
4
5d8afe69 5import re
5b333c1c 6import json
5d8afe69
PR
7
8from .common import InfoExtractor
1cc79574
PH
9from ..compat import (
10 compat_urllib_parse_urlparse,
5d8afe69 11 compat_urlparse,
1cc79574
PH
12)
13from ..utils import (
64892c0b 14 clean_html,
1cc79574 15 ExtractorError,
64892c0b 16 int_or_none,
f05d0e73 17 float_or_none,
1cc79574 18 parse_duration,
bc03228a 19 determine_ext,
5d8afe69 20)
6f96e308 21from .dailymotion import DailymotionCloudIE
5d8afe69
PR
22
23
648d25d4 24class FranceTVBaseInfoExtractor(InfoExtractor):
64892c0b
S
25 def _extract_video(self, video_id, catalogue):
26 info = self._download_json(
27 'http://webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=%s&catalogue=%s'
28 % (video_id, catalogue),
29 video_id, 'Downloading video JSON')
30
31 if info.get('status') == 'NOK':
32 raise ExtractorError(
33 '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True)
00e9d396
JMF
34 allowed_countries = info['videos'][0].get('geoblocage')
35 if allowed_countries:
36 georestricted = True
37 geo_info = self._download_json(
38 'http://geo.francetv.fr/ws/edgescape.json', video_id,
39 'Downloading geo restriction info')
40 country = geo_info['reponse']['geo_info']['country_code']
41 if country not in allowed_countries:
42 raise ExtractorError(
43 'The video is not available from your location',
44 expected=True)
45 else:
46 georestricted = False
47
64892c0b
S
48 formats = []
49 for video in info['videos']:
50 if video['statut'] != 'ONLINE':
51 continue
52 video_url = video['url']
53 if not video_url:
54 continue
55 format_id = video['format']
bc03228a
S
56 ext = determine_ext(video_url)
57 if ext == 'f4m':
00e9d396
JMF
58 if georestricted:
59 # See https://github.com/rg3/youtube-dl/issues/3963
60 # m3u8 urls work fine
61 continue
64892c0b
S
62 video_url_parsed = compat_urllib_parse_urlparse(video_url)
63 f4m_url = self._download_webpage(
99e6833c 64 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url_parsed.path,
64892c0b
S
65 video_id, 'Downloading f4m manifest token', fatal=False)
66 if f4m_url:
bc03228a
S
67 formats.extend(self._extract_f4m_formats(f4m_url, video_id, 1, format_id))
68 elif ext == 'm3u8':
69 formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4', m3u8_id=format_id))
64892c0b
S
70 elif video_url.startswith('rtmp'):
71 formats.append({
72 'url': video_url,
73 'format_id': 'rtmp-%s' % format_id,
74 'ext': 'flv',
75 'preference': 1,
76 })
77 else:
78 formats.append({
79 'url': video_url,
80 'format_id': format_id,
2399535f 81 'preference': -1,
64892c0b
S
82 })
83 self._sort_formats(formats)
648d25d4 84
7e8d73c1
JMF
85 return {
86 'id': video_id,
64892c0b
S
87 'title': info['titre'],
88 'description': clean_html(info['synopsis']),
89 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
f05d0e73 90 'duration': float_or_none(info.get('real_duration'), 1000) or parse_duration(info['duree']),
64892c0b 91 'timestamp': int_or_none(info['diffusion']['timestamp']),
7e8d73c1 92 'formats': formats,
7e8d73c1 93 }
648d25d4
JMF
94
95
96class PluzzIE(FranceTVBaseInfoExtractor):
3c1b4669 97 IE_NAME = 'pluzz.francetv.fr'
5d8afe69
PR
98 _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
99
5d13df79 100 # Can't use tests, videos expire in 7 days
5d8afe69
PR
101
102 def _real_extract(self, url):
103 title = re.match(self._VALID_URL, url).group(1)
104 webpage = self._download_webpage(url, title)
105 video_id = self._search_regex(
106 r'data-diffusion="(\d+)"', webpage, 'ID')
64892c0b 107 return self._extract_video(video_id, 'Pluzz')
5d8afe69 108
5d8afe69 109
648d25d4 110class FranceTvInfoIE(FranceTVBaseInfoExtractor):
3c1b4669 111 IE_NAME = 'francetvinfo.fr'
23d3c422 112 _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
5d8afe69 113
5c30b268 114 _TESTS = [{
3c1b4669 115 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
3c1b4669 116 'info_dict': {
5c30b268 117 'id': '84981923',
64892c0b 118 'ext': 'flv',
3c1b4669 119 'title': 'Soir 3',
64892c0b
S
120 'upload_date': '20130826',
121 'timestamp': 1377548400,
648d25d4 122 },
5c30b268
PH
123 }, {
124 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
125 'info_dict': {
126 'id': 'EV_20019',
127 'ext': 'mp4',
128 'title': 'Débat des candidats à la Commission européenne',
129 'description': 'Débat des candidats à la Commission européenne',
130 },
131 'params': {
132 'skip_download': 'HLS (reqires ffmpeg)'
64892c0b
S
133 },
134 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
6f96e308
YCH
135 }, {
136 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
137 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
138 'info_dict': {
139 'id': '556e03339473995ee145930c',
140 'ext': 'mp4',
141 'title': 'Les entreprises familiales : le secret de la réussite',
142 'thumbnail': 're:^https?://.*\.jpe?g$',
143 }
5c30b268 144 }]
648d25d4
JMF
145
146 def _real_extract(self, url):
147 mobj = re.match(self._VALID_URL, url)
148 page_title = mobj.group('title')
149 webpage = self._download_webpage(url, page_title)
6f96e308
YCH
150
151 dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
152 if dmcloud_url:
153 return self.url_result(dmcloud_url, 'DailymotionCloud')
154
64892c0b
S
155 video_id, catalogue = self._search_regex(
156 r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
157 return self._extract_video(video_id, catalogue)
a825f330
JMF
158
159
9e606020 160class FranceTVIE(FranceTVBaseInfoExtractor):
3c1b4669
PH
161 IE_NAME = 'francetv'
162 IE_DESC = 'France 2, 3, 4, 5 and Ô'
9e606020 163 _VALID_URL = r'''(?x)https?://www\.france[2345o]\.fr/
da0a5d2d 164 (?:
9e606020 165 emissions/.*?/(videos|emissions)/(?P<id>[^/?]+)
3514813d 166 | (emissions?|jt)/(?P<key>[^/?]+)
da0a5d2d 167 )'''
a825f330 168
9e606020
JMF
169 _TESTS = [
170 # france2
171 {
3c1b4669 172 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
64892c0b 173 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
3c1b4669 174 'info_dict': {
64892c0b
S
175 'id': '109169362',
176 'ext': 'flv',
177 'title': '13h15, le dimanche...',
178 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
179 'upload_date': '20140914',
180 'timestamp': 1410693600,
9e606020 181 },
a825f330 182 },
9e606020
JMF
183 # france3
184 {
3c1b4669 185 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
64892c0b 186 'md5': '679bb8f8921f8623bd658fa2f8364da0',
3c1b4669
PH
187 'info_dict': {
188 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
64892c0b 189 'ext': 'mp4',
3c1b4669
PH
190 'title': 'Le scandale du prix des médicaments',
191 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
64892c0b
S
192 'upload_date': '20131113',
193 'timestamp': 1384380000,
9e606020 194 },
a825f330 195 },
9e606020
JMF
196 # france4
197 {
3c1b4669 198 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
64892c0b 199 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
3c1b4669
PH
200 'info_dict': {
201 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
64892c0b 202 'ext': 'mp4',
3c1b4669
PH
203 'title': 'Hero Corp Making of - Extrait 1',
204 'description': 'md5:c87d54871b1790679aec1197e73d650a',
64892c0b
S
205 'upload_date': '20131106',
206 'timestamp': 1383766500,
9e606020
JMF
207 },
208 },
209 # france5
210 {
3c1b4669 211 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
64892c0b 212 'md5': '78f0f4064f9074438e660785bbf2c5d9',
3c1b4669 213 'info_dict': {
64892c0b
S
214 'id': '108961659',
215 'ext': 'flv',
3c1b4669 216 'title': 'C à dire ?!',
64892c0b
S
217 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
218 'upload_date': '20140915',
219 'timestamp': 1410795000,
9e606020
JMF
220 },
221 },
222 # franceo
223 {
3c1b4669 224 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
64892c0b 225 'md5': '52f0bfe202848b15915a2f39aaa8981b',
3c1b4669 226 'info_dict': {
64892c0b
S
227 'id': '108634970',
228 'ext': 'flv',
229 'title': 'Infô Afrique',
3c1b4669 230 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
64892c0b
S
231 'upload_date': '20140915',
232 'timestamp': 1410822000,
9e606020 233 },
9e606020
JMF
234 },
235 ]
a825f330
JMF
236
237 def _real_extract(self, url):
238 mobj = re.match(self._VALID_URL, url)
64892c0b
S
239 webpage = self._download_webpage(url, mobj.group('key') or mobj.group('id'))
240 video_id, catalogue = self._html_search_regex(
241 r'href="http://videos\.francetv\.fr/video/([^@]+@[^"]+)"',
242 webpage, 'video ID').split('@')
243 return self._extract_video(video_id, catalogue)
5b333c1c
JMF
244
245
246class GenerationQuoiIE(InfoExtractor):
3c1b4669 247 IE_NAME = 'france2.fr:generation-quoi'
c4e817ce 248 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
5b333c1c
JMF
249
250 _TEST = {
3c1b4669 251 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
3c1b4669 252 'info_dict': {
c4e817ce
PH
253 'id': 'k7FJX8VBcvvLmX4wA5Q',
254 'ext': 'mp4',
3c1b4669
PH
255 'title': 'Génération Quoi - Garde à Vous',
256 'uploader': 'Génération Quoi',
5b333c1c 257 },
3c1b4669 258 'params': {
5b333c1c 259 # It uses Dailymotion
3c1b4669 260 'skip_download': True,
5b333c1c
JMF
261 },
262 }
263
264 def _real_extract(self, url):
c4e817ce
PH
265 display_id = self._match_id(url)
266 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
267 info_json = self._download_webpage(info_url, display_id)
5b333c1c
JMF
268 info = json.loads(info_json)
269 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
9e1a5b84 270 ie='Dailymotion')
469ec941
JMF
271
272
273class CultureboxIE(FranceTVBaseInfoExtractor):
3c1b4669 274 IE_NAME = 'culturebox.francetvinfo.fr'
23d3c422 275 _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
469ec941
JMF
276
277 _TEST = {
aed2d4b3 278 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
ac651e97 279 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
3c1b4669 280 'info_dict': {
aed2d4b3 281 'id': 'EV_50111',
ac651e97 282 'ext': 'flv',
aed2d4b3
S
283 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
284 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
285 'upload_date': '20150320',
286 'timestamp': 1426892400,
287 'duration': 2760.9,
288 },
469ec941
JMF
289 }
290
291 def _real_extract(self, url):
292 mobj = re.match(self._VALID_URL, url)
293 name = mobj.group('name')
184a1974 294
469ec941 295 webpage = self._download_webpage(url, name)
184a1974
S
296
297 if ">Ce live n'est plus disponible en replay<" in webpage:
298 raise ExtractorError('Video %s is not available' % name, expected=True)
299
64892c0b
S
300 video_id, catalogue = self._search_regex(
301 r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
302
303 return self._extract_video(video_id, catalogue)