]>
Commit | Line | Data |
---|---|---|
ad94a6fe | 1 | # encoding: utf-8 |
b075d25b S |
2 | from __future__ import unicode_literals |
3 | ||
ffca4b5c | 4 | import re |
ffca4b5c JMF |
5 | |
6 | from .common import InfoExtractor | |
7 | from ..utils import unified_strdate | |
8 | ||
69545c2a | 9 | |
ffca4b5c | 10 | class CanalplusIE(InfoExtractor): |
ad94a6fe | 11 | _VALID_URL = r'https?://(www\.canalplus\.fr/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>\d+))' |
ffca4b5c | 12 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s' |
b075d25b | 13 | IE_NAME = 'canalplus.fr' |
ffca4b5c JMF |
14 | |
15 | _TEST = { | |
b075d25b | 16 | 'url': 'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470', |
f401c6f6 | 17 | 'md5': '60c29434a416a83c15dae2587d47027d', |
b075d25b S |
18 | 'info_dict': { |
19 | 'id': '922470', | |
20 | 'ext': 'flv', | |
21 | 'title': 'Zapping - 26/08/13', | |
22 | 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013', | |
23 | 'upload_date': '20130826', | |
ad94a6fe | 24 | }, |
ffca4b5c JMF |
25 | } |
26 | ||
27 | def _real_extract(self, url): | |
28 | mobj = re.match(self._VALID_URL, url) | |
b075d25b S |
29 | video_id = mobj.group('id') |
30 | ||
ad94a6fe JMF |
31 | if video_id is None: |
32 | webpage = self._download_webpage(url, mobj.group('path')) | |
b075d25b S |
33 | video_id = self._search_regex(r'<canal:player videoId="(\d+)"', webpage, 'video id') |
34 | ||
ffca4b5c | 35 | info_url = self._VIDEO_INFO_TEMPLATE % video_id |
b075d25b | 36 | doc = self._download_xml(info_url, video_id, 'Downloading video XML') |
ffca4b5c | 37 | |
ffca4b5c | 38 | video_info = [video for video in doc if video.find('ID').text == video_id][0] |
ffca4b5c | 39 | media = video_info.find('MEDIA') |
b075d25b S |
40 | infos = video_info.find('INFOS') |
41 | ||
42 | preferences = ['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS'] | |
43 | ||
44 | formats = [ | |
45 | { | |
46 | 'url': fmt.text + '?hdcore=2.11.3' if fmt.tag == 'HDS' else fmt.text, | |
47 | 'format_id': fmt.tag, | |
48 | 'ext': 'mp4' if fmt.tag == 'HLS' else 'flv', | |
49 | 'preference': preferences.index(fmt.tag) if fmt.tag in preferences else -1, | |
50 | } for fmt in media.find('VIDEOS') if fmt.text | |
51 | ] | |
52 | self._sort_formats(formats) | |
53 | ||
54 | return { | |
55 | 'id': video_id, | |
56 | 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text, | |
57 | infos.find('TITRAGE/SOUS_TITRE').text), | |
58 | 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text), | |
59 | 'thumbnail': media.find('IMAGES/GRAND').text, | |
60 | 'description': infos.find('DESCRIPTION').text, | |
61 | 'view_count': int(infos.find('NB_VUES').text), | |
62 | 'like_count': int(infos.find('NB_LIKES').text), | |
63 | 'comment_count': int(infos.find('NB_COMMENTS').text), | |
64 | 'formats': formats, | |
65 | } |