]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvplay.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
23 class TVPlayIE(InfoExtractor
):
25 IE_DESC
= 'MTG services'
32 tvplay(?:\.skaties)?\.lv(?:/parraides)?|
33 (?:tv3play|play\.tv3)\.lt(?:/programos)?|
34 tv3play(?:\.tv3)?\.ee/sisu|
35 (?:tv(?:3|6|8|10)play|viafree)\.se/program|
36 (?:(?:tv3play|viasat4play|tv6play|viafree)\.no|(?:tv3play|viafree)\.dk)/programmer|
37 play\.nova(?:tv)?\.bg/programi
45 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
46 'md5': 'a1612fe0849455423ad8718fe049be21',
50 'title': 'Kādi ir īri? - Viņas melo labāk',
51 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
52 'series': 'Viņas melo labāk',
56 'timestamp': 1406097056,
57 'upload_date': '20140723',
61 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
65 'title': 'Moterys meluoja geriau',
66 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
67 'series': 'Moterys meluoja geriau',
69 'season': '1 sezonas',
72 'timestamp': 1403769181,
73 'upload_date': '20140626',
77 'skip_download': True,
81 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
85 'title': 'Kodu keset linna 398537',
86 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
88 'timestamp': 1292449761,
89 'upload_date': '20101215',
93 'skip_download': True,
97 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
101 'title': 'Husräddarna S02E07',
102 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
104 'timestamp': 1400596321,
105 'upload_date': '20140520',
108 'skip_download': True,
112 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
116 'title': 'Den sista dokusåpan S01E08',
117 'description': 'md5:295be39c872520221b933830f660b110',
119 'timestamp': 1330522854,
120 'upload_date': '20120229',
124 'skip_download': True,
128 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
132 'title': 'Antikjakten S01E10',
133 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
135 'timestamp': 1348575868,
136 'upload_date': '20120925',
139 'skip_download': True,
143 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
147 'title': 'Anna Anka søker assistent - Ep. 8',
148 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
150 'timestamp': 1277720005,
151 'upload_date': '20100628',
154 'skip_download': True,
158 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
162 'title': 'Budbringerne program 10',
163 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
165 'timestamp': 1254205102,
166 'upload_date': '20090929',
169 'skip_download': True,
173 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
177 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
178 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
180 'timestamp': 1393236292,
181 'upload_date': '20140224',
184 'skip_download': True,
188 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
192 'title': 'Здравей, България (12.06.2015 г.) ',
193 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
195 'timestamp': 1434100372,
196 'upload_date': '20150612',
200 'skip_download': True,
204 'url': 'https://play.nova.bg/programi/zdravei-bulgariya/764300?autostart=true',
205 'only_matching': True,
208 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
209 'only_matching': True,
212 'url': 'https://tvplay.skaties.lv/vinas-melo-labak/418113/?autostart=true',
213 'only_matching': True,
217 'url': 'http://tvplay.skaties.lv/parraides/tv3-zinas/760183',
218 'only_matching': True,
221 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
222 'only_matching': True,
225 'url': 'http://www.viafree.se/program/underhallning/i-like-radio-live/sasong-1/676869',
226 'only_matching': True,
230 'only_matching': True,
234 def _real_extract(self
, url
):
235 video_id
= self
._match
_id
(url
)
236 geo_country
= self
._search
_regex
(
237 r
'https?://[^/]+\.([a-z]{2})', url
,
238 'geo country', default
=None)
240 self
._initialize
_geo
_bypass
({'countries': [geo_country
.upper()]})
241 video
= self
._download
_json
(
242 'http://playapi.mtgx.tv/v3/videos/%s' % video_id
, video_id
, 'Downloading video JSON')
244 title
= video
['title']
247 streams
= self
._download
_json
(
248 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id
,
249 video_id
, 'Downloading streams JSON')
250 except ExtractorError
as e
:
251 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
252 msg
= self
._parse
_json
(e
.cause
.read().decode('utf-8'), video_id
)
253 raise ExtractorError(msg
['msg'], expected
=True)
256 quality
= qualities(['hls', 'medium', 'high'])
258 for format_id
, video_url
in streams
.get('streams', {}).items():
259 video_url
= url_or_none(video_url
)
262 ext
= determine_ext(video_url
)
264 formats
.extend(self
._extract
_f
4m
_formats
(
265 update_url_query(video_url
, {
267 'plugin': 'aasp-3.5.0.151.81'
268 }), video_id
, f4m_id
='hds', fatal
=False))
270 formats
.extend(self
._extract
_m
3u8_formats
(
271 video_url
, video_id
, 'mp4', 'm3u8_native',
272 m3u8_id
='hls', fatal
=False))
275 'format_id': format_id
,
276 'quality': quality(format_id
),
279 if video_url
.startswith('rtmp'):
281 r
'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url
)
286 'url': m
.group('url'),
287 'app': m
.group('app'),
288 'play_path': m
.group('playpath'),
297 if not formats
and video
.get('is_geo_blocked'):
298 self
.raise_geo_restricted(
299 'This content might not be available in your country due to copyright reasons')
301 self
._sort
_formats
(formats
)
303 # TODO: webvtt in m3u8
305 sami_path
= video
.get('sami_path')
307 lang
= self
._search
_regex
(
308 r
'_([a-z]{2})\.xml', sami_path
, 'lang',
309 default
=compat_urlparse
.urlparse(url
).netloc
.rsplit('.', 1)[-1])
314 series
= video
.get('format_title')
315 episode_number
= int_or_none(video
.get('format_position', {}).get('episode'))
316 season
= video
.get('_embedded', {}).get('season', {}).get('title')
317 season_number
= int_or_none(video
.get('format_position', {}).get('season'))
322 'description': video
.get('description'),
324 'episode_number': episode_number
,
326 'season_number': season_number
,
327 'duration': int_or_none(video
.get('duration')),
328 'timestamp': parse_iso8601(video
.get('created_at')),
329 'view_count': try_get(video
, lambda x
: x
['views']['total'], int),
330 'age_limit': int_or_none(video
.get('age_limit', 0)),
332 'subtitles': subtitles
,
336 class ViafreeIE(InfoExtractor
):
337 _VALID_URL
= r
'''(?x)
340 viafree\.(?P<country>dk|no|se)
341 /(?P<id>program(?:mer)?/(?:[^/]+/)+[^/?#&]+)
344 'url': 'http://www.viafree.no/programmer/underholdning/det-beste-vorspielet/sesong-2/episode-1',
348 'title': 'Det beste vorspielet - Sesong 2 - Episode 1',
349 'description': 'md5:b632cb848331404ccacd8cd03e83b4c3',
350 'series': 'Det beste vorspielet',
353 'timestamp': 1471200600,
354 'upload_date': '20160814',
357 'skip_download': True,
361 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-1',
362 'only_matching': True,
364 # Different og:image URL schema
365 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-2',
366 'only_matching': True,
368 'url': 'http://www.viafree.se/program/livsstil/husraddarna/sasong-2/avsnitt-2',
369 'only_matching': True,
371 'url': 'http://www.viafree.dk/programmer/reality/paradise-hotel/saeson-7/episode-5',
372 'only_matching': True,
377 def suitable(cls
, url
):
378 return False if TVPlayIE
.suitable(url
) else super(ViafreeIE
, cls
).suitable(url
)
380 def _real_extract(self
, url
):
381 country
, path
= re
.match(self
._VALID
_URL
, url
).groups()
382 content
= self
._download
_json
(
383 'https://viafree-content.mtg-api.com/viafree-content/v1/%s/path/%s' % (country
, path
), path
)
384 program
= content
['_embedded']['viafreeBlocks'][0]['_embedded']['program']
385 guid
= program
['guid']
386 meta
= content
['meta']
387 title
= meta
['title']
390 stream_href
= self
._download
_json
(
391 program
['_links']['streamLink']['href'], guid
,
392 headers
=self
.geo_verification_headers())['embedded']['prioritizedStreams'][0]['links']['stream']['href']
393 except ExtractorError
as e
:
394 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
395 self
.raise_geo_restricted(countries
=[country
])
398 formats
= self
._extract
_m
3u8_formats
(stream_href
, guid
, 'mp4')
399 self
._sort
_formats
(formats
)
400 episode
= program
.get('episode') or {}
405 'thumbnail': meta
.get('image'),
406 'description': meta
.get('description'),
407 'series': episode
.get('seriesTitle'),
408 'episode_number': int_or_none(episode
.get('episodeNumber')),
409 'season_number': int_or_none(episode
.get('seasonNumber')),
410 'duration': int_or_none(try_get(program
, lambda x
: x
['video']['duration']['milliseconds']), 1000),
411 'timestamp': parse_iso8601(try_get(program
, lambda x
: x
['availability']['start'])),
416 class TVPlayHomeIE(InfoExtractor
):
417 _VALID_URL
= r
'https?://tvplay\.(?:tv3\.lt|skaties\.lv|tv3\.ee)/[^/]+/[^/?#&]+-(?P<id>\d+)'
419 'url': 'https://tvplay.tv3.lt/aferistai-n-7/aferistai-10047125/',
423 'title': 'Aferistai',
424 'description': 'Aferistai. Kalėdinė pasaka.',
425 'series': 'Aferistai [N-7]',
426 'season': '1 sezonas',
429 'timestamp': 1394209658,
430 'upload_date': '20140307',
434 'skip_download': True,
436 'add_ie': [TVPlayIE
.ie_key()],
438 'url': 'https://tvplay.skaties.lv/vinas-melo-labak/vinas-melo-labak-10280317/',
439 'only_matching': True,
441 'url': 'https://tvplay.tv3.ee/cool-d-ga-mehhikosse/cool-d-ga-mehhikosse-10044354/',
442 'only_matching': True,
445 def _real_extract(self
, url
):
446 video_id
= self
._match
_id
(url
)
448 webpage
= self
._download
_webpage
(url
, video_id
)
450 video_id
= self
._search
_regex
(
451 r
'data-asset-id\s*=\s*["\'](\d
{5,})\b', webpage, 'video
id')
453 if len(video_id) < 8:
454 return self.url_result(
455 'mtg
:%s' % video_id, ie=TVPlayIE.ie_key(), video_id=video_id)
457 m3u8_url = self._search_regex(
458 r'data
-file\s
*=\s
*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
459 'm3u8 url', group='url')
461 formats = self._extract_m3u8_formats(
462 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
464 self._sort_formats(formats)
466 title = self._search_regex(
467 r'data-title\s*=\s*(["\'])(?P
<value
>(?
:(?
!\
1).)+)\
1', webpage,
468 'title
', default=None, group='value
') or self._html_search_meta(
469 'title
', webpage, default=None) or self._og_search_title(
472 description = self._html_search_meta(
473 'description
', webpage,
474 default=None) or self._og_search_description(webpage)
476 thumbnail = self._search_regex(
477 r'data
-image\s
*=\s
*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
478 'thumbnail', default=None, group='url') or self._html_search_meta(
479 'thumbnail', webpage, default=None) or self._og_search_thumbnail(
482 duration = int_or_none(self._search_regex(
483 r'data-duration\s*=\s*["\'](\d
+)', webpage, 'duration
',
486 season = self._search_regex(
487 (r'data
-series
-title\s
*=\s
*(["\'])[^/]+/(?P<value>(?:(?!\1).)+)\1',
488 r'\bseason\s*:\s*(["\'])(?P
<value
>(?
:(?
!\
1).)+)\
1'), webpage,
489 'season
', default=None, group='value
')
490 season_number = int_or_none(self._search_regex(
491 r'(\d
+)(?
:[.\s
]+sezona|\s
+HOOAEG
)', season or '', 'season number
',
493 episode = self._search_regex(
494 (r'\bepisode\s
*:\s
*(["\'])(?P<value>(?:(?!\1).)+)\1',
495 r'data-subtitle\s*=\s*(["\'])(?P
<value
>(?
:(?
!\
1).)+)\
1'), webpage,
496 'episode
', default=None, group='value
')
497 episode_number = int_or_none(self._search_regex(
498 r'(?
:S
[eē
]rija|Osa
)\s
+(\d
+)', episode or '', 'episode number
',
504 'description
': description,
505 'thumbnail
': thumbnail,
506 'duration
': duration,
508 'season_number
': season_number,
510 'episode_number
': episode_number,