2 from __future__ import unicode_literals
6 from .common import InfoExtractor
22 class TVPlayIE(InfoExtractor):
23 IE_DESC = 'TV3Play and related services'
24 _VALID_URL = r'''(?x)https?://(?:www\.)?
25 (?:tvplay(?:\.skaties)?\.lv/parraides|
26 (?:tv3play|play\.tv3)\.lt/programos|
27 tv3play(?:\.tv3)?\.ee/sisu|
28 tv(?:3|6|8|10)play\.se/program|
29 (?:(?:tv3play|viasat4play|tv6play)\.no|tv3play\.dk)/programmer|
30 play\.novatv\.bg/programi
35 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
36 'md5': 'a1612fe0849455423ad8718fe049be21',
40 'title': 'Kādi ir īri? - Viņas melo labāk',
41 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
42 'series': 'Viņas melo labāk',
46 'timestamp': 1406097056,
47 'upload_date': '20140723',
51 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
55 'title': 'Moterys meluoja geriau',
56 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
57 'series': 'Moterys meluoja geriau',
59 'season': '1 sezonas',
62 'timestamp': 1403769181,
63 'upload_date': '20140626',
67 'skip_download': True,
71 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
75 'title': 'Kodu keset linna 398537',
76 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
78 'timestamp': 1292449761,
79 'upload_date': '20101215',
83 'skip_download': True,
87 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
91 'title': 'Husräddarna S02E07',
92 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
94 'timestamp': 1400596321,
95 'upload_date': '20140520',
98 'skip_download': True,
102 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
106 'title': 'Den sista dokusåpan S01E08',
107 'description': 'md5:295be39c872520221b933830f660b110',
109 'timestamp': 1330522854,
110 'upload_date': '20120229',
114 'skip_download': True,
118 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
122 'title': 'Antikjakten S01E10',
123 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
125 'timestamp': 1348575868,
126 'upload_date': '20120925',
129 'skip_download': True,
133 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
137 'title': 'Anna Anka søker assistent - Ep. 8',
138 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
140 'timestamp': 1277720005,
141 'upload_date': '20100628',
144 'skip_download': True,
148 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
152 'title': 'Budbringerne program 10',
153 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
155 'timestamp': 1254205102,
156 'upload_date': '20090929',
159 'skip_download': True,
163 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
167 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
168 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
170 'timestamp': 1393236292,
171 'upload_date': '20140224',
174 'skip_download': True,
178 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
182 'title': 'Здравей, България (12.06.2015 г.) ',
183 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
185 'timestamp': 1434100372,
186 'upload_date': '20150612',
190 'skip_download': True,
194 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
195 'only_matching': True,
198 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
199 'only_matching': True,
203 def _real_extract(self, url):
204 video_id = self._match_id(url)
206 video = self._download_json(
207 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
209 title = video['title']
212 streams = self._download_json(
213 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id,
214 video_id, 'Downloading streams JSON')
215 except ExtractorError as e:
216 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
217 msg = self._parse_json(e.cause.read().decode('utf-8'), video_id)
218 raise ExtractorError(msg['msg'], expected=True)
221 quality = qualities(['hls', 'medium', 'high'])
223 for format_id, video_url in streams.get('streams', {}).items():
224 if not video_url or not isinstance(video_url, compat_str):
226 ext = determine_ext(video_url)
228 formats.extend(self._extract_f4m_formats(
229 update_url_query(video_url, {
231 'plugin': 'aasp-3.5.0.151.81'
232 }), video_id, f4m_id='hds', fatal=False))
234 formats.extend(self._extract_m3u8_formats(
235 video_url, video_id, 'mp4', 'm3u8_native',
236 m3u8_id='hls', fatal=False))
239 'format_id': format_id,
240 'quality': quality(format_id),
243 if video_url.startswith('rtmp'):
245 r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
250 'url': m.group('url'),
251 'app': m.group('app'),
252 'play_path': m.group('playpath'),
260 if not formats and video.get('is_geo_blocked'):
261 self.raise_geo_restricted(
262 'This content might not be available in your country due to copyright reasons')
264 self._sort_formats(formats)
266 # TODO: webvtt in m3u8
268 sami_path = video.get('sami_path')
270 lang = self._search_regex(
271 r'_([a-z]{2})\.xml', sami_path, 'lang',
272 default=compat_urlparse.urlparse(url).netloc.rsplit('.', 1)[-1])
277 series = video.get('format_title')
278 episode_number = int_or_none(video.get('format_position', {}).get('episode'))
279 season = video.get('_embedded', {}).get('season', {}).get('title')
280 season_number = int_or_none(video.get('format_position', {}).get('season'))
285 'description': video.get('description'),
287 'episode_number': episode_number,
289 'season_number': season_number,
290 'duration': int_or_none(video.get('duration')),
291 'timestamp': parse_iso8601(video.get('created_at')),
292 'view_count': int_or_none(video.get('views', {}).get('total')),
293 'age_limit': int_or_none(video.get('age_limit', 0)),
295 'subtitles': subtitles,