2 from __future__ import unicode_literals
6 from .common import InfoExtractor
22 class TVPlayIE(InfoExtractor):
24 IE_DESC = 'MTG services'
31 tvplay(?:\.skaties)?\.lv/parraides|
32 (?:tv3play|play\.tv3)\.lt/programos|
33 tv3play(?:\.tv3)?\.ee/sisu|
34 (?:tv(?:3|6|8|10)play|viafree)\.se/program|
35 (?:(?:tv3play|viasat4play|tv6play|viafree)\.no|(?:tv3play|viafree)\.dk)/programmer|
36 play\.novatv\.bg/programi
44 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
45 'md5': 'a1612fe0849455423ad8718fe049be21',
49 'title': 'Kādi ir īri? - Viņas melo labāk',
50 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
51 'series': 'Viņas melo labāk',
55 'timestamp': 1406097056,
56 'upload_date': '20140723',
60 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
64 'title': 'Moterys meluoja geriau',
65 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
66 'series': 'Moterys meluoja geriau',
68 'season': '1 sezonas',
71 'timestamp': 1403769181,
72 'upload_date': '20140626',
76 'skip_download': True,
80 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
84 'title': 'Kodu keset linna 398537',
85 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
87 'timestamp': 1292449761,
88 'upload_date': '20101215',
92 'skip_download': True,
96 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
100 'title': 'Husräddarna S02E07',
101 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
103 'timestamp': 1400596321,
104 'upload_date': '20140520',
107 'skip_download': True,
111 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
115 'title': 'Den sista dokusåpan S01E08',
116 'description': 'md5:295be39c872520221b933830f660b110',
118 'timestamp': 1330522854,
119 'upload_date': '20120229',
123 'skip_download': True,
127 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
131 'title': 'Antikjakten S01E10',
132 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
134 'timestamp': 1348575868,
135 'upload_date': '20120925',
138 'skip_download': True,
142 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
146 'title': 'Anna Anka søker assistent - Ep. 8',
147 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
149 'timestamp': 1277720005,
150 'upload_date': '20100628',
153 'skip_download': True,
157 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
161 'title': 'Budbringerne program 10',
162 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
164 'timestamp': 1254205102,
165 'upload_date': '20090929',
168 'skip_download': True,
172 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
176 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
177 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
179 'timestamp': 1393236292,
180 'upload_date': '20140224',
183 'skip_download': True,
187 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
191 'title': 'Здравей, България (12.06.2015 г.) ',
192 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
194 'timestamp': 1434100372,
195 'upload_date': '20150612',
199 'skip_download': True,
203 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
204 'only_matching': True,
207 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
208 'only_matching': True,
211 'url': 'http://www.viafree.se/program/underhallning/i-like-radio-live/sasong-1/676869',
212 'only_matching': True,
216 'only_matching': True,
220 def _real_extract(self, url):
221 video_id = self._match_id(url)
223 video = self._download_json(
224 'http://playapi.mtgx.tv/v3/videos/%s' % video_id, video_id, 'Downloading video JSON')
226 title = video['title']
229 streams = self._download_json(
230 'http://playapi.mtgx.tv/v3/videos/stream/%s' % video_id,
231 video_id, 'Downloading streams JSON')
232 except ExtractorError as e:
233 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
234 msg = self._parse_json(e.cause.read().decode('utf-8'), video_id)
235 raise ExtractorError(msg['msg'], expected=True)
238 quality = qualities(['hls', 'medium', 'high'])
240 for format_id, video_url in streams.get('streams', {}).items():
241 if not video_url or not isinstance(video_url, compat_str):
243 ext = determine_ext(video_url)
245 formats.extend(self._extract_f4m_formats(
246 update_url_query(video_url, {
248 'plugin': 'aasp-3.5.0.151.81'
249 }), video_id, f4m_id='hds', fatal=False))
251 formats.extend(self._extract_m3u8_formats(
252 video_url, video_id, 'mp4', 'm3u8_native',
253 m3u8_id='hls', fatal=False))
256 'format_id': format_id,
257 'quality': quality(format_id),
260 if video_url.startswith('rtmp'):
262 r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
267 'url': m.group('url'),
268 'app': m.group('app'),
269 'play_path': m.group('playpath'),
277 if not formats and video.get('is_geo_blocked'):
278 self.raise_geo_restricted(
279 'This content might not be available in your country due to copyright reasons')
281 self._sort_formats(formats)
283 # TODO: webvtt in m3u8
285 sami_path = video.get('sami_path')
287 lang = self._search_regex(
288 r'_([a-z]{2})\.xml', sami_path, 'lang',
289 default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
294 series = video.get('format_title')
295 episode_number = int_or_none(video.get('format_position', {}).get('episode'))
296 season = video.get('_embedded', {}).get('season', {}).get('title')
297 season_number = int_or_none(video.get('format_position', {}).get('season'))
302 'description': video.get('description'),
304 'episode_number': episode_number,
306 'season_number': season_number,
307 'duration': int_or_none(video.get('duration')),
308 'timestamp': parse_iso8601(video.get('created_at')),
309 'view_count': int_or_none(video.get('views', {}).get('total')),
310 'age_limit': int_or_none(video.get('age_limit', 0)),
312 'subtitles': subtitles,