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