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