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