]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/francetv.py
Prepare for release.
[youtubedl] / 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 )
12
13
14 class FranceTVBaseInfoExtractor(InfoExtractor):
15 def _extract_video(self, video_id):
16 info = self._download_xml(
17 'http://www.francetvinfo.fr/appftv/webservices/video/'
18 'getInfosOeuvre.php?id-diffusion='
19 + video_id, video_id, 'Downloading XML config')
20
21 manifest_url = info.find('videos/video/url').text
22 video_url = manifest_url.replace('manifest.f4m', 'index_2_av.m3u8')
23 video_url = video_url.replace('/z/', '/i/')
24 thumbnail_path = info.find('image').text
25
26 return {'id': video_id,
27 'ext': 'flv' if video_url.startswith('rtmp') else 'mp4',
28 'url': video_url,
29 'title': info.find('titre').text,
30 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', thumbnail_path),
31 'description': info.find('synopsis').text,
32 }
33
34
35 class PluzzIE(FranceTVBaseInfoExtractor):
36 IE_NAME = 'pluzz.francetv.fr'
37 _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
38
39 # Can't use tests, videos expire in 7 days
40
41 def _real_extract(self, url):
42 title = re.match(self._VALID_URL, url).group(1)
43 webpage = self._download_webpage(url, title)
44 video_id = self._search_regex(
45 r'data-diffusion="(\d+)"', webpage, 'ID')
46 return self._extract_video(video_id)
47
48
49 class FranceTvInfoIE(FranceTVBaseInfoExtractor):
50 IE_NAME = 'francetvinfo.fr'
51 _VALID_URL = r'https?://www\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
52
53 _TESTS = [{
54 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
55 'info_dict': {
56 'id': '84981923',
57 'ext': 'mp4',
58 'title': 'Soir 3',
59 },
60 'params': {
61 'skip_download': True,
62 },
63 }, {
64 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
65 'info_dict': {
66 'id': 'EV_20019',
67 'ext': 'mp4',
68 'title': 'Débat des candidats à la Commission européenne',
69 'description': 'Débat des candidats à la Commission européenne',
70 },
71 'params': {
72 'skip_download': 'HLS (reqires ffmpeg)'
73 }
74 }]
75
76 def _real_extract(self, url):
77 mobj = re.match(self._VALID_URL, url)
78 page_title = mobj.group('title')
79 webpage = self._download_webpage(url, page_title)
80 video_id = self._search_regex(r'id-video=((?:[^0-9]*?_)?[0-9]+)[@"]', webpage, 'video id')
81 return self._extract_video(video_id)
82
83
84 class FranceTVIE(FranceTVBaseInfoExtractor):
85 IE_NAME = 'francetv'
86 IE_DESC = 'France 2, 3, 4, 5 and Ô'
87 _VALID_URL = r'''(?x)https?://www\.france[2345o]\.fr/
88 (?:
89 emissions/.*?/(videos|emissions)/(?P<id>[^/?]+)
90 | (emissions?|jt)/(?P<key>[^/?]+)
91 )'''
92
93 _TESTS = [
94 # france2
95 {
96 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
97 'file': '75540104.mp4',
98 'info_dict': {
99 'title': '13h15, le samedi...',
100 'description': 'md5:2e5b58ba7a2d3692b35c792be081a03d',
101 },
102 'params': {
103 # m3u8 download
104 'skip_download': True,
105 },
106 },
107 # france3
108 {
109 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
110 'info_dict': {
111 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
112 'ext': 'flv',
113 'title': 'Le scandale du prix des médicaments',
114 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
115 },
116 'params': {
117 # rtmp download
118 'skip_download': True,
119 },
120 },
121 # france4
122 {
123 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
124 'info_dict': {
125 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
126 'ext': 'flv',
127 'title': 'Hero Corp Making of - Extrait 1',
128 'description': 'md5:c87d54871b1790679aec1197e73d650a',
129 },
130 'params': {
131 # rtmp download
132 'skip_download': True,
133 },
134 },
135 # france5
136 {
137 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
138 'info_dict': {
139 'id': '92837968',
140 'ext': 'mp4',
141 'title': 'C à dire ?!',
142 'description': 'md5:fb1db1cbad784dcce7c7a7bd177c8e2f',
143 },
144 'params': {
145 # m3u8 download
146 'skip_download': True,
147 },
148 },
149 # franceo
150 {
151 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
152 'info_dict': {
153 'id': '92327925',
154 'ext': 'mp4',
155 'title': 'Infô-Afrique',
156 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
157 },
158 'params': {
159 # m3u8 download
160 'skip_download': True,
161 },
162 'skip': 'The id changes frequently',
163 },
164 ]
165
166 def _real_extract(self, url):
167 mobj = re.match(self._VALID_URL, url)
168 if mobj.group('key'):
169 webpage = self._download_webpage(url, mobj.group('key'))
170 id_res = [
171 (r'''(?x)<div\s+class="video-player">\s*
172 <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+
173 class="francetv-video-player">'''),
174 (r'<a id="player_direct" href="http://info\.francetelevisions'
175 '\.fr/\?id-video=([^"/&]+)'),
176 (r'<a class="video" id="ftv_player_(.+?)"'),
177 ]
178 video_id = self._html_search_regex(id_res, webpage, 'video ID')
179 else:
180 video_id = mobj.group('id')
181 return self._extract_video(video_id)
182
183
184 class GenerationQuoiIE(InfoExtractor):
185 IE_NAME = 'france2.fr:generation-quoi'
186 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
187
188 _TEST = {
189 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
190 'file': 'k7FJX8VBcvvLmX4wA5Q.mp4',
191 'info_dict': {
192 'title': 'Génération Quoi - Garde à Vous',
193 'uploader': 'Génération Quoi',
194 },
195 'params': {
196 # It uses Dailymotion
197 'skip_download': True,
198 },
199 'skip': 'Only available from France',
200 }
201
202 def _real_extract(self, url):
203 mobj = re.match(self._VALID_URL, url)
204 name = mobj.group('name')
205 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
206 info_json = self._download_webpage(info_url, name)
207 info = json.loads(info_json)
208 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
209 ie='Dailymotion')
210
211
212 class CultureboxIE(FranceTVBaseInfoExtractor):
213 IE_NAME = 'culturebox.francetvinfo.fr'
214 _VALID_URL = r'https?://culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
215
216 _TEST = {
217 'url': 'http://culturebox.francetvinfo.fr/einstein-on-the-beach-au-theatre-du-chatelet-146813',
218 'info_dict': {
219 'id': 'EV_6785',
220 'ext': 'mp4',
221 'title': 'Einstein on the beach au Théâtre du Châtelet',
222 'description': 'md5:9ce2888b1efefc617b5e58b3f6200eeb',
223 },
224 'params': {
225 # m3u8 download
226 'skip_download': True,
227 },
228 }
229
230 def _real_extract(self, url):
231 mobj = re.match(self._VALID_URL, url)
232 name = mobj.group('name')
233 webpage = self._download_webpage(url, name)
234 video_id = self._search_regex(r'"http://videos\.francetv\.fr/video/(.*?)"', webpage, 'video id')
235 return self._extract_video(video_id)