2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
25 class TVPlayIE(InfoExtractor
):
27 IE_DESC
= 'MTG services'
34 tvplay(?:\.skaties)?\.lv(?:/parraides)?|
35 (?:tv3play|play\.tv3)\.lt(?:/programos)?|
36 tv3play(?:\.tv3)?\.ee/sisu|
37 (?:tv(?:3|6|8|10)play)\.se/program|
38 (?:(?:tv3play|viasat4play|tv6play)\.no|(?:tv3play)\.dk)/programmer|
39 play\.nova(?:tv)?\.bg/programi
47 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
48 'md5': 'a1612fe0849455423ad8718fe049be21',
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.',
54 'series': 'Viņas melo labāk',
58 'timestamp': 1406097056,
59 'upload_date': '20140723',
63 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
67 'title': 'Moterys meluoja geriau',
68 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
69 'series': 'Moterys meluoja geriau',
71 'season': '1 sezonas',
74 'timestamp': 1403769181,
75 'upload_date': '20140626',
79 'skip_download': True,
83 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
87 'title': 'Kodu keset linna 398537',
88 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
90 'timestamp': 1292449761,
91 'upload_date': '20101215',
95 'skip_download': True,
99 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
103 'title': 'Husräddarna S02E07',
104 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
106 'timestamp': 1400596321,
107 'upload_date': '20140520',
110 'skip_download': True,
114 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
118 'title': 'Den sista dokusåpan S01E08',
119 'description': 'md5:295be39c872520221b933830f660b110',
121 'timestamp': 1330522854,
122 'upload_date': '20120229',
126 'skip_download': True,
130 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
134 'title': 'Antikjakten S01E10',
135 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
137 'timestamp': 1348575868,
138 'upload_date': '20120925',
141 'skip_download': True,
145 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
149 'title': 'Anna Anka søker assistent - Ep. 8',
150 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
152 'timestamp': 1277720005,
153 'upload_date': '20100628',
156 'skip_download': True,
160 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
164 'title': 'Budbringerne program 10',
165 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
167 'timestamp': 1254205102,
168 'upload_date': '20090929',
171 'skip_download': True,
175 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
179 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
180 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
182 'timestamp': 1393236292,
183 'upload_date': '20140224',
186 'skip_download': True,
190 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
194 'title': 'Здравей, България (12.06.2015 г.) ',
195 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
197 'timestamp': 1434100372,
198 'upload_date': '20150612',
202 'skip_download': True,
206 'url': 'https://play.nova.bg/programi/zdravei-bulgariya/764300?autostart=true',
207 'only_matching': True,
210 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
211 'only_matching': True,
214 'url': 'https://tvplay.skaties.lv/vinas-melo-labak/418113/?autostart=true',
215 'only_matching': True,
219 'url': 'http://tvplay.skaties.lv/parraides/tv3-zinas/760183',
220 'only_matching': True,
223 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
224 'only_matching': True,
228 'only_matching': True,
232 def _real_extract(self
, url
):
233 video_id
= self
._match
_id
(url
)
234 geo_country
= self
._search
_regex
(
235 r
'https?://[^/]+\.([a-z]{2})', url
,
236 'geo country', default
=None)
238 self
._initialize
_geo
_bypass
({'countries': [geo_country.upper()]}
)
239 video
= self
._download
_json
(
240 'http://playapi.mtgx.tv/v3/videos/%s' % video_id
, video_id
, 'Downloading video JSON')
242 title
= video
['title']
245 streams
= self
._download
_json
(
246 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id
,
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)
254 quality
= qualities(['hls', 'medium', 'high'])
256 for format_id
, video_url
in streams
.get('streams', {}).items():
257 video_url
= url_or_none(video_url
)
260 ext
= determine_ext(video_url
)
262 formats
.extend(self
._extract
_f
4m
_formats
(
263 update_url_query(video_url
, {
265 'plugin': 'aasp-3.5.0.151.81'
266 }), video_id
, f4m_id
='hds', fatal
=False))
268 formats
.extend(self
._extract
_m
3u8_formats
(
269 video_url
, video_id
, 'mp4', 'm3u8_native',
270 m3u8_id
='hls', fatal
=False))
273 'format_id': format_id
,
274 'quality': quality(format_id
),
277 if video_url
.startswith('rtmp'):
279 r
'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url
)
284 'url': m
.group('url'),
285 'app': m
.group('app'),
286 'play_path': m
.group('playpath'),
295 if not formats
and video
.get('is_geo_blocked'):
296 self
.raise_geo_restricted(
297 'This content might not be available in your country due to copyright reasons',
298 metadata_available
=True)
300 self
._sort
_formats
(formats
)
302 # TODO: webvtt in m3u8
304 sami_path
= video
.get('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])
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'))
321 'description': video
.get('description'),
323 'episode_number': episode_number
,
325 'season_number': season_number
,
326 'duration': int_or_none(video
.get('duration')),
327 'timestamp': parse_iso8601(video
.get('created_at')),
328 'view_count': try_get(video
, lambda x
: x
['views']['total'], int),
329 'age_limit': int_or_none(video
.get('age_limit', 0)),
331 'subtitles': subtitles
,
335 class ViafreeIE(InfoExtractor
):
336 _VALID_URL
= r
'''(?x)
339 viafree\.(?P<country>dk|no|se|fi)
340 /(?P<id>(?:program(?:mer)?|ohjelmat)?/(?:[^/]+/)+[^/?#&]+)
343 'url': 'http://www.viafree.no/programmer/underholdning/det-beste-vorspielet/sesong-2/episode-1',
347 'title': 'Det beste vorspielet - Sesong 2 - Episode 1',
348 'description': 'md5:b632cb848331404ccacd8cd03e83b4c3',
349 'series': 'Det beste vorspielet',
352 'timestamp': 1471200600,
353 'upload_date': '20160814',
356 'skip_download': True,
359 'url': 'https://www.viafree.dk/programmer/humor/comedy-central-roast-of-charlie-sheen/film/1047660',
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',
368 'timestamp': 1608246060,
369 'upload_date': '20201217'
372 'skip_download': True
376 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-1',
377 'only_matching': True,
379 # Different og:image URL schema
380 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-2',
381 'only_matching': True,
383 'url': 'http://www.viafree.se/program/livsstil/husraddarna/sasong-2/avsnitt-2',
384 'only_matching': True,
386 'url': 'http://www.viafree.dk/programmer/reality/paradise-hotel/saeson-7/episode-5',
387 'only_matching': True,
389 'url': 'http://www.viafree.se/program/underhallning/i-like-radio-live/sasong-1/676869',
390 'only_matching': True,
392 'url': 'https://www.viafree.fi/ohjelmat/entertainment/amazing-makeovers/kausi-7/jakso-2',
393 'only_matching': True,
397 def _real_extract(self
, url
):
398 country
, path
= self
._match
_valid
_url
(url
).groups()
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']
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
])
415 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(stream_href
, guid
, 'mp4')
416 self
._sort
_formats
(formats
)
417 episode
= program
.get('episode') or {}
421 'thumbnail': meta
.get('image'),
422 'description': meta
.get('description'),
423 'series': episode
.get('seriesTitle'),
424 'subtitles': subtitles
,
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'])),
433 class TVPlayHomeIE(InfoExtractor
):
434 _VALID_URL
= r
'https?://(?:tv3?)?play\.(?:tv3\.lt|skaties\.lv|tv3\.ee)/(?:[^/]+/)*[^/?#&]+-(?P<id>\d+)'
436 'url': 'https://tvplay.tv3.lt/aferistai-n-7/aferistai-10047125/',
440 'title': 'Aferistai',
441 'description': 'Aferistai. Kalėdinė pasaka.',
442 'series': 'Aferistai [N-7]',
443 'season': '1 sezonas',
446 'timestamp': 1394209658,
447 'upload_date': '20140307',
451 'skip_download': True,
454 'url': 'https://tvplay.skaties.lv/vinas-melo-labak/vinas-melo-labak-10280317/',
455 'only_matching': True,
457 'url': 'https://tvplay.tv3.ee/cool-d-ga-mehhikosse/cool-d-ga-mehhikosse-10044354/',
458 'only_matching': True,
460 'url': 'https://play.tv3.lt/aferistai-10047125',
461 'only_matching': True,
463 'url': 'https://tv3play.skaties.lv/vinas-melo-labak-10280317',
464 'only_matching': True,
466 'url': 'https://play.tv3.ee/cool-d-ga-mehhikosse-10044354',
467 'only_matching': True,
470 def _real_extract(self
, url
):
471 video_id
= self
._match
_id
(url
)
473 asset
= self
._download
_json
(
474 urljoin(url
, '/sb/public/asset/' + video_id
), video_id
)
476 m3u8_url
= asset
['movie']['contentUrl']
477 video_id
= asset
['assetId']
478 asset_title
= asset
['title']
479 title
= asset_title
['title']
481 formats
= self
._extract
_m
3u8_formats
(
482 m3u8_url
, video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls')
483 self
._sort
_formats
(formats
)
486 image_url
= asset
.get('imageUrl')
489 'url': urljoin(url
, image_url
),
493 metadata
= asset
.get('metadata') or {}
498 'description': asset_title
.get('summaryLong') or asset_title
.get('summaryShort'),
499 'thumbnails': thumbnails
,
500 'duration': parse_duration(asset_title
.get('runTime')),
501 'series': asset
.get('tvSeriesTitle'),
502 'season': asset
.get('tvSeasonTitle'),
503 'season_number': int_or_none(metadata
.get('seasonNumber')),
504 'episode': asset_title
.get('titleBrief'),
505 'episode_number': int_or_none(metadata
.get('episodeNumber')),