Merge pull request #1438 from rzhxeo/fktv
[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     # Can't use tests, videos expire in 7 days
38
39     def _real_extract(self, url):
40         title = re.match(self._VALID_URL, url).group(1)
41         webpage = self._download_webpage(url, title)
42         video_id = self._search_regex(
43             r'data-diffusion="(\d+)"', webpage, 'ID')
44         return self._extract_video(video_id)
45
46
47 class FranceTvInfoIE(FranceTVBaseInfoExtractor):
48     IE_NAME = u'francetvinfo.fr'
49     _VALID_URL = r'https?://www\.francetvinfo\.fr/replay.*/(?P<title>.+).html'
50
51     _TEST = {
52         u'url': u'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
53         u'file': u'84981923.mp4',
54         u'info_dict': {
55             u'title': u'Soir 3',
56         },
57         u'params': {
58             u'skip_download': True,
59         },
60     }
61
62     def _real_extract(self, url):
63         mobj = re.match(self._VALID_URL, url)
64         page_title = mobj.group('title')
65         webpage = self._download_webpage(url, page_title)
66         video_id = self._search_regex(r'id-video=(\d+?)"', webpage, u'video id')
67         return self._extract_video(video_id)