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\.novatv\.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': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
205 'only_matching': True,
209 'url': 'http://tvplay.skaties.lv/parraides/tv3-zinas/760183',
210 'only_matching': True,
213 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
214 'only_matching': True,
217 'url': 'http://www.viafree.se/program/underhallning/i-like-radio-live/sasong-1/676869',
218 'only_matching': True,
222 'only_matching': True,
226 def _real_extract(self, url):
227 video_id = self._match_id(url)
229 video = self._download_json(
230 'http://playapi.mtgx.tv/v3/videos/%s' % video_id, video_id, 'Downloading video JSON')
232 title = video['title']
235 streams = self._download_json(
236 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id,
237 video_id, 'Downloading streams JSON')
238 except ExtractorError as e:
239 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
240 msg = self._parse_json(e.cause.read().decode('utf-8'), video_id)
241 raise ExtractorError(msg['msg'], expected=True)
244 quality = qualities(['hls', 'medium', 'high'])
246 for format_id, video_url in streams.get('streams', {}).items():
247 if not video_url or not isinstance(video_url, compat_str):
249 ext = determine_ext(video_url)
251 formats.extend(self._extract_f4m_formats(
252 update_url_query(video_url, {
254 'plugin': 'aasp-3.5.0.151.81'
255 }), video_id, f4m_id='hds', fatal=False))
257 formats.extend(self._extract_m3u8_formats(
258 video_url, video_id, 'mp4', 'm3u8_native',
259 m3u8_id='hls', fatal=False))
262 'format_id': format_id,
263 'quality': quality(format_id),
266 if video_url.startswith('rtmp'):
268 r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
273 'url': m.group('url'),
274 'app': m.group('app'),
275 'play_path': m.group('playpath'),
283 if not formats and video.get('is_geo_blocked'):
284 self.raise_geo_restricted(
285 'This content might not be available in your country due to copyright reasons')
287 self._sort_formats(formats)
289 # TODO: webvtt in m3u8
291 sami_path = video.get('sami_path')
293 lang = self._search_regex(
294 r'_([a-z]{2})\.xml', sami_path, 'lang',
295 default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
300 series = video.get('format_title')
301 episode_number = int_or_none(video.get('format_position', {}).get('episode'))
302 season = video.get('_embedded', {}).get('season', {}).get('title')
303 season_number = int_or_none(video.get('format_position', {}).get('season'))
308 'description': video.get('description'),
310 'episode_number': episode_number,
312 'season_number': season_number,
313 'duration': int_or_none(video.get('duration')),
314 'timestamp': parse_iso8601(video.get('created_at')),
315 'view_count': try_get(video, lambda x: x['views']['total'], int),
316 'age_limit': int_or_none(video.get('age_limit', 0)),
318 'subtitles': subtitles,
322 class ViafreeIE(InfoExtractor):
323 _VALID_URL = r'''(?x)
328 (?:dk|no)/programmer|
331 /(?:[^/]+/)+(?P<id>[^/?#&]+)
334 'url': 'http://www.viafree.se/program/livsstil/husraddarna/sasong-2/avsnitt-2',
338 'title': 'Husräddarna S02E02',
339 'description': 'md5:4db5c933e37db629b5a2f75dfb34829e',
340 'series': 'Husräddarna',
341 'season': 'Säsong 2',
344 'timestamp': 1400596321,
345 'upload_date': '20140520',
348 'skip_download': True,
350 'add_ie': [TVPlayIE.ie_key()],
353 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-1',
357 'title': 'Sommaren med YouTube-stjärnorna S01E01',
358 'description': 'md5:2bc69dce2c4bb48391e858539bbb0e3f',
359 'series': 'Sommaren med YouTube-stjärnorna',
360 'season': 'Säsong 1',
363 'timestamp': 1470905572,
364 'upload_date': '20160811',
367 'skip_download': True,
369 'add_ie': [TVPlayIE.ie_key()],
371 # Different og:image URL schema
372 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-2',
373 'only_matching': True,
375 'url': 'http://www.viafree.no/programmer/underholdning/det-beste-vorspielet/sesong-2/episode-1',
376 'only_matching': True,
378 'url': 'http://www.viafree.dk/programmer/reality/paradise-hotel/saeson-7/episode-5',
379 'only_matching': True,
383 def suitable(cls, url):
384 return False if TVPlayIE.suitable(url) else super(ViafreeIE, cls).suitable(url)
386 def _real_extract(self, url):
387 video_id = self._match_id(url)
389 webpage = self._download_webpage(url, video_id)
391 data = self._parse_json(
393 r'(?s)window\.App\s*=\s*({.+?})\s*;\s*</script',
394 webpage, 'data', default='{}'),
395 video_id, transform_source=lambda x: re.sub(
396 r'(?s)function\s+[a-zA-Z_][\da-zA-Z_]*\s*\([^)]*\)\s*{[^}]*}\s*',
397 'null', x), fatal=False)
403 data, lambda x: x['context']['dispatcher']['stores'][
404 'ContentPageProgramStore']['currentVideo']['id'],
407 # Fallback #1 (extract from og:image URL schema)
409 thumbnail = self._og_search_thumbnail(webpage, default=None)
411 video_id = self._search_regex(
413 # http://cdn.playapi.mtgx.tv/imagecache/600x315/cloud/content-images/inbox/765166/a2e95e5f1d735bab9f309fa345cc3f25.jpg
414 # http://cdn.playapi.mtgx.tv/imagecache/600x315/cloud/content-images/seasons/15204/758770/4a5ba509ca8bc043e1ebd1a76131cdf2.jpg
415 r'https?://[^/]+/imagecache/(?:[^/]+/)+(\d{6,})/',
416 thumbnail, 'video id', default=None)
418 # Fallback #2. Extract from raw JSON string.
419 # May extract wrong video id if relatedClips is present.
421 video_id = self._search_regex(
422 r'currentVideo["\']\s*:\s*.+?["\']id["\']\s*:\s*["\'](\d{6,})',
425 return self.url_result('mtg:%s' % video_id, TVPlayIE.ie_key())