]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/francetv.py
6e1971043b3853b9fe54e682473a61621c9989e2
[youtubedl] / 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': '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 France2IE(FranceTVBaseInfoExtractor):
70 IE_NAME = u'france2.fr'
71 _VALID_URL = r'''(?x)https?://www\.france2\.fr/
72 (?:
73 emissions/.*?/videos/(?P<id>\d+)
74 | emission/(?P<key>[^/?]+)
75 )'''
76
77 _TEST = {
78 u'url': u'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
79 u'file': u'75540104.mp4',
80 u'info_dict': {
81 u'title': u'13h15, le samedi...',
82 u'description': u'md5:2e5b58ba7a2d3692b35c792be081a03d',
83 },
84 u'params': {
85 u'skip_download': True,
86 },
87 }
88
89 def _real_extract(self, url):
90 mobj = re.match(self._VALID_URL, url)
91 if mobj.group('key'):
92 webpage = self._download_webpage(url, mobj.group('key'))
93 video_id = self._html_search_regex(
94 r'''(?x)<div\s+class="video-player">\s*
95 <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+
96 class="francetv-video-player">''',
97 webpage, u'video ID')
98 else:
99 video_id = mobj.group('id')
100 return self._extract_video(video_id)
101
102
103 class GenerationQuoiIE(InfoExtractor):
104 IE_NAME = u'france2.fr:generation-quoi'
105 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
106
107 _TEST = {
108 u'url': u'http://generation-quoi.france2.fr/portrait/garde-a-vous',
109 u'file': u'k7FJX8VBcvvLmX4wA5Q.mp4',
110 u'info_dict': {
111 u'title': u'Génération Quoi - Garde à Vous',
112 u'uploader': u'Génération Quoi',
113 },
114 u'params': {
115 # It uses Dailymotion
116 u'skip_download': True,
117 },
118 }
119
120 def _real_extract(self, url):
121 mobj = re.match(self._VALID_URL, url)
122 name = mobj.group('name')
123 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
124 info_json = self._download_webpage(info_url, name)
125 info = json.loads(info_json)
126 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
127 ie='Dailymotion')