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