]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/canalplus.py
[ssa] Add extractor (Closes #5169)
[yt-dlp.git] / youtube_dl / extractor / canalplus.py
CommitLineData
ad94a6fe 1# encoding: utf-8
b075d25b
S
2from __future__ import unicode_literals
3
ffca4b5c 4import re
ffca4b5c
JMF
5
6from .common import InfoExtractor
4de9e9a6 7from ..utils import (
817f786f
JMF
8 ExtractorError,
9 HEADRequest,
4de9e9a6
PH
10 unified_strdate,
11 url_basename,
6e1cff9c 12 qualities,
4de9e9a6 13)
ffca4b5c 14
69545c2a 15
ffca4b5c 16class CanalplusIE(InfoExtractor):
6e1cff9c 17 IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv'
ea5db846 18 _VALID_URL = r'https?://(?:www\.(?P<site>canalplus\.fr|piwiplus\.fr|d8\.tv|itele\.fr)/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))'
72975729
S
19 _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s'
20 _SITE_ID_MAP = {
6e1cff9c
S
21 'canalplus.fr': 'cplus',
22 'piwiplus.fr': 'teletoon',
23 'd8.tv': 'd8',
ea5db846 24 'itele.fr': 'itele',
72975729 25 }
ffca4b5c 26
72975729 27 _TESTS = [{
b075d25b 28 'url': 'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470',
113c7d3e 29 'md5': '3db39fb48b9685438ecf33a1078023e4',
b075d25b
S
30 'info_dict': {
31 'id': '922470',
32 'ext': 'flv',
33 'title': 'Zapping - 26/08/13',
34 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
35 'upload_date': '20130826',
ad94a6fe 36 },
72975729
S
37 }, {
38 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190',
72975729
S
39 'info_dict': {
40 'id': '1108190',
41 'ext': 'flv',
42 'title': 'Le labyrinthe - Boing super ranger',
6e1cff9c 43 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff',
72975729
S
44 'upload_date': '20140724',
45 },
6e1cff9c
S
46 'skip': 'Only works from France',
47 }, {
48 'url': 'http://www.d8.tv/d8-docs-mags/pid6589-d8-campagne-intime.html',
49 'info_dict': {
50 'id': '966289',
51 'ext': 'flv',
52 'title': 'Campagne intime - Documentaire exceptionnel',
53 'description': 'md5:d2643b799fb190846ae09c61e59a859f',
54 'upload_date': '20131108',
55 },
56 'skip': 'videos get deleted after a while',
ea5db846
NJ
57 }, {
58 'url': 'http://www.itele.fr/france/video/aubervilliers-un-lycee-en-colere-111559',
59 'md5': '65aa83ad62fe107ce29e564bb8712580',
60 'info_dict': {
61 'id': '1213714',
62 'ext': 'flv',
63 'title': 'Aubervilliers : un lycée en colère - Le 11/02/2015 à 06h45',
64 'description': 'md5:8216206ec53426ea6321321f3b3c16db',
65 'upload_date': '20150211',
66 },
72975729 67 }]
ffca4b5c
JMF
68
69 def _real_extract(self, url):
70 mobj = re.match(self._VALID_URL, url)
4de9e9a6
PH
71 video_id = mobj.groupdict().get('id')
72
72975729
S
73 site_id = self._SITE_ID_MAP[mobj.group('site') or 'canal']
74
4de9e9a6
PH
75 # Beware, some subclasses do not define an id group
76 display_id = url_basename(mobj.group('path'))
b075d25b 77
ad94a6fe 78 if video_id is None:
4de9e9a6 79 webpage = self._download_webpage(url, display_id)
72975729
S
80 video_id = self._search_regex(
81 r'<canal:player[^>]+?videoId="(\d+)"', webpage, 'video id')
b075d25b 82
72975729 83 info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id)
b075d25b 84 doc = self._download_xml(info_url, video_id, 'Downloading video XML')
ffca4b5c 85
ffca4b5c 86 video_info = [video for video in doc if video.find('ID').text == video_id][0]
ffca4b5c 87 media = video_info.find('MEDIA')
b075d25b
S
88 infos = video_info.find('INFOS')
89
6e1cff9c 90 preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS'])
b075d25b 91
817f786f
JMF
92 fmt_url = next(iter(media.find('VIDEOS'))).text
93 if '/geo' in fmt_url.lower():
94 response = self._request_webpage(
95 HEADRequest(fmt_url), video_id,
96 'Checking if the video is georestricted')
97 if '/blocage' in response.geturl():
98 raise ExtractorError(
99 'The video is not available in your country',
100 expected=True)
101
6e1cff9c
S
102 formats = []
103 for fmt in media.find('VIDEOS'):
104 format_url = fmt.text
105 if not format_url:
106 continue
107 format_id = fmt.tag
108 if format_id == 'HLS':
109 hls_formats = self._extract_m3u8_formats(format_url, video_id, 'flv')
110 for fmt in hls_formats:
111 fmt['preference'] = preference(format_id)
112 formats.extend(hls_formats)
113 elif format_id == 'HDS':
114 hds_formats = self._extract_f4m_formats(format_url + '?hdcore=2.11.3', video_id)
115 for fmt in hds_formats:
116 fmt['preference'] = preference(format_id)
117 formats.extend(hds_formats)
118 else:
119 formats.append({
120 'url': format_url,
121 'format_id': format_id,
122 'preference': preference(format_id),
123 })
b075d25b
S
124 self._sort_formats(formats)
125
126 return {
127 'id': video_id,
4de9e9a6 128 'display_id': display_id,
b075d25b
S
129 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
130 infos.find('TITRAGE/SOUS_TITRE').text),
131 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
132 'thumbnail': media.find('IMAGES/GRAND').text,
133 'description': infos.find('DESCRIPTION').text,
134 'view_count': int(infos.find('NB_VUES').text),
135 'like_count': int(infos.find('NB_LIKES').text),
136 'comment_count': int(infos.find('NB_COMMENTS').text),
137 'formats': formats,
5f6a1245 138 }