]>
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 | |
4de9e9a6 PH |
7 | from ..utils import ( |
8 | unified_strdate, | |
9 | url_basename, | |
6e1cff9c | 10 | qualities, |
4de9e9a6 | 11 | ) |
ffca4b5c | 12 | |
69545c2a | 13 | |
ffca4b5c | 14 | class CanalplusIE(InfoExtractor): |
6e1cff9c S |
15 | IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv' |
16 | _VALID_URL = r'https?://(?:www\.(?P<site>canalplus\.fr|piwiplus\.fr|d8\.tv)/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))' | |
72975729 S |
17 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s' |
18 | _SITE_ID_MAP = { | |
6e1cff9c S |
19 | 'canalplus.fr': 'cplus', |
20 | 'piwiplus.fr': 'teletoon', | |
21 | 'd8.tv': 'd8', | |
72975729 | 22 | } |
ffca4b5c | 23 | |
72975729 | 24 | _TESTS = [{ |
b075d25b | 25 | 'url': 'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470', |
113c7d3e | 26 | 'md5': '3db39fb48b9685438ecf33a1078023e4', |
b075d25b S |
27 | 'info_dict': { |
28 | 'id': '922470', | |
29 | 'ext': 'flv', | |
30 | 'title': 'Zapping - 26/08/13', | |
31 | 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013', | |
32 | 'upload_date': '20130826', | |
ad94a6fe | 33 | }, |
72975729 S |
34 | }, { |
35 | 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190', | |
72975729 S |
36 | 'info_dict': { |
37 | 'id': '1108190', | |
38 | 'ext': 'flv', | |
39 | 'title': 'Le labyrinthe - Boing super ranger', | |
6e1cff9c | 40 | 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff', |
72975729 S |
41 | 'upload_date': '20140724', |
42 | }, | |
6e1cff9c S |
43 | 'skip': 'Only works from France', |
44 | }, { | |
45 | 'url': 'http://www.d8.tv/d8-docs-mags/pid6589-d8-campagne-intime.html', | |
46 | 'info_dict': { | |
47 | 'id': '966289', | |
48 | 'ext': 'flv', | |
49 | 'title': 'Campagne intime - Documentaire exceptionnel', | |
50 | 'description': 'md5:d2643b799fb190846ae09c61e59a859f', | |
51 | 'upload_date': '20131108', | |
52 | }, | |
53 | 'skip': 'videos get deleted after a while', | |
72975729 | 54 | }] |
ffca4b5c JMF |
55 | |
56 | def _real_extract(self, url): | |
57 | mobj = re.match(self._VALID_URL, url) | |
4de9e9a6 PH |
58 | video_id = mobj.groupdict().get('id') |
59 | ||
72975729 S |
60 | site_id = self._SITE_ID_MAP[mobj.group('site') or 'canal'] |
61 | ||
4de9e9a6 PH |
62 | # Beware, some subclasses do not define an id group |
63 | display_id = url_basename(mobj.group('path')) | |
b075d25b | 64 | |
ad94a6fe | 65 | if video_id is None: |
4de9e9a6 | 66 | webpage = self._download_webpage(url, display_id) |
72975729 S |
67 | video_id = self._search_regex( |
68 | r'<canal:player[^>]+?videoId="(\d+)"', webpage, 'video id') | |
b075d25b | 69 | |
72975729 | 70 | info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id) |
b075d25b | 71 | doc = self._download_xml(info_url, video_id, 'Downloading video XML') |
ffca4b5c | 72 | |
ffca4b5c | 73 | video_info = [video for video in doc if video.find('ID').text == video_id][0] |
ffca4b5c | 74 | media = video_info.find('MEDIA') |
b075d25b S |
75 | infos = video_info.find('INFOS') |
76 | ||
6e1cff9c | 77 | preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS']) |
b075d25b | 78 | |
6e1cff9c S |
79 | formats = [] |
80 | for fmt in media.find('VIDEOS'): | |
81 | format_url = fmt.text | |
82 | if not format_url: | |
83 | continue | |
84 | format_id = fmt.tag | |
85 | if format_id == 'HLS': | |
86 | hls_formats = self._extract_m3u8_formats(format_url, video_id, 'flv') | |
87 | for fmt in hls_formats: | |
88 | fmt['preference'] = preference(format_id) | |
89 | formats.extend(hls_formats) | |
90 | elif format_id == 'HDS': | |
91 | hds_formats = self._extract_f4m_formats(format_url + '?hdcore=2.11.3', video_id) | |
92 | for fmt in hds_formats: | |
93 | fmt['preference'] = preference(format_id) | |
94 | formats.extend(hds_formats) | |
95 | else: | |
96 | formats.append({ | |
97 | 'url': format_url, | |
98 | 'format_id': format_id, | |
99 | 'preference': preference(format_id), | |
100 | }) | |
b075d25b S |
101 | self._sort_formats(formats) |
102 | ||
103 | return { | |
104 | 'id': video_id, | |
4de9e9a6 | 105 | 'display_id': display_id, |
b075d25b S |
106 | 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text, |
107 | infos.find('TITRAGE/SOUS_TITRE').text), | |
108 | 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text), | |
109 | 'thumbnail': media.find('IMAGES/GRAND').text, | |
110 | 'description': infos.find('DESCRIPTION').text, | |
111 | 'view_count': int(infos.find('NB_VUES').text), | |
112 | 'like_count': int(infos.find('NB_LIKES').text), | |
113 | 'comment_count': int(infos.find('NB_COMMENTS').text), | |
114 | 'formats': formats, | |
5f6a1245 | 115 | } |