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