]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | # ExtractorError, | |
4 | # HEADRequest, | |
5 | int_or_none, | |
6 | qualities, | |
7 | unified_strdate, | |
8 | ) | |
9 | ||
10 | ||
11 | class CanalplusIE(InfoExtractor): | |
12 | IE_DESC = 'mycanal.fr and piwiplus.fr' | |
13 | _VALID_URL = r'https?://(?:www\.)?(?P<site>mycanal|piwiplus)\.fr/(?:[^/]+/)*(?P<display_id>[^?/]+)(?:\.html\?.*\bvid=|/p/)(?P<id>\d+)' | |
14 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json' | |
15 | _SITE_ID_MAP = { | |
16 | 'mycanal': 'cplus', | |
17 | 'piwiplus': 'teletoon', | |
18 | } | |
19 | ||
20 | # Only works for direct mp4 URLs | |
21 | _GEO_COUNTRIES = ['FR'] | |
22 | ||
23 | _TESTS = [{ | |
24 | 'url': 'https://www.mycanal.fr/d17-emissions/lolywood/p/1397061', | |
25 | 'info_dict': { | |
26 | 'id': '1397061', | |
27 | 'display_id': 'lolywood', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Euro 2016 : Je préfère te prévenir - Lolywood - Episode 34', | |
30 | 'description': 'md5:7d97039d455cb29cdba0d652a0efaa5e', | |
31 | 'upload_date': '20160602', | |
32 | }, | |
33 | }, { | |
34 | # geo restricted, bypassed | |
35 | 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190', | |
36 | 'info_dict': { | |
37 | 'id': '1108190', | |
38 | 'display_id': 'pid1405-le-labyrinthe-boing-super-ranger', | |
39 | 'ext': 'mp4', | |
40 | 'title': 'BOING SUPER RANGER - Ep : Le labyrinthe', | |
41 | 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff', | |
42 | 'upload_date': '20140724', | |
43 | }, | |
44 | 'expected_warnings': ['HTTP Error 403: Forbidden'], | |
45 | }] | |
46 | ||
47 | def _real_extract(self, url): | |
48 | site, display_id, video_id = self._match_valid_url(url).groups() | |
49 | ||
50 | site_id = self._SITE_ID_MAP[site] | |
51 | ||
52 | info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id) | |
53 | video_data = self._download_json(info_url, video_id, 'Downloading video JSON') | |
54 | ||
55 | if isinstance(video_data, list): | |
56 | video_data = [video for video in video_data if video.get('ID') == video_id][0] | |
57 | media = video_data['MEDIA'] | |
58 | infos = video_data['INFOS'] | |
59 | ||
60 | preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD']) | |
61 | ||
62 | # _, fmt_url = next(iter(media['VIDEOS'].items())) | |
63 | # if '/geo' in fmt_url.lower(): | |
64 | # response = self._request_webpage( | |
65 | # HEADRequest(fmt_url), video_id, | |
66 | # 'Checking if the video is georestricted') | |
67 | # if '/blocage' in response.url: | |
68 | # raise ExtractorError( | |
69 | # 'The video is not available in your country', | |
70 | # expected=True) | |
71 | ||
72 | formats = [] | |
73 | for format_id, format_url in media['VIDEOS'].items(): | |
74 | if not format_url: | |
75 | continue | |
76 | if format_id == 'HLS': | |
77 | formats.extend(self._extract_m3u8_formats( | |
78 | format_url, video_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False)) | |
79 | elif format_id == 'HDS': | |
80 | formats.extend(self._extract_f4m_formats( | |
81 | format_url + '?hdcore=2.11.3', video_id, f4m_id=format_id, fatal=False)) | |
82 | else: | |
83 | formats.append({ | |
84 | # the secret extracted from ya function in http://player.canalplus.fr/common/js/canalPlayer.js | |
85 | 'url': format_url + '?secret=pqzerjlsmdkjfoiuerhsdlfknaes', | |
86 | 'format_id': format_id, | |
87 | 'quality': preference(format_id), | |
88 | }) | |
89 | ||
90 | thumbnails = [{ | |
91 | 'id': image_id, | |
92 | 'url': image_url, | |
93 | } for image_id, image_url in media.get('images', {}).items()] | |
94 | ||
95 | titrage = infos['TITRAGE'] | |
96 | ||
97 | return { | |
98 | 'id': video_id, | |
99 | 'display_id': display_id, | |
100 | 'title': '%s - %s' % (titrage['TITRE'], | |
101 | titrage['SOUS_TITRE']), | |
102 | 'upload_date': unified_strdate(infos.get('PUBLICATION', {}).get('DATE')), | |
103 | 'thumbnails': thumbnails, | |
104 | 'description': infos.get('DESCRIPTION'), | |
105 | 'duration': int_or_none(infos.get('DURATION')), | |
106 | 'view_count': int_or_none(infos.get('NB_VUES')), | |
107 | 'like_count': int_or_none(infos.get('NB_LIKES')), | |
108 | 'comment_count': int_or_none(infos.get('NB_COMMENTS')), | |
109 | 'formats': formats, | |
110 | } |