]>
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 | 7 | from ..utils import ( |
817f786f JMF |
8 | ExtractorError, |
9 | HEADRequest, | |
4de9e9a6 PH |
10 | unified_strdate, |
11 | url_basename, | |
6e1cff9c | 12 | qualities, |
d5f6429d | 13 | int_or_none, |
4de9e9a6 | 14 | ) |
ffca4b5c | 15 | |
69545c2a | 16 | |
ffca4b5c | 17 | class CanalplusIE(InfoExtractor): |
6e1cff9c | 18 | IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv' |
ea5db846 | 19 | _VALID_URL = r'https?://(?:www\.(?P<site>canalplus\.fr|piwiplus\.fr|d8\.tv|itele\.fr)/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))' |
d5f6429d | 20 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json' |
72975729 | 21 | _SITE_ID_MAP = { |
6e1cff9c S |
22 | 'canalplus.fr': 'cplus', |
23 | 'piwiplus.fr': 'teletoon', | |
24 | 'd8.tv': 'd8', | |
ea5db846 | 25 | 'itele.fr': 'itele', |
72975729 | 26 | } |
ffca4b5c | 27 | |
72975729 | 28 | _TESTS = [{ |
509c630d | 29 | 'url': 'http://www.canalplus.fr/c-emissions/pid1830-c-zapping.html?vid=1263092', |
d5f6429d | 30 | 'md5': '12164a6f14ff6df8bd628e8ba9b10b78', |
b075d25b | 31 | 'info_dict': { |
509c630d | 32 | 'id': '1263092', |
d5f6429d | 33 | 'ext': 'mp4', |
509c630d | 34 | 'title': 'Le Zapping - 13/05/15', |
35 | 'description': 'md5:09738c0d06be4b5d06a0940edb0da73f', | |
36 | 'upload_date': '20150513', | |
ad94a6fe | 37 | }, |
72975729 S |
38 | }, { |
39 | 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190', | |
72975729 S |
40 | 'info_dict': { |
41 | 'id': '1108190', | |
42 | 'ext': 'flv', | |
43 | 'title': 'Le labyrinthe - Boing super ranger', | |
6e1cff9c | 44 | 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff', |
72975729 S |
45 | 'upload_date': '20140724', |
46 | }, | |
6e1cff9c S |
47 | 'skip': 'Only works from France', |
48 | }, { | |
49 | 'url': 'http://www.d8.tv/d8-docs-mags/pid6589-d8-campagne-intime.html', | |
50 | 'info_dict': { | |
51 | 'id': '966289', | |
52 | 'ext': 'flv', | |
53 | 'title': 'Campagne intime - Documentaire exceptionnel', | |
54 | 'description': 'md5:d2643b799fb190846ae09c61e59a859f', | |
55 | 'upload_date': '20131108', | |
56 | }, | |
57 | 'skip': 'videos get deleted after a while', | |
ea5db846 NJ |
58 | }, { |
59 | 'url': 'http://www.itele.fr/france/video/aubervilliers-un-lycee-en-colere-111559', | |
d5f6429d | 60 | 'md5': '38b8f7934def74f0d6f3ba6c036a5f82', |
ea5db846 NJ |
61 | 'info_dict': { |
62 | 'id': '1213714', | |
d5f6429d | 63 | 'ext': 'mp4', |
ea5db846 NJ |
64 | 'title': 'Aubervilliers : un lycée en colère - Le 11/02/2015 à 06h45', |
65 | 'description': 'md5:8216206ec53426ea6321321f3b3c16db', | |
66 | 'upload_date': '20150211', | |
67 | }, | |
72975729 | 68 | }] |
ffca4b5c JMF |
69 | |
70 | def _real_extract(self, url): | |
71 | mobj = re.match(self._VALID_URL, url) | |
4de9e9a6 PH |
72 | video_id = mobj.groupdict().get('id') |
73 | ||
72975729 S |
74 | site_id = self._SITE_ID_MAP[mobj.group('site') or 'canal'] |
75 | ||
4de9e9a6 PH |
76 | # Beware, some subclasses do not define an id group |
77 | display_id = url_basename(mobj.group('path')) | |
b075d25b | 78 | |
ad94a6fe | 79 | if video_id is None: |
4de9e9a6 | 80 | webpage = self._download_webpage(url, display_id) |
72975729 | 81 | video_id = self._search_regex( |
83a56686 | 82 | [r'<canal:player[^>]+?videoId=(["\'])(?P<id>\d+)', r'id=["\']canal_video_player(?P<id>\d+)'], |
fc10824c | 83 | webpage, 'video id', group='id') |
b075d25b | 84 | |
72975729 | 85 | info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id) |
d5f6429d | 86 | video_data = self._download_json(info_url, video_id, 'Downloading video JSON') |
ffca4b5c | 87 | |
d5f6429d | 88 | if isinstance(video_data, list): |
89 | video_data = [video for video in video_data if video.get('ID') == video_id][0] | |
90 | media = video_data['MEDIA'] | |
91 | infos = video_data['INFOS'] | |
b075d25b | 92 | |
d5f6429d | 93 | preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD']) |
b075d25b | 94 | |
d5f6429d | 95 | fmt_url = next(iter(media.get('VIDEOS'))) |
817f786f JMF |
96 | if '/geo' in fmt_url.lower(): |
97 | response = self._request_webpage( | |
98 | HEADRequest(fmt_url), video_id, | |
99 | 'Checking if the video is georestricted') | |
100 | if '/blocage' in response.geturl(): | |
101 | raise ExtractorError( | |
102 | 'The video is not available in your country', | |
103 | expected=True) | |
104 | ||
6e1cff9c | 105 | formats = [] |
d5f6429d | 106 | for format_id, format_url in media['VIDEOS'].items(): |
6e1cff9c S |
107 | if not format_url: |
108 | continue | |
6e1cff9c | 109 | if format_id == 'HLS': |
f3f0b8e4 | 110 | formats.extend(self._extract_m3u8_formats( |
d5f6429d | 111 | format_url, video_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False)) |
6e1cff9c | 112 | elif format_id == 'HDS': |
f3f0b8e4 | 113 | formats.extend(self._extract_f4m_formats( |
d5f6429d | 114 | format_url + '?hdcore=2.11.3', video_id, f4m_id=format_id, fatal=False)) |
6e1cff9c S |
115 | else: |
116 | formats.append({ | |
d5f6429d | 117 | # the secret extracted ya function in http://player.canalplus.fr/common/js/canalPlayer.js |
118 | 'url': format_url + '?secret=pqzerjlsmdkjfoiuerhsdlfknaes', | |
6e1cff9c S |
119 | 'format_id': format_id, |
120 | 'preference': preference(format_id), | |
121 | }) | |
b075d25b S |
122 | self._sort_formats(formats) |
123 | ||
d5f6429d | 124 | thumbnails = [{ |
125 | 'id': image_id, | |
126 | 'url': image_url, | |
127 | } for image_id, image_url in media.get('images', {}).items()] | |
128 | ||
129 | titrage = infos['TITRAGE'] | |
130 | ||
b075d25b S |
131 | return { |
132 | 'id': video_id, | |
4de9e9a6 | 133 | 'display_id': display_id, |
d5f6429d | 134 | 'title': '%s - %s' % (titrage['TITRE'], |
135 | titrage['SOUS_TITRE']), | |
136 | 'upload_date': unified_strdate(infos.get('PUBLICATION', {}).get('DATE')), | |
137 | 'thumbnails': thumbnails, | |
138 | 'description': infos.get('DESCRIPTION'), | |
139 | 'duration': int_or_none(infos.get('DURATION')), | |
140 | 'view_count': int_or_none(infos.get('NB_VUES')), | |
141 | 'like_count': int_or_none(infos.get('NB_LIKES')), | |
142 | 'comment_count': int_or_none(infos.get('NB_COMMENTS')), | |
b075d25b | 143 | 'formats': formats, |
5f6a1245 | 144 | } |