]>
Commit | Line | Data |
---|---|---|
ffca4b5c | 1 | from .common import InfoExtractor |
4de9e9a6 | 2 | from ..utils import ( |
6f1b2374 S |
3 | # ExtractorError, |
4 | # HEADRequest, | |
d5f6429d | 5 | int_or_none, |
e2004cca | 6 | qualities, |
e2004cca | 7 | unified_strdate, |
4de9e9a6 | 8 | ) |
ffca4b5c | 9 | |
69545c2a | 10 | |
ffca4b5c | 11 | class CanalplusIE(InfoExtractor): |
a39e15c5 RA |
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+)' | |
d5f6429d | 14 | _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json' |
72975729 | 15 | _SITE_ID_MAP = { |
a39e15c5 | 16 | 'mycanal': 'cplus', |
74193838 | 17 | 'piwiplus': 'teletoon', |
72975729 | 18 | } |
ffca4b5c | 19 | |
6214611a S |
20 | # Only works for direct mp4 URLs |
21 | _GEO_COUNTRIES = ['FR'] | |
22 | ||
72975729 | 23 | _TESTS = [{ |
a39e15c5 | 24 | 'url': 'https://www.mycanal.fr/d17-emissions/lolywood/p/1397061', |
b075d25b | 25 | 'info_dict': { |
a39e15c5 RA |
26 | 'id': '1397061', |
27 | 'display_id': 'lolywood', | |
d5f6429d | 28 | 'ext': 'mp4', |
a39e15c5 RA |
29 | 'title': 'Euro 2016 : Je préfère te prévenir - Lolywood - Episode 34', |
30 | 'description': 'md5:7d97039d455cb29cdba0d652a0efaa5e', | |
31 | 'upload_date': '20160602', | |
ad94a6fe | 32 | }, |
72975729 | 33 | }, { |
6214611a | 34 | # geo restricted, bypassed |
72975729 | 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', | |
e2004cca YCH |
38 | 'display_id': 'pid1405-le-labyrinthe-boing-super-ranger', |
39 | 'ext': 'mp4', | |
40 | 'title': 'BOING SUPER RANGER - Ep : Le labyrinthe', | |
6e1cff9c | 41 | 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff', |
72975729 S |
42 | 'upload_date': '20140724', |
43 | }, | |
6214611a | 44 | 'expected_warnings': ['HTTP Error 403: Forbidden'], |
72975729 | 45 | }] |
ffca4b5c JMF |
46 | |
47 | def _real_extract(self, url): | |
5ad28e7f | 48 | site, display_id, video_id = self._match_valid_url(url).groups() |
b075d25b | 49 | |
a39e15c5 | 50 | site_id = self._SITE_ID_MAP[site] |
b075d25b | 51 | |
72975729 | 52 | info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id) |
d5f6429d | 53 | video_data = self._download_json(info_url, video_id, 'Downloading video JSON') |
ffca4b5c | 54 | |
d5f6429d | 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'] | |
b075d25b | 59 | |
d5f6429d | 60 | preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD']) |
b075d25b | 61 | |
6214611a S |
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') | |
3d2623a8 | 67 | # if '/blocage' in response.url: |
6214611a S |
68 | # raise ExtractorError( |
69 | # 'The video is not available in your country', | |
70 | # expected=True) | |
817f786f | 71 | |
6e1cff9c | 72 | formats = [] |
d5f6429d | 73 | for format_id, format_url in media['VIDEOS'].items(): |
6e1cff9c S |
74 | if not format_url: |
75 | continue | |
6e1cff9c | 76 | if format_id == 'HLS': |
f3f0b8e4 | 77 | formats.extend(self._extract_m3u8_formats( |
d5f6429d | 78 | format_url, video_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False)) |
6e1cff9c | 79 | elif format_id == 'HDS': |
f3f0b8e4 | 80 | formats.extend(self._extract_f4m_formats( |
d5f6429d | 81 | format_url + '?hdcore=2.11.3', video_id, f4m_id=format_id, fatal=False)) |
6e1cff9c S |
82 | else: |
83 | formats.append({ | |
a39e15c5 | 84 | # the secret extracted from ya function in http://player.canalplus.fr/common/js/canalPlayer.js |
d5f6429d | 85 | 'url': format_url + '?secret=pqzerjlsmdkjfoiuerhsdlfknaes', |
6e1cff9c | 86 | 'format_id': format_id, |
f983b875 | 87 | 'quality': preference(format_id), |
6e1cff9c | 88 | }) |
b075d25b | 89 | |
d5f6429d | 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 | ||
b075d25b S |
97 | return { |
98 | 'id': video_id, | |
4de9e9a6 | 99 | 'display_id': display_id, |
d5f6429d | 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')), | |
b075d25b | 109 | 'formats': formats, |
5f6a1245 | 110 | } |