]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/francetv.py
Add bug number that we are closing.
[youtubedl] / youtube_dl / extractor / francetv.py
1 # encoding: utf-8
2 import re
3 import xml.etree.ElementTree
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urlparse,
9 )
10
11
12 class FranceTVBaseInfoExtractor(InfoExtractor):
13 def _extract_video(self, video_id):
14 xml_desc = self._download_webpage(
15 'http://www.francetvinfo.fr/appftv/webservices/video/'
16 'getInfosOeuvre.php?id-diffusion='
17 + video_id, video_id, 'Downloading XML config')
18 info = xml.etree.ElementTree.fromstring(xml_desc.encode('utf-8'))
19
20 manifest_url = info.find('videos/video/url').text
21 video_url = manifest_url.replace('manifest.f4m', 'index_2_av.m3u8')
22 video_url = video_url.replace('/z/', '/i/')
23 thumbnail_path = info.find('image').text
24
25 return {'id': video_id,
26 'ext': 'mp4',
27 'url': video_url,
28 'title': info.find('titre').text,
29 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', thumbnail_path),
30 'description': info.find('synopsis').text,
31 }
32
33
34 class PluzzIE(FranceTVBaseInfoExtractor):
35 IE_NAME = u'pluzz.francetv.fr'
36 _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
37
38 # Can't use tests, videos expire in 7 days
39
40 def _real_extract(self, url):
41 title = re.match(self._VALID_URL, url).group(1)
42 webpage = self._download_webpage(url, title)
43 video_id = self._search_regex(
44 r'data-diffusion="(\d+)"', webpage, 'ID')
45 return self._extract_video(video_id)
46
47
48 class FranceTvInfoIE(FranceTVBaseInfoExtractor):
49 IE_NAME = u'francetvinfo.fr'
50 _VALID_URL = r'https?://www\.francetvinfo\.fr/replay.*/(?P<title>.+).html'
51
52 _TEST = {
53 u'url': u'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
54 u'file': u'84981923.mp4',
55 u'info_dict': {
56 u'title': u'Soir 3',
57 },
58 u'params': {
59 u'skip_download': True,
60 },
61 }
62
63 def _real_extract(self, url):
64 mobj = re.match(self._VALID_URL, url)
65 page_title = mobj.group('title')
66 webpage = self._download_webpage(url, page_title)
67 video_id = self._search_regex(r'id-video=(\d+?)"', webpage, u'video id')
68 return self._extract_video(video_id)
69
70
71 class France2IE(FranceTVBaseInfoExtractor):
72 IE_NAME = u'france2.fr'
73 _VALID_URL = r'''(?x)https?://www\.france2\.fr/
74 (?:
75 emissions/.*?/videos/(?P<id>\d+)
76 | emission/(?P<key>[^/?]+)
77 )'''
78
79 _TEST = {
80 u'url': u'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
81 u'file': u'75540104.mp4',
82 u'info_dict': {
83 u'title': u'13h15, le samedi...',
84 u'description': u'md5:2e5b58ba7a2d3692b35c792be081a03d',
85 },
86 u'params': {
87 u'skip_download': True,
88 },
89 }
90
91 def _real_extract(self, url):
92 mobj = re.match(self._VALID_URL, url)
93 if mobj.group('key'):
94 webpage = self._download_webpage(url, mobj.group('key'))
95 video_id = self._html_search_regex(
96 r'''(?x)<div\s+class="video-player">\s*
97 <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+
98 class="francetv-video-player">''',
99 webpage, u'video ID')
100 else:
101 video_id = mobj.group('id')
102 return self._extract_video(video_id)
103
104
105 class GenerationQuoiIE(InfoExtractor):
106 IE_NAME = u'http://generation-quoi.france2.fr'
107 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
108
109 _TEST = {
110 u'url': u'http://generation-quoi.france2.fr/portrait/garde-a-vous',
111 u'file': u'k7FJX8VBcvvLmX4wA5Q.mp4',
112 u'info_dict': {
113 u'title': u'Génération Quoi - Garde à Vous',
114 u'uploader': u'Génération Quoi',
115 },
116 u'params': {
117 # It uses Dailymotion
118 u'skip_download': True,
119 },
120 }
121
122 def _real_extract(self, url):
123 mobj = re.match(self._VALID_URL, url)
124 name = mobj.group('name')
125 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
126 info_json = self._download_webpage(info_url, name)
127 info = json.loads(info_json)
128 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
129 ie='Dailymotion')