]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/canalplus.py
Update changelog.
[youtubedl] / youtube_dl / extractor / canalplus.py
1 # encoding: utf-8
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import unified_strdate
6
7
8 class CanalplusIE(InfoExtractor):
9 _VALID_URL = r'https?://(www\.canalplus\.fr/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>\d+))'
10 _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s'
11 IE_NAME = u'canalplus.fr'
12
13 _TEST = {
14 u'url': u'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470',
15 u'file': u'922470.flv',
16 u'info_dict': {
17 u'title': u'Zapping - 26/08/13',
18 u'description': u'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
19 u'upload_date': u'20130826',
20 },
21 u'params': {
22 u'skip_download': True,
23 },
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.groupdict().get('id')
29 if video_id is None:
30 webpage = self._download_webpage(url, mobj.group('path'))
31 video_id = self._search_regex(r'videoId = "(\d+)";', webpage, u'video id')
32 info_url = self._VIDEO_INFO_TEMPLATE % video_id
33 doc = self._download_xml(info_url,video_id,
34 u'Downloading video info')
35
36 self.report_extraction(video_id)
37 video_info = [video for video in doc if video.find('ID').text == video_id][0]
38 infos = video_info.find('INFOS')
39 media = video_info.find('MEDIA')
40 formats = [media.find('VIDEOS/%s' % format)
41 for format in ['BAS_DEBIT', 'HAUT_DEBIT', 'HD']]
42 video_url = [format.text for format in formats if format is not None][-1]
43
44 return {'id': video_id,
45 'title': u'%s - %s' % (infos.find('TITRAGE/TITRE').text,
46 infos.find('TITRAGE/SOUS_TITRE').text),
47 'url': video_url,
48 'ext': 'flv',
49 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
50 'thumbnail': media.find('IMAGES/GRAND').text,
51 'description': infos.find('DESCRIPTION').text,
52 'view_count': int(infos.find('NB_VUES').text),
53 }