]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/telequebec.py
ae9f66787439462967baa63dc58f39870fb89382
[youtubedl] / youtube_dl / extractor / telequebec.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7 int_or_none,
8 smuggle_url,
9 try_get,
10 unified_timestamp,
11 )
12
13
14 class TeleQuebecBaseIE(InfoExtractor):
15 @staticmethod
16 def _limelight_result(media_id):
17 return {
18 '_type': 'url_transparent',
19 'url': smuggle_url(
20 'limelight:media:' + media_id, {'geo_countries': ['CA']}),
21 'ie_key': 'LimelightMedia',
22 }
23
24
25 class TeleQuebecIE(TeleQuebecBaseIE):
26 _VALID_URL = r'''(?x)
27 https?://
28 (?:
29 zonevideo\.telequebec\.tv/media|
30 coucou\.telequebec\.tv/videos
31 )/(?P<id>\d+)
32 '''
33 _TESTS = [{
34 # available till 01.01.2023
35 'url': 'http://zonevideo.telequebec.tv/media/37578/un-petit-choc-et-puis-repart/un-chef-a-la-cabane',
36 'info_dict': {
37 'id': '577116881b4b439084e6b1cf4ef8b1b3',
38 'ext': 'mp4',
39 'title': 'Un petit choc et puis repart!',
40 'description': 'md5:b04a7e6b3f74e32d7b294cffe8658374',
41 'upload_date': '20180222',
42 'timestamp': 1519326631,
43 },
44 'params': {
45 'skip_download': True,
46 },
47 }, {
48 # no description
49 'url': 'http://zonevideo.telequebec.tv/media/30261',
50 'only_matching': True,
51 }, {
52 'url': 'https://coucou.telequebec.tv/videos/41788/idee-de-genie/l-heure-du-bain',
53 'only_matching': True,
54 }]
55
56 def _real_extract(self, url):
57 media_id = self._match_id(url)
58
59 media_data = self._download_json(
60 'https://mnmedias.api.telequebec.tv/api/v2/media/' + media_id,
61 media_id)['media']
62
63 info = self._limelight_result(media_data['streamInfo']['sourceId'])
64 info.update({
65 'title': media_data.get('title'),
66 'description': try_get(
67 media_data, lambda x: x['descriptions'][0]['text'], compat_str),
68 'duration': int_or_none(
69 media_data.get('durationInMilliseconds'), 1000),
70 })
71 return info
72
73
74 class TeleQuebecSquatIE(InfoExtractor):
75 _VALID_URL = r'https://squat\.telequebec\.tv/videos/(?P<id>\d+)'
76 _TESTS = [{
77 'url': 'https://squat.telequebec.tv/videos/9314',
78 'info_dict': {
79 'id': 'd59ae78112d542e793d83cc9d3a5b530',
80 'ext': 'mp4',
81 'title': 'Poupeflekta',
82 'description': 'md5:2f0718f8d2f8fece1646ee25fb7bce75',
83 'duration': 1351,
84 'timestamp': 1569057600,
85 'upload_date': '20190921',
86 'series': 'Miraculous : Les Aventures de Ladybug et Chat Noir',
87 'season': 'Saison 3',
88 'season_number': 3,
89 'episode_number': 57,
90 },
91 'params': {
92 'skip_download': True,
93 },
94 }]
95
96 def _real_extract(self, url):
97 video_id = self._match_id(url)
98
99 video = self._download_json(
100 'https://squat.api.telequebec.tv/v1/videos/%s' % video_id,
101 video_id)
102
103 media_id = video['sourceId']
104
105 return {
106 '_type': 'url_transparent',
107 'url': 'http://zonevideo.telequebec.tv/media/%s' % media_id,
108 'ie_key': TeleQuebecIE.ie_key(),
109 'id': media_id,
110 'title': video.get('titre'),
111 'description': video.get('description'),
112 'timestamp': unified_timestamp(video.get('datePublication')),
113 'series': video.get('container'),
114 'season': video.get('saison'),
115 'season_number': int_or_none(video.get('noSaison')),
116 'episode_number': int_or_none(video.get('episode')),
117 }
118
119
120 class TeleQuebecEmissionIE(TeleQuebecBaseIE):
121 _VALID_URL = r'''(?x)
122 https?://
123 (?:
124 [^/]+\.telequebec\.tv/emissions/|
125 (?:www\.)?telequebec\.tv/
126 )
127 (?P<id>[^?#&]+)
128 '''
129 _TESTS = [{
130 'url': 'http://lindicemcsween.telequebec.tv/emissions/100430013/des-soins-esthetiques-a-377-d-interets-annuels-ca-vous-tente',
131 'info_dict': {
132 'id': '66648a6aef914fe3badda25e81a4d50a',
133 'ext': 'mp4',
134 'title': "Des soins esthétiques à 377 % d'intérêts annuels, ça vous tente?",
135 'description': 'md5:369e0d55d0083f1fc9b71ffb640ea014',
136 'upload_date': '20171024',
137 'timestamp': 1508862118,
138 },
139 'params': {
140 'skip_download': True,
141 },
142 }, {
143 'url': 'http://bancpublic.telequebec.tv/emissions/emission-49/31986/jeunes-meres-sous-pression',
144 'only_matching': True,
145 }, {
146 'url': 'http://www.telequebec.tv/masha-et-michka/epi059masha-et-michka-3-053-078',
147 'only_matching': True,
148 }, {
149 'url': 'http://www.telequebec.tv/documentaire/bebes-sur-mesure/',
150 'only_matching': True,
151 }]
152
153 def _real_extract(self, url):
154 display_id = self._match_id(url)
155
156 webpage = self._download_webpage(url, display_id)
157
158 media_id = self._search_regex(
159 r'mediaUID\s*:\s*["\'][Ll]imelight_(?P<id>[a-z0-9]{32})', webpage,
160 'limelight id')
161
162 info = self._limelight_result(media_id)
163 info.update({
164 'title': self._og_search_title(webpage, default=None),
165 'description': self._og_search_description(webpage, default=None),
166 })
167 return info
168
169
170 class TeleQuebecLiveIE(InfoExtractor):
171 _VALID_URL = r'https?://zonevideo\.telequebec\.tv/(?P<id>endirect)'
172 _TEST = {
173 'url': 'http://zonevideo.telequebec.tv/endirect/',
174 'info_dict': {
175 'id': 'endirect',
176 'ext': 'mp4',
177 'title': 're:^Télé-Québec - En direct [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
178 'is_live': True,
179 },
180 'params': {
181 'skip_download': True,
182 },
183 }
184
185 def _real_extract(self, url):
186 video_id = self._match_id(url)
187
188 m3u8_url = None
189 webpage = self._download_webpage(
190 'https://player.telequebec.tv/Tq_VideoPlayer.js', video_id,
191 fatal=False)
192 if webpage:
193 m3u8_url = self._search_regex(
194 r'm3U8Url\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
195 'm3u8 url', default=None, group='url')
196 if not m3u8_url:
197 m3u8_url = 'https://teleqmmd.mmdlive.lldns.net/teleqmmd/f386e3b206814e1f8c8c1c71c0f8e748/manifest.m3u8'
198 formats = self._extract_m3u8_formats(
199 m3u8_url, video_id, 'mp4', m3u8_id='hls')
200 self._sort_formats(formats)
201
202 return {
203 'id': video_id,
204 'title': self._live_title('Télé-Québec - En direct'),
205 'is_live': True,
206 'formats': formats,
207 }