]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
b075d25b S |
2 | from __future__ import unicode_literals |
3 | ||
ffca4b5c | 4 | import re |
ffca4b5c JMF |
5 | |
6 | from .common import InfoExtractor | |
74193838 | 7 | from ..compat import compat_urllib_parse_urlparse |
4de9e9a6 | 8 | from ..utils import ( |
e2004cca | 9 | dict_get, |
6f1b2374 S |
10 | # ExtractorError, |
11 | # HEADRequest, | |
d5f6429d | 12 | int_or_none, |
e2004cca YCH |
13 | qualities, |
14 | remove_end, | |
15 | unified_strdate, | |
4de9e9a6 | 16 | ) |
ffca4b5c | 17 | |
69545c2a | 18 | |
ffca4b5c | 19 | class CanalplusIE(InfoExtractor): |
6e1cff9c | 20 | IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv' |
74193838 S |
21 | _VALID_URL = r'''(?x) |
22 | https?:// | |
23 | (?: | |
24 | (?: | |
25 | (?:(?:www|m)\.)?canalplus\.fr| | |
26 | (?:www\.)?piwiplus\.fr| | |
27 | (?:www\.)?d8\.tv| | |
b29f842e | 28 | (?:www\.)?c8\.fr| |
57b6e965 | 29 | (?:www\.)?d17\.tv| |
d5d904ff | 30 | (?:(?:football|www)\.)?cstar\.fr| |
74193838 S |
31 | (?:www\.)?itele\.fr |
32 | )/(?:(?:[^/]+/)*(?P<display_id>[^/?#&]+))?(?:\?.*\bvid=(?P<vid>\d+))?| | |
33 | player\.canalplus\.fr/#/(?P<id>\d+) | |
34 | ) | |
35 | ||
36 | ''' | |
d5f6429d | 37 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json' |
72975729 | 38 | _SITE_ID_MAP = { |
74193838 S |
39 | 'canalplus': 'cplus', |
40 | 'piwiplus': 'teletoon', | |
41 | 'd8': 'd8', | |
b29f842e | 42 | 'c8': 'd8', |
57b6e965 | 43 | 'd17': 'd17', |
d5d904ff | 44 | 'cstar': 'd17', |
74193838 | 45 | 'itele': 'itele', |
72975729 | 46 | } |
ffca4b5c | 47 | |
6214611a S |
48 | # Only works for direct mp4 URLs |
49 | _GEO_COUNTRIES = ['FR'] | |
50 | ||
72975729 | 51 | _TESTS = [{ |
3d9b3605 | 52 | 'url': 'http://www.canalplus.fr/c-emissions/pid1830-c-zapping.html?vid=1192814', |
b075d25b | 53 | 'info_dict': { |
e2004cca YCH |
54 | 'id': '1405510', |
55 | 'display_id': 'pid1830-c-zapping', | |
d5f6429d | 56 | 'ext': 'mp4', |
e2004cca YCH |
57 | 'title': 'Zapping - 02/07/2016', |
58 | 'description': 'Le meilleur de toutes les chaînes, tous les jours', | |
59 | 'upload_date': '20160702', | |
ad94a6fe | 60 | }, |
72975729 | 61 | }, { |
6214611a | 62 | # geo restricted, bypassed |
72975729 | 63 | 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190', |
72975729 S |
64 | 'info_dict': { |
65 | 'id': '1108190', | |
e2004cca YCH |
66 | 'display_id': 'pid1405-le-labyrinthe-boing-super-ranger', |
67 | 'ext': 'mp4', | |
68 | 'title': 'BOING SUPER RANGER - Ep : Le labyrinthe', | |
6e1cff9c | 69 | 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff', |
72975729 S |
70 | 'upload_date': '20140724', |
71 | }, | |
6214611a | 72 | 'expected_warnings': ['HTTP Error 403: Forbidden'], |
6e1cff9c | 73 | }, { |
6214611a S |
74 | # geo restricted, bypassed |
75 | 'url': 'http://www.c8.fr/c8-divertissement/ms-touche-pas-a-mon-poste/pid6318-videos-integrales.html?vid=1443684', | |
76 | 'md5': 'bb6f9f343296ab7ebd88c97b660ecf8d', | |
6e1cff9c | 77 | 'info_dict': { |
6214611a | 78 | 'id': '1443684', |
e2004cca | 79 | 'display_id': 'pid6318-videos-integrales', |
3d9b3605 | 80 | 'ext': 'mp4', |
6214611a S |
81 | 'title': 'Guess my iep ! - TPMP - 07/04/2017', |
82 | 'description': 'md5:6f005933f6e06760a9236d9b3b5f17fa', | |
83 | 'upload_date': '20170407', | |
6e1cff9c | 84 | }, |
6214611a | 85 | 'expected_warnings': ['HTTP Error 403: Forbidden'], |
ea5db846 | 86 | }, { |
e2004cca | 87 | 'url': 'http://www.itele.fr/chroniques/invite-michael-darmon/rachida-dati-nicolas-sarkozy-est-le-plus-en-phase-avec-les-inquietudes-des-francais-171510', |
ea5db846 | 88 | 'info_dict': { |
e2004cca YCH |
89 | 'id': '1420176', |
90 | 'display_id': 'rachida-dati-nicolas-sarkozy-est-le-plus-en-phase-avec-les-inquietudes-des-francais-171510', | |
d5f6429d | 91 | 'ext': 'mp4', |
e2004cca YCH |
92 | 'title': 'L\'invité de Michaël Darmon du 14/10/2016 - ', |
93 | 'description': 'Chaque matin du lundi au vendredi, Michaël Darmon reçoit un invité politique à 8h25.', | |
94 | 'upload_date': '20161014', | |
ea5db846 | 95 | }, |
d5d904ff S |
96 | }, { |
97 | 'url': 'http://football.cstar.fr/cstar-minisite-foot/pid7566-feminines-videos.html?vid=1416769', | |
98 | 'info_dict': { | |
99 | 'id': '1416769', | |
100 | 'display_id': 'pid7566-feminines-videos', | |
101 | 'ext': 'mp4', | |
102 | 'title': 'France - Albanie : les temps forts de la soirée - 20/09/2016', | |
103 | 'description': 'md5:c3f30f2aaac294c1c969b3294de6904e', | |
104 | 'upload_date': '20160921', | |
105 | }, | |
106 | 'params': { | |
107 | 'skip_download': True, | |
108 | }, | |
74193838 S |
109 | }, { |
110 | 'url': 'http://m.canalplus.fr/?vid=1398231', | |
111 | 'only_matching': True, | |
57b6e965 S |
112 | }, { |
113 | 'url': 'http://www.d17.tv/emissions/pid8303-lolywood.html?vid=1397061', | |
114 | 'only_matching': True, | |
72975729 | 115 | }] |
ffca4b5c JMF |
116 | |
117 | def _real_extract(self, url): | |
118 | mobj = re.match(self._VALID_URL, url) | |
4de9e9a6 | 119 | |
74193838 | 120 | site_id = self._SITE_ID_MAP[compat_urllib_parse_urlparse(url).netloc.rsplit('.', 2)[-2]] |
72975729 | 121 | |
4de9e9a6 | 122 | # Beware, some subclasses do not define an id group |
e2004cca | 123 | display_id = remove_end(dict_get(mobj.groupdict(), ('display_id', 'id', 'vid')), '.html') |
b075d25b | 124 | |
e2004cca YCH |
125 | webpage = self._download_webpage(url, display_id) |
126 | video_id = self._search_regex( | |
127 | [r'<canal:player[^>]+?videoId=(["\'])(?P<id>\d+)', | |
6ca478d4 S |
128 | r'id=["\']canal_video_player(?P<id>\d+)', |
129 | r'data-video=["\'](?P<id>\d+)'], | |
aaf2b7c5 | 130 | webpage, 'video id', default=mobj.group('vid'), group='id') |
b075d25b | 131 | |
72975729 | 132 | info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id) |
d5f6429d | 133 | video_data = self._download_json(info_url, video_id, 'Downloading video JSON') |
ffca4b5c | 134 | |
d5f6429d | 135 | if isinstance(video_data, list): |
136 | video_data = [video for video in video_data if video.get('ID') == video_id][0] | |
137 | media = video_data['MEDIA'] | |
138 | infos = video_data['INFOS'] | |
b075d25b | 139 | |
d5f6429d | 140 | preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD']) |
b075d25b | 141 | |
6214611a S |
142 | # _, fmt_url = next(iter(media['VIDEOS'].items())) |
143 | # if '/geo' in fmt_url.lower(): | |
144 | # response = self._request_webpage( | |
145 | # HEADRequest(fmt_url), video_id, | |
146 | # 'Checking if the video is georestricted') | |
147 | # if '/blocage' in response.geturl(): | |
148 | # raise ExtractorError( | |
149 | # 'The video is not available in your country', | |
150 | # expected=True) | |
817f786f | 151 | |
6e1cff9c | 152 | formats = [] |
d5f6429d | 153 | for format_id, format_url in media['VIDEOS'].items(): |
6e1cff9c S |
154 | if not format_url: |
155 | continue | |
6e1cff9c | 156 | if format_id == 'HLS': |
f3f0b8e4 | 157 | formats.extend(self._extract_m3u8_formats( |
d5f6429d | 158 | format_url, video_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False)) |
6e1cff9c | 159 | elif format_id == 'HDS': |
f3f0b8e4 | 160 | formats.extend(self._extract_f4m_formats( |
d5f6429d | 161 | format_url + '?hdcore=2.11.3', video_id, f4m_id=format_id, fatal=False)) |
6e1cff9c S |
162 | else: |
163 | formats.append({ | |
d5f6429d | 164 | # the secret extracted ya function in http://player.canalplus.fr/common/js/canalPlayer.js |
165 | 'url': format_url + '?secret=pqzerjlsmdkjfoiuerhsdlfknaes', | |
6e1cff9c S |
166 | 'format_id': format_id, |
167 | 'preference': preference(format_id), | |
168 | }) | |
b075d25b S |
169 | self._sort_formats(formats) |
170 | ||
d5f6429d | 171 | thumbnails = [{ |
172 | 'id': image_id, | |
173 | 'url': image_url, | |
174 | } for image_id, image_url in media.get('images', {}).items()] | |
175 | ||
176 | titrage = infos['TITRAGE'] | |
177 | ||
b075d25b S |
178 | return { |
179 | 'id': video_id, | |
4de9e9a6 | 180 | 'display_id': display_id, |
d5f6429d | 181 | 'title': '%s - %s' % (titrage['TITRE'], |
182 | titrage['SOUS_TITRE']), | |
183 | 'upload_date': unified_strdate(infos.get('PUBLICATION', {}).get('DATE')), | |
184 | 'thumbnails': thumbnails, | |
185 | 'description': infos.get('DESCRIPTION'), | |
186 | 'duration': int_or_none(infos.get('DURATION')), | |
187 | 'view_count': int_or_none(infos.get('NB_VUES')), | |
188 | 'like_count': int_or_none(infos.get('NB_LIKES')), | |
189 | 'comment_count': int_or_none(infos.get('NB_COMMENTS')), | |
b075d25b | 190 | 'formats': formats, |
5f6a1245 | 191 | } |