]>
Commit | Line | Data |
---|---|---|
1220352f S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
f0d31c62 | 7 | from ..compat import ( |
3859ebee | 8 | compat_HTTPError, |
f0d31c62 S |
9 | compat_urlparse, |
10 | ) | |
1220352f | 11 | from ..utils import ( |
3859ebee S |
12 | determine_ext, |
13 | ExtractorError, | |
14 | int_or_none, | |
1220352f S |
15 | parse_iso8601, |
16 | qualities, | |
896a88c5 | 17 | traverse_obj, |
502d87c5 | 18 | try_get, |
4a7a5e41 | 19 | update_url_query, |
3052a30d | 20 | url_or_none, |
29f7c58a | 21 | urljoin, |
1220352f S |
22 | ) |
23 | ||
24 | ||
25 | class TVPlayIE(InfoExtractor): | |
6e7e4a6e S |
26 | IE_NAME = 'mtg' |
27 | IE_DESC = 'MTG services' | |
28 | _VALID_URL = r'''(?x) | |
29 | (?: | |
30 | mtg:| | |
31 | https?:// | |
32 | (?:www\.)? | |
33 | (?: | |
dac6f765 S |
34 | tvplay(?:\.skaties)?\.lv(?:/parraides)?| |
35 | (?:tv3play|play\.tv3)\.lt(?:/programos)?| | |
6e7e4a6e | 36 | tv3play(?:\.tv3)?\.ee/sisu| |
e88dabb3 | 37 | (?:tv(?:3|6|8|10)play)\.se/program| |
38 | (?:(?:tv3play|viasat4play|tv6play)\.no|(?:tv3play)\.dk)/programmer| | |
dac6f765 | 39 | play\.nova(?:tv)?\.bg/programi |
6e7e4a6e S |
40 | ) |
41 | /(?:[^/]+/)+ | |
42 | ) | |
43 | (?P<id>\d+) | |
44 | ''' | |
1220352f S |
45 | _TESTS = [ |
46 | { | |
47 | 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true', | |
4a7a5e41 | 48 | 'md5': 'a1612fe0849455423ad8718fe049be21', |
1220352f S |
49 | 'info_dict': { |
50 | 'id': '418113', | |
4a7a5e41 | 51 | 'ext': 'mp4', |
1220352f S |
52 | 'title': 'Kādi ir īri? - Viņas melo labāk', |
53 | 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.', | |
5ca968d0 S |
54 | 'series': 'Viņas melo labāk', |
55 | 'season': '2.sezona', | |
56 | 'season_number': 2, | |
1220352f S |
57 | 'duration': 25, |
58 | 'timestamp': 1406097056, | |
59 | 'upload_date': '20140723', | |
60 | }, | |
1220352f | 61 | }, |
eef93b09 | 62 | { |
22d36283 | 63 | 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true', |
eef93b09 NJ |
64 | 'info_dict': { |
65 | 'id': '409229', | |
66 | 'ext': 'flv', | |
67 | 'title': 'Moterys meluoja geriau', | |
68 | 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e', | |
5ca968d0 S |
69 | 'series': 'Moterys meluoja geriau', |
70 | 'episode_number': 47, | |
71 | 'season': '1 sezonas', | |
72 | 'season_number': 1, | |
eef93b09 NJ |
73 | 'duration': 1330, |
74 | 'timestamp': 1403769181, | |
75 | 'upload_date': '20140626', | |
76 | }, | |
77 | 'params': { | |
78 | # rtmp download | |
79 | 'skip_download': True, | |
80 | }, | |
81 | }, | |
82 | { | |
83 | 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true', | |
84 | 'info_dict': { | |
85 | 'id': '238551', | |
86 | 'ext': 'flv', | |
87 | 'title': 'Kodu keset linna 398537', | |
88 | 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701', | |
89 | 'duration': 1257, | |
90 | 'timestamp': 1292449761, | |
91 | 'upload_date': '20101215', | |
92 | }, | |
93 | 'params': { | |
94 | # rtmp download | |
95 | 'skip_download': True, | |
96 | }, | |
97 | }, | |
98 | { | |
99 | 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true', | |
100 | 'info_dict': { | |
101 | 'id': '395385', | |
4a7a5e41 | 102 | 'ext': 'mp4', |
eef93b09 NJ |
103 | 'title': 'Husräddarna S02E07', |
104 | 'description': 'md5:f210c6c89f42d4fc39faa551be813777', | |
105 | 'duration': 2574, | |
106 | 'timestamp': 1400596321, | |
107 | 'upload_date': '20140520', | |
108 | }, | |
109 | 'params': { | |
eef93b09 NJ |
110 | 'skip_download': True, |
111 | }, | |
112 | }, | |
113 | { | |
114 | 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true', | |
115 | 'info_dict': { | |
116 | 'id': '266636', | |
4a7a5e41 | 117 | 'ext': 'mp4', |
eef93b09 NJ |
118 | 'title': 'Den sista dokusåpan S01E08', |
119 | 'description': 'md5:295be39c872520221b933830f660b110', | |
120 | 'duration': 1492, | |
121 | 'timestamp': 1330522854, | |
122 | 'upload_date': '20120229', | |
b1ac38fa | 123 | 'age_limit': 18, |
eef93b09 NJ |
124 | }, |
125 | 'params': { | |
eef93b09 NJ |
126 | 'skip_download': True, |
127 | }, | |
128 | }, | |
129 | { | |
130 | 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true', | |
131 | 'info_dict': { | |
132 | 'id': '282756', | |
4a7a5e41 | 133 | 'ext': 'mp4', |
eef93b09 NJ |
134 | 'title': 'Antikjakten S01E10', |
135 | 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8', | |
136 | 'duration': 2646, | |
137 | 'timestamp': 1348575868, | |
138 | 'upload_date': '20120925', | |
139 | }, | |
140 | 'params': { | |
eef93b09 NJ |
141 | 'skip_download': True, |
142 | }, | |
143 | }, | |
144 | { | |
145 | 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true', | |
146 | 'info_dict': { | |
147 | 'id': '230898', | |
4a7a5e41 | 148 | 'ext': 'mp4', |
eef93b09 NJ |
149 | 'title': 'Anna Anka søker assistent - Ep. 8', |
150 | 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474', | |
151 | 'duration': 2656, | |
152 | 'timestamp': 1277720005, | |
153 | 'upload_date': '20100628', | |
154 | }, | |
155 | 'params': { | |
eef93b09 NJ |
156 | 'skip_download': True, |
157 | }, | |
158 | }, | |
159 | { | |
160 | 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true', | |
161 | 'info_dict': { | |
162 | 'id': '21873', | |
4a7a5e41 | 163 | 'ext': 'mp4', |
eef93b09 NJ |
164 | 'title': 'Budbringerne program 10', |
165 | 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d', | |
166 | 'duration': 1297, | |
167 | 'timestamp': 1254205102, | |
168 | 'upload_date': '20090929', | |
169 | }, | |
170 | 'params': { | |
eef93b09 NJ |
171 | 'skip_download': True, |
172 | }, | |
173 | }, | |
174 | { | |
175 | 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true', | |
176 | 'info_dict': { | |
177 | 'id': '361883', | |
4a7a5e41 | 178 | 'ext': 'mp4', |
eef93b09 NJ |
179 | 'title': 'Hotelinspektør Alex Polizzi - Ep. 10', |
180 | 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81', | |
181 | 'duration': 2594, | |
182 | 'timestamp': 1393236292, | |
183 | 'upload_date': '20140224', | |
184 | }, | |
185 | 'params': { | |
eef93b09 NJ |
186 | 'skip_download': True, |
187 | }, | |
188 | }, | |
755a9d3d NJ |
189 | { |
190 | 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true', | |
191 | 'info_dict': { | |
192 | 'id': '624952', | |
193 | 'ext': 'flv', | |
194 | 'title': 'Здравей, България (12.06.2015 г.) ', | |
195 | 'description': 'md5:99f3700451ac5bb71a260268b8daefd7', | |
196 | 'duration': 8838, | |
197 | 'timestamp': 1434100372, | |
198 | 'upload_date': '20150612', | |
199 | }, | |
200 | 'params': { | |
201 | # rtmp download | |
202 | 'skip_download': True, | |
203 | }, | |
204 | }, | |
dac6f765 S |
205 | { |
206 | 'url': 'https://play.nova.bg/programi/zdravei-bulgariya/764300?autostart=true', | |
207 | 'only_matching': True, | |
208 | }, | |
4a7a5e41 RA |
209 | { |
210 | 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true', | |
211 | 'only_matching': True, | |
212 | }, | |
dac6f765 S |
213 | { |
214 | 'url': 'https://tvplay.skaties.lv/vinas-melo-labak/418113/?autostart=true', | |
215 | 'only_matching': True, | |
216 | }, | |
502d87c5 S |
217 | { |
218 | # views is null | |
219 | 'url': 'http://tvplay.skaties.lv/parraides/tv3-zinas/760183', | |
220 | 'only_matching': True, | |
221 | }, | |
4a7a5e41 RA |
222 | { |
223 | 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true', | |
224 | 'only_matching': True, | |
6e7e4a6e | 225 | }, |
6e7e4a6e S |
226 | { |
227 | 'url': 'mtg:418113', | |
228 | 'only_matching': True, | |
4a7a5e41 | 229 | } |
1220352f S |
230 | ] |
231 | ||
232 | def _real_extract(self, url): | |
73689daf | 233 | video_id = self._match_id(url) |
be61efdf RA |
234 | geo_country = self._search_regex( |
235 | r'https?://[^/]+\.([a-z]{2})', url, | |
236 | 'geo country', default=None) | |
237 | if geo_country: | |
5f95927a | 238 | self._initialize_geo_bypass({'countries': [geo_country.upper()]}) |
1220352f | 239 | video = self._download_json( |
6e7e4a6e | 240 | 'http://playapi.mtgx.tv/v3/videos/%s' % video_id, video_id, 'Downloading video JSON') |
1220352f | 241 | |
4a7a5e41 RA |
242 | title = video['title'] |
243 | ||
3859ebee S |
244 | try: |
245 | streams = self._download_json( | |
6e7e4a6e | 246 | 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id, |
3859ebee S |
247 | video_id, 'Downloading streams JSON') |
248 | except ExtractorError as e: | |
249 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
250 | msg = self._parse_json(e.cause.read().decode('utf-8'), video_id) | |
251 | raise ExtractorError(msg['msg'], expected=True) | |
252 | raise | |
1220352f S |
253 | |
254 | quality = qualities(['hls', 'medium', 'high']) | |
255 | formats = [] | |
4a7a5e41 | 256 | for format_id, video_url in streams.get('streams', {}).items(): |
3052a30d S |
257 | video_url = url_or_none(video_url) |
258 | if not video_url: | |
1220352f | 259 | continue |
4a7a5e41 RA |
260 | ext = determine_ext(video_url) |
261 | if ext == 'f4m': | |
73689daf | 262 | formats.extend(self._extract_f4m_formats( |
4a7a5e41 RA |
263 | update_url_query(video_url, { |
264 | 'hdcore': '3.5.0', | |
265 | 'plugin': 'aasp-3.5.0.151.81' | |
266 | }), video_id, f4m_id='hds', fatal=False)) | |
267 | elif ext == 'm3u8': | |
268 | formats.extend(self._extract_m3u8_formats( | |
269 | video_url, video_id, 'mp4', 'm3u8_native', | |
270 | m3u8_id='hls', fatal=False)) | |
1220352f | 271 | else: |
4a7a5e41 RA |
272 | fmt = { |
273 | 'format_id': format_id, | |
274 | 'quality': quality(format_id), | |
275 | 'ext': ext, | |
276 | } | |
277 | if video_url.startswith('rtmp'): | |
f0d31c62 S |
278 | m = re.search( |
279 | r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url) | |
4a7a5e41 RA |
280 | if not m: |
281 | continue | |
282 | fmt.update({ | |
283 | 'ext': 'flv', | |
284 | 'url': m.group('url'), | |
285 | 'app': m.group('app'), | |
286 | 'play_path': m.group('playpath'), | |
dac6f765 | 287 | 'preference': -1, |
4a7a5e41 RA |
288 | }) |
289 | else: | |
290 | fmt.update({ | |
291 | 'url': video_url, | |
292 | }) | |
293 | formats.append(fmt) | |
3859ebee S |
294 | |
295 | if not formats and video.get('is_geo_blocked'): | |
296 | self.raise_geo_restricted( | |
b7da73eb | 297 | 'This content might not be available in your country due to copyright reasons', |
298 | metadata_available=True) | |
3859ebee | 299 | |
1220352f S |
300 | self._sort_formats(formats) |
301 | ||
f0d31c62 S |
302 | # TODO: webvtt in m3u8 |
303 | subtitles = {} | |
304 | sami_path = video.get('sami_path') | |
305 | if sami_path: | |
306 | lang = self._search_regex( | |
307 | r'_([a-z]{2})\.xml', sami_path, 'lang', | |
308 | default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1]) | |
309 | subtitles[lang] = [{ | |
310 | 'url': sami_path, | |
311 | }] | |
312 | ||
5ca968d0 S |
313 | series = video.get('format_title') |
314 | episode_number = int_or_none(video.get('format_position', {}).get('episode')) | |
315 | season = video.get('_embedded', {}).get('season', {}).get('title') | |
316 | season_number = int_or_none(video.get('format_position', {}).get('season')) | |
317 | ||
1220352f S |
318 | return { |
319 | 'id': video_id, | |
4a7a5e41 RA |
320 | 'title': title, |
321 | 'description': video.get('description'), | |
5ca968d0 S |
322 | 'series': series, |
323 | 'episode_number': episode_number, | |
324 | 'season': season, | |
325 | 'season_number': season_number, | |
4a7a5e41 RA |
326 | 'duration': int_or_none(video.get('duration')), |
327 | 'timestamp': parse_iso8601(video.get('created_at')), | |
502d87c5 | 328 | 'view_count': try_get(video, lambda x: x['views']['total'], int), |
4a7a5e41 | 329 | 'age_limit': int_or_none(video.get('age_limit', 0)), |
1220352f | 330 | 'formats': formats, |
f0d31c62 | 331 | 'subtitles': subtitles, |
1220352f | 332 | } |
b35b0d73 S |
333 | |
334 | ||
335 | class ViafreeIE(InfoExtractor): | |
336 | _VALID_URL = r'''(?x) | |
337 | https?:// | |
338 | (?:www\.)? | |
e3950399 | 339 | viafree\.(?P<country>dk|no|se|fi) |
340 | /(?P<id>(?:program(?:mer)?|ohjelmat)?/(?:[^/]+/)+[^/?#&]+) | |
b35b0d73 S |
341 | ''' |
342 | _TESTS = [{ | |
700265bf | 343 | 'url': 'http://www.viafree.no/programmer/underholdning/det-beste-vorspielet/sesong-2/episode-1', |
b35b0d73 | 344 | 'info_dict': { |
700265bf | 345 | 'id': '757786', |
b35b0d73 | 346 | 'ext': 'mp4', |
700265bf RA |
347 | 'title': 'Det beste vorspielet - Sesong 2 - Episode 1', |
348 | 'description': 'md5:b632cb848331404ccacd8cd03e83b4c3', | |
349 | 'series': 'Det beste vorspielet', | |
b35b0d73 | 350 | 'season_number': 2, |
700265bf RA |
351 | 'duration': 1116, |
352 | 'timestamp': 1471200600, | |
353 | 'upload_date': '20160814', | |
b35b0d73 S |
354 | }, |
355 | 'params': { | |
356 | 'skip_download': True, | |
357 | }, | |
e88dabb3 | 358 | }, { |
359 | 'url': 'https://www.viafree.dk/programmer/humor/comedy-central-roast-of-charlie-sheen/film/1047660', | |
360 | 'info_dict': { | |
361 | 'id': '1047660', | |
362 | 'ext': 'mp4', | |
363 | 'title': 'Comedy Central Roast of Charlie Sheen - Comedy Central Roast of Charlie Sheen', | |
364 | 'description': 'md5:ec956d941ae9fd7c65a48fd64951dc6d', | |
365 | 'series': 'Comedy Central Roast of Charlie Sheen', | |
366 | 'season_number': 1, | |
367 | 'duration': 3747, | |
368 | 'timestamp': 1608246060, | |
369 | 'upload_date': '20201217' | |
370 | }, | |
371 | 'params': { | |
e88dabb3 | 372 | 'skip_download': True |
373 | } | |
155bc674 S |
374 | }, { |
375 | # with relatedClips | |
376 | 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-1', | |
700265bf | 377 | 'only_matching': True, |
2cb93afc S |
378 | }, { |
379 | # Different og:image URL schema | |
b690ea15 | 380 | 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-2', |
2cb93afc | 381 | 'only_matching': True, |
b35b0d73 | 382 | }, { |
700265bf | 383 | 'url': 'http://www.viafree.se/program/livsstil/husraddarna/sasong-2/avsnitt-2', |
b35b0d73 S |
384 | 'only_matching': True, |
385 | }, { | |
386 | 'url': 'http://www.viafree.dk/programmer/reality/paradise-hotel/saeson-7/episode-5', | |
387 | 'only_matching': True, | |
e88dabb3 | 388 | }, { |
389 | 'url': 'http://www.viafree.se/program/underhallning/i-like-radio-live/sasong-1/676869', | |
390 | 'only_matching': True, | |
e3950399 | 391 | }, { |
392 | 'url': 'https://www.viafree.fi/ohjelmat/entertainment/amazing-makeovers/kausi-7/jakso-2', | |
393 | 'only_matching': True, | |
b35b0d73 | 394 | }] |
700265bf | 395 | _GEO_BYPASS = False |
b35b0d73 | 396 | |
b35b0d73 | 397 | def _real_extract(self, url): |
5ad28e7f | 398 | country, path = self._match_valid_url(url).groups() |
700265bf RA |
399 | content = self._download_json( |
400 | 'https://viafree-content.mtg-api.com/viafree-content/v1/%s/path/%s' % (country, path), path) | |
401 | program = content['_embedded']['viafreeBlocks'][0]['_embedded']['program'] | |
402 | guid = program['guid'] | |
403 | meta = content['meta'] | |
404 | title = meta['title'] | |
155bc674 | 405 | |
700265bf RA |
406 | try: |
407 | stream_href = self._download_json( | |
408 | program['_links']['streamLink']['href'], guid, | |
409 | headers=self.geo_verification_headers())['embedded']['prioritizedStreams'][0]['links']['stream']['href'] | |
410 | except ExtractorError as e: | |
411 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
412 | self.raise_geo_restricted(countries=[country]) | |
413 | raise | |
155bc674 | 414 | |
e88dabb3 | 415 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(stream_href, guid, 'mp4') |
700265bf RA |
416 | self._sort_formats(formats) |
417 | episode = program.get('episode') or {} | |
700265bf RA |
418 | return { |
419 | 'id': guid, | |
420 | 'title': title, | |
421 | 'thumbnail': meta.get('image'), | |
422 | 'description': meta.get('description'), | |
423 | 'series': episode.get('seriesTitle'), | |
e88dabb3 | 424 | 'subtitles': subtitles, |
700265bf RA |
425 | 'episode_number': int_or_none(episode.get('episodeNumber')), |
426 | 'season_number': int_or_none(episode.get('seasonNumber')), | |
427 | 'duration': int_or_none(try_get(program, lambda x: x['video']['duration']['milliseconds']), 1000), | |
428 | 'timestamp': parse_iso8601(try_get(program, lambda x: x['availability']['start'])), | |
429 | 'formats': formats, | |
430 | } | |
dac6f765 S |
431 | |
432 | ||
433 | class TVPlayHomeIE(InfoExtractor): | |
896a88c5 | 434 | _VALID_URL = r'''(?x) |
435 | https?:// | |
436 | (?:tv3?)? | |
437 | play\.(?:tv3|skaties)\.(?P<country>lv|lt|ee)/ | |
438 | (?P<live>lives/)? | |
439 | [^?#&]+(?:episode|programme|clip)-(?P<id>\d+) | |
440 | ''' | |
dac6f765 | 441 | _TESTS = [{ |
896a88c5 | 442 | 'url': 'https://play.tv3.lt/series/gauju-karai-karveliai,serial-2343791/serija-8,episode-2343828', |
dac6f765 | 443 | 'info_dict': { |
896a88c5 | 444 | 'id': '2343828', |
dac6f765 | 445 | 'ext': 'mp4', |
896a88c5 | 446 | 'title': 'Gaujų karai. Karveliai (2021) | S01E08: Serija 8', |
447 | 'description': 'md5:f6fcfbb236429f05531131640dfa7c81', | |
448 | 'duration': 2710, | |
449 | 'season': 'Gaujų karai. Karveliai', | |
dac6f765 | 450 | 'season_number': 1, |
896a88c5 | 451 | 'release_year': 2021, |
452 | 'episode': 'Serija 8', | |
453 | 'episode_number': 8, | |
dac6f765 S |
454 | }, |
455 | 'params': { | |
896a88c5 | 456 | 'skip_download': 'm3u8', |
dac6f765 | 457 | }, |
dac6f765 | 458 | }, { |
896a88c5 | 459 | 'url': 'https://play.tv3.lt/series/moterys-meluoja-geriau-n-7,serial-2574652/serija-25,episode-3284937', |
460 | 'info_dict': { | |
461 | 'id': '3284937', | |
462 | 'ext': 'mp4', | |
463 | 'season': 'Moterys meluoja geriau [N-7]', | |
464 | 'season_number': 14, | |
465 | 'release_year': 2021, | |
466 | 'episode': 'Serija 25', | |
467 | 'episode_number': 25, | |
468 | 'title': 'Moterys meluoja geriau [N-7] (2021) | S14|E25: Serija 25', | |
469 | 'description': 'md5:c6926e9710f1a126f028fbe121eddb79', | |
470 | 'duration': 2440, | |
471 | }, | |
472 | 'skip': '404' | |
dac6f765 | 473 | }, { |
896a88c5 | 474 | 'url': 'https://play.tv3.lt/lives/tv6-lt,live-2838694/optibet-a-lygos-rungtynes-marijampoles-suduva--vilniaus-riteriai,programme-3422014', |
dac6f765 | 475 | 'only_matching': True, |
29f7c58a | 476 | }, { |
896a88c5 | 477 | 'url': 'https://tv3play.skaties.lv/series/women-lie-better-lv,serial-1024464/women-lie-better-lv,episode-1038762', |
29f7c58a | 478 | 'only_matching': True, |
479 | }, { | |
896a88c5 | 480 | 'url': 'https://play.tv3.ee/series/_,serial-2654462/_,episode-2654474', |
29f7c58a | 481 | 'only_matching': True, |
482 | }, { | |
896a88c5 | 483 | 'url': 'https://tv3play.skaties.lv/clips/tv3-zinas-valsti-lidz-15novembrim-bus-majsede,clip-3464509', |
29f7c58a | 484 | 'only_matching': True, |
dac6f765 S |
485 | }] |
486 | ||
487 | def _real_extract(self, url): | |
896a88c5 | 488 | country, is_live, video_id = self._match_valid_url(url).groups() |
dac6f765 | 489 | |
896a88c5 | 490 | api_path = 'lives/programmes' if is_live else 'vods' |
491 | data = self._download_json( | |
492 | urljoin(url, f'/api/products/{api_path}/{video_id}?platform=BROWSER&lang={country.upper()}'), | |
493 | video_id) | |
dac6f765 | 494 | |
896a88c5 | 495 | video_type = 'CATCHUP' if is_live else 'MOVIE' |
496 | stream_id = data['programRecordingId'] if is_live else video_id | |
497 | stream = self._download_json( | |
498 | urljoin(url, f'/api/products/{stream_id}/videos/playlist?videoType={video_type}&platform=BROWSER'), video_id) | |
499 | formats, subtitles = self._extract_m3u8_formats_and_subtitles( | |
500 | stream['sources']['HLS'][0]['src'], video_id, 'mp4', 'm3u8_native', m3u8_id='hls') | |
dac6f765 S |
501 | self._sort_formats(formats) |
502 | ||
896a88c5 | 503 | thumbnails = set(traverse_obj( |
504 | data, (('galary', 'images', 'artworks'), ..., ..., ('miniUrl', 'mainUrl')), expected_type=url_or_none)) | |
dac6f765 S |
505 | |
506 | return { | |
507 | 'id': video_id, | |
896a88c5 | 508 | 'title': self._resolve_title(data), |
509 | 'description': traverse_obj(data, 'description', 'lead'), | |
510 | 'duration': int_or_none(data.get('duration')), | |
511 | 'season': traverse_obj(data, ('season', 'serial', 'title')), | |
512 | 'season_number': int_or_none(traverse_obj(data, ('season', 'number'))), | |
513 | 'episode': data.get('title'), | |
514 | 'episode_number': int_or_none(data.get('episode')), | |
515 | 'release_year': int_or_none(traverse_obj(data, ('season', 'serial', 'year'))), | |
516 | 'thumbnails': [{'url': url, 'ext': 'jpg'} for url in thumbnails], | |
dac6f765 | 517 | 'formats': formats, |
896a88c5 | 518 | 'subtitles': subtitles, |
dac6f765 | 519 | } |
896a88c5 | 520 | |
521 | @staticmethod | |
522 | def _resolve_title(data): | |
523 | return try_get(data, lambda x: ( | |
524 | f'{data["season"]["serial"]["title"]} ({data["season"]["serial"]["year"]}) | ' | |
525 | f'S{data["season"]["number"]:02d}E{data["episode"]:02d}: {data["title"]}' | |
526 | )) or data.get('title') |