Add an extractor for pluzz.francetv.fr (closes PR #1399)
[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 PluzzIE(InfoExtractor):
12     IE_NAME = u'pluzz.francetv.fr'
13     _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
14
15     _TEST = {
16         u'url': u'http://pluzz.francetv.fr/videos/allo_rufo_saison5_,88439064.html',
17         u'file': u'88439064.mp4',
18         u'info_dict': {
19             u'title': u'AllĂ´ Rufo',
20             u'description': u'md5:d909f1ebdf963814b65772aea250400e',
21         },
22         u'params': {
23             u'skip_download': True,
24         },
25     }
26
27     def _real_extract(self, url):
28         title = re.match(self._VALID_URL, url).group(1)
29         webpage = self._download_webpage(url, title)
30         video_id = self._search_regex(
31             r'data-diffusion="(\d+)"', webpage, 'ID')
32
33         xml_desc = self._download_webpage(
34             'http://www.pluzz.fr/appftv/webservices/video/'
35             'getInfosOeuvre.php?id-diffusion='
36             + video_id, title, 'Downloading XML config')
37         info = xml.etree.ElementTree.fromstring(xml_desc.encode('utf-8'))
38
39         manifest_url = info.find('videos/video/url').text
40         video_url = manifest_url.replace('manifest.f4m', 'index_2_av.m3u8')
41         video_url = video_url.replace('/z/', '/i/')
42         thumbnail_path = info.find('image').text
43
44         return {'id': video_id,
45                 'ext': 'mp4',
46                 'url': video_url,
47                 'title': info.find('titre').text,
48                 'thumbnail': compat_urlparse.urljoin(url, thumbnail_path),
49                 'description': info.find('synopsis').text,
50                 }