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)
228 geo_country = self._search_regex(
229 r'https?://[^/]+\.([a-z]{2})', url,
230 'geo country', default=None)
232 self._initialize_geo_bypass([geo_country.upper()])
233 video = self._download_json(
234 'http://playapi.mtgx.tv/v3/videos/%s' % video_id, video_id, 'Downloading video JSON')
236 title = video['title']
239 streams = self._download_json(
240 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id,
241 video_id, 'Downloading streams JSON')
242 except ExtractorError as e:
243 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
244 msg = self._parse_json(e.cause.read().decode('utf-8'), video_id)
245 raise ExtractorError(msg['msg'], expected=True)
248 quality = qualities(['hls', 'medium', 'high'])
250 for format_id, video_url in streams.get('streams', {}).items():
251 if not video_url or not isinstance(video_url, compat_str):
253 ext = determine_ext(video_url)
255 formats.extend(self._extract_f4m_formats(
256 update_url_query(video_url, {
258 'plugin': 'aasp-3.5.0.151.81'
259 }), video_id, f4m_id='hds', fatal=False))
261 formats.extend(self._extract_m3u8_formats(
262 video_url, video_id, 'mp4', 'm3u8_native',
263 m3u8_id='hls', fatal=False))
266 'format_id': format_id,
267 'quality': quality(format_id),
270 if video_url.startswith('rtmp'):
272 r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
277 'url': m.group('url'),
278 'app': m.group('app'),
279 'play_path': m.group('playpath'),
287 if not formats and video.get('is_geo_blocked'):
288 self.raise_geo_restricted(
289 'This content might not be available in your country due to copyright reasons')
291 self._sort_formats(formats)
293 # TODO: webvtt in m3u8
295 sami_path = video.get('sami_path')
297 lang = self._search_regex(
298 r'_([a-z]{2})\.xml', sami_path, 'lang',
299 default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
304 series = video.get('format_title')
305 episode_number = int_or_none(video.get('format_position', {}).get('episode'))
306 season = video.get('_embedded', {}).get('season', {}).get('title')
307 season_number = int_or_none(video.get('format_position', {}).get('season'))
312 'description': video.get('description'),
314 'episode_number': episode_number,
316 'season_number': season_number,
317 'duration': int_or_none(video.get('duration')),
318 'timestamp': parse_iso8601(video.get('created_at')),
319 'view_count': try_get(video, lambda x: x['views']['total'], int),
320 'age_limit': int_or_none(video.get('age_limit', 0)),
322 'subtitles': subtitles,
326 class ViafreeIE(InfoExtractor):
327 _VALID_URL = r'''(?x)
332 (?:dk|no)/programmer|
335 /(?:[^/]+/)+(?P<id>[^/?#&]+)
338 'url': 'http://www.viafree.se/program/livsstil/husraddarna/sasong-2/avsnitt-2',
342 'title': 'Husräddarna S02E02',
343 'description': 'md5:4db5c933e37db629b5a2f75dfb34829e',
344 'series': 'Husräddarna',
345 'season': 'Säsong 2',
348 'timestamp': 1400596321,
349 'upload_date': '20140520',
352 'skip_download': True,
354 'add_ie': [TVPlayIE.ie_key()],
357 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-1',
361 'title': 'Sommaren med YouTube-stjärnorna S01E01',
362 'description': 'md5:2bc69dce2c4bb48391e858539bbb0e3f',
363 'series': 'Sommaren med YouTube-stjärnorna',
364 'season': 'Säsong 1',
367 'timestamp': 1470905572,
368 'upload_date': '20160811',
371 'skip_download': True,
373 'add_ie': [TVPlayIE.ie_key()],
375 # Different og:image URL schema
376 'url': 'http://www.viafree.se/program/reality/sommaren-med-youtube-stjarnorna/sasong-1/avsnitt-2',
377 'only_matching': True,
379 'url': 'http://www.viafree.no/programmer/underholdning/det-beste-vorspielet/sesong-2/episode-1',
380 'only_matching': True,
382 'url': 'http://www.viafree.dk/programmer/reality/paradise-hotel/saeson-7/episode-5',
383 'only_matching': True,
387 def suitable(cls, url):
388 return False if TVPlayIE.suitable(url) else super(ViafreeIE, cls).suitable(url)
390 def _real_extract(self, url):
391 video_id = self._match_id(url)
393 webpage = self._download_webpage(url, video_id)
395 data = self._parse_json(
397 r'(?s)window\.App\s*=\s*({.+?})\s*;\s*</script',
398 webpage, 'data', default='{}'),
399 video_id, transform_source=lambda x: re.sub(
400 r'(?s)function\s+[a-zA-Z_][\da-zA-Z_]*\s*\([^)]*\)\s*{[^}]*}\s*',
401 'null', x), fatal=False)
407 data, lambda x: x['context']['dispatcher']['stores'][
408 'ContentPageProgramStore']['currentVideo']['id'],
411 # Fallback #1 (extract from og:image URL schema)
413 thumbnail = self._og_search_thumbnail(webpage, default=None)
415 video_id = self._search_regex(
417 # http://cdn.playapi.mtgx.tv/imagecache/600x315/cloud/content-images/inbox/765166/a2e95e5f1d735bab9f309fa345cc3f25.jpg
418 # http://cdn.playapi.mtgx.tv/imagecache/600x315/cloud/content-images/seasons/15204/758770/4a5ba509ca8bc043e1ebd1a76131cdf2.jpg
419 r'https?://[^/]+/imagecache/(?:[^/]+/)+(\d{6,})/',
420 thumbnail, 'video id', default=None)
422 # Fallback #2. Extract from raw JSON string.
423 # May extract wrong video id if relatedClips is present.
425 video_id = self._search_regex(
426 r'currentVideo["\']\s*:\s*.+?["\']id["\']\s*:\s*["\'](\d{6,})',
429 return self.url_result('mtg:%s' % video_id, TVPlayIE.ie_key())