]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/canalplus.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class CanalplusIE(InfoExtractor
):
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+)'
19 _VIDEO_INFO_TEMPLATE
= 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json'
22 'piwiplus': 'teletoon',
25 # Only works for direct mp4 URLs
26 _GEO_COUNTRIES
= ['FR']
29 'url': 'https://www.mycanal.fr/d17-emissions/lolywood/p/1397061',
32 'display_id': 'lolywood',
34 'title': 'Euro 2016 : Je préfère te prévenir - Lolywood - Episode 34',
35 'description': 'md5:7d97039d455cb29cdba0d652a0efaa5e',
36 'upload_date': '20160602',
39 # geo restricted, bypassed
40 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190',
43 'display_id': 'pid1405-le-labyrinthe-boing-super-ranger',
45 'title': 'BOING SUPER RANGER - Ep : Le labyrinthe',
46 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff',
47 'upload_date': '20140724',
49 'expected_warnings': ['HTTP Error 403: Forbidden'],
52 def _real_extract(self
, url
):
53 site
, display_id
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
55 site_id
= self
._SITE
_ID
_MAP
[site
]
57 info_url
= self
._VIDEO
_INFO
_TEMPLATE
% (site_id
, video_id
)
58 video_data
= self
._download
_json
(info_url
, video_id
, 'Downloading video JSON')
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']
65 preference
= qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD'])
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',
78 for format_id
, format_url
in media
['VIDEOS'].items():
81 if format_id
== 'HLS':
82 formats
.extend(self
._extract
_m
3u8_formats
(
83 format_url
, video_id
, 'mp4', 'm3u8_native', m3u8_id
=format_id
, fatal
=False))
84 elif format_id
== 'HDS':
85 formats
.extend(self
._extract
_f
4m
_formats
(
86 format_url
+ '?hdcore=2.11.3', video_id
, f4m_id
=format_id
, fatal
=False))
89 # the secret extracted from ya function in http://player.canalplus.fr/common/js/canalPlayer.js
90 'url': format_url
+ '?secret=pqzerjlsmdkjfoiuerhsdlfknaes',
91 'format_id': format_id
,
92 'preference': preference(format_id
),
94 self
._sort
_formats
(formats
)
99 } for image_id
, image_url
in media
.get('images', {}).items()]
101 titrage
= infos
['TITRAGE']
105 'display_id': display_id
,
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')),