Merge branch 'master' into subtitles_rework
[youtube-dl] / youtube_dl / extractor / francetv.py
1 # encoding: utf-8
2 import re
3 import xml.etree.ElementTree
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         xml_desc = self._download_webpage(
14             'http://www.francetvinfo.fr/appftv/webservices/video/'
15             'getInfosOeuvre.php?id-diffusion='
16             + video_id, video_id, 'Downloading XML config')
17         info = xml.etree.ElementTree.fromstring(xml_desc.encode('utf-8'))
18
19         manifest_url = info.find('videos/video/url').text
20         video_url = manifest_url.replace('manifest.f4m', 'index_2_av.m3u8')
21         video_url = video_url.replace('/z/', '/i/')
22         thumbnail_path = info.find('image').text
23
24         return {'id': video_id,
25                 'ext': 'mp4',
26                 'url': video_url,
27                 'title': info.find('titre').text,
28                 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', thumbnail_path),
29                 'description': info.find('synopsis').text,
30                 }
31
32
33 class PluzzIE(FranceTVBaseInfoExtractor):
34     IE_NAME = u'pluzz.francetv.fr'
35     _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
36
37     _TEST = {
38         u'url': u'http://pluzz.francetv.fr/videos/allo_rufo_saison5_,88439064.html',
39         u'file': u'88439064.mp4',
40         u'info_dict': {
41             u'title': u'AllĂ´ Rufo',
42             u'description': u'md5:d909f1ebdf963814b65772aea250400e',
43         },
44         u'params': {
45             u'skip_download': True,
46         },
47     }
48
49     def _real_extract(self, url):
50         title = re.match(self._VALID_URL, url).group(1)
51         webpage = self._download_webpage(url, title)
52         video_id = self._search_regex(
53             r'data-diffusion="(\d+)"', webpage, 'ID')
54         return self._extract_video(video_id)
55
56
57 class FranceTvInfoIE(FranceTVBaseInfoExtractor):
58     IE_NAME = u'francetvinfo.fr'
59     _VALID_URL = r'https?://www\.francetvinfo\.fr/replay.*/(?P<title>.+).html'
60
61     _TEST = {
62         u'url': u'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
63         u'file': u'84981923.mp4',
64         u'info_dict': {
65             u'title': u'Soir 3',
66         },
67         u'params': {
68             u'skip_download': True,
69         },
70     }
71
72     def _real_extract(self, url):
73         mobj = re.match(self._VALID_URL, url)
74         page_title = mobj.group('title')
75         webpage = self._download_webpage(url, page_title)
76         video_id = self._search_regex(r'id-video=(\d+?)"', webpage, u'video id')
77         return self._extract_video(video_id)