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