2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
17 class TVPlayIE(InfoExtractor):
18 IE_DESC = 'TV3Play and related services'
19 _VALID_URL = r'''(?x)https?://(?:www\.)?
20 (?:tvplay(?:\.skaties)?\.lv/parraides|
21 (?:tv3play|play\.tv3)\.lt/programos|
22 tv3play(?:\.tv3)?\.ee/sisu|
23 tv(?:3|6|8|10)play\.se/program|
24 (?:(?:tv3play|viasat4play|tv6play)\.no|tv3play\.dk)/programmer|
25 play\.novatv\.bg/programi
30 'url': 'http://www.tvplay.lv/parraides/vinas-melo-labak/418113?autostart=true',
31 'md5': 'a1612fe0849455423ad8718fe049be21',
35 'title': 'Kādi ir īri? - Viņas melo labāk',
36 'description': 'Baiba apsmej īrus, kādi tie ir un ko viņi dara.',
38 'timestamp': 1406097056,
39 'upload_date': '20140723',
43 'url': 'http://play.tv3.lt/programos/moterys-meluoja-geriau/409229?autostart=true',
47 'title': 'Moterys meluoja geriau',
48 'description': 'md5:9aec0fc68e2cbc992d2a140bd41fa89e',
50 'timestamp': 1403769181,
51 'upload_date': '20140626',
55 'skip_download': True,
59 'url': 'http://www.tv3play.ee/sisu/kodu-keset-linna/238551?autostart=true',
63 'title': 'Kodu keset linna 398537',
64 'description': 'md5:7df175e3c94db9e47c0d81ffa5d68701',
66 'timestamp': 1292449761,
67 'upload_date': '20101215',
71 'skip_download': True,
75 'url': 'http://www.tv3play.se/program/husraddarna/395385?autostart=true',
79 'title': 'Husräddarna S02E07',
80 'description': 'md5:f210c6c89f42d4fc39faa551be813777',
82 'timestamp': 1400596321,
83 'upload_date': '20140520',
86 'skip_download': True,
90 'url': 'http://www.tv6play.se/program/den-sista-dokusapan/266636?autostart=true',
94 'title': 'Den sista dokusåpan S01E08',
95 'description': 'md5:295be39c872520221b933830f660b110',
97 'timestamp': 1330522854,
98 'upload_date': '20120229',
102 'skip_download': True,
106 'url': 'http://www.tv8play.se/program/antikjakten/282756?autostart=true',
110 'title': 'Antikjakten S01E10',
111 'description': 'md5:1b201169beabd97e20c5ad0ad67b13b8',
113 'timestamp': 1348575868,
114 'upload_date': '20120925',
117 'skip_download': True,
121 'url': 'http://www.tv3play.no/programmer/anna-anka-soker-assistent/230898?autostart=true',
125 'title': 'Anna Anka søker assistent - Ep. 8',
126 'description': 'md5:f80916bf5bbe1c5f760d127f8dd71474',
128 'timestamp': 1277720005,
129 'upload_date': '20100628',
132 'skip_download': True,
136 'url': 'http://www.viasat4play.no/programmer/budbringerne/21873?autostart=true',
140 'title': 'Budbringerne program 10',
141 'description': 'md5:4db78dc4ec8a85bb04fd322a3ee5092d',
143 'timestamp': 1254205102,
144 'upload_date': '20090929',
147 'skip_download': True,
151 'url': 'http://www.tv6play.no/programmer/hotelinspektor-alex-polizzi/361883?autostart=true',
155 'title': 'Hotelinspektør Alex Polizzi - Ep. 10',
156 'description': 'md5:3ecf808db9ec96c862c8ecb3a7fdaf81',
158 'timestamp': 1393236292,
159 'upload_date': '20140224',
162 'skip_download': True,
166 'url': 'http://play.novatv.bg/programi/zdravei-bulgariya/624952?autostart=true',
170 'title': 'Здравей, България (12.06.2015 г.) ',
171 'description': 'md5:99f3700451ac5bb71a260268b8daefd7',
173 'timestamp': 1434100372,
174 'upload_date': '20150612',
178 'skip_download': True,
182 'url': 'http://tvplay.skaties.lv/parraides/vinas-melo-labak/418113?autostart=true',
183 'only_matching': True,
186 'url': 'http://tv3play.tv3.ee/sisu/kodu-keset-linna/238551?autostart=true',
187 'only_matching': True,
191 def _real_extract(self, url):
192 video_id = self._match_id(url)
194 video = self._download_json(
195 'http://playapi.mtgx.tv/v1/videos/%s' % video_id, video_id, 'Downloading video JSON')
197 title = video['title']
199 if video.get('is_geo_blocked'):
201 'This content might not be available in your country due to copyright reasons')
203 streams = self._download_json(
204 'http://playapi.mtgx.tv/v1/videos/stream/%s' % video_id, video_id, 'Downloading streams JSON')
206 quality = qualities(['hls', 'medium', 'high'])
208 for format_id, video_url in streams.get('streams', {}).items():
209 if not video_url or not isinstance(video_url, compat_str):
211 ext = determine_ext(video_url)
213 formats.extend(self._extract_f4m_formats(
214 update_url_query(video_url, {
216 'plugin': 'aasp-3.5.0.151.81'
217 }), video_id, f4m_id='hds', fatal=False))
219 formats.extend(self._extract_m3u8_formats(
220 video_url, video_id, 'mp4', 'm3u8_native',
221 m3u8_id='hls', fatal=False))
224 'format_id': format_id,
225 'quality': quality(format_id),
228 if video_url.startswith('rtmp'):
229 m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', video_url)
234 'url': m.group('url'),
235 'app': m.group('app'),
236 'play_path': m.group('playpath'),
243 self._sort_formats(formats)
248 'description': video.get('description'),
249 'duration': int_or_none(video.get('duration')),
250 'timestamp': parse_iso8601(video.get('created_at')),
251 'view_count': int_or_none(video.get('views', {}).get('total')),
252 'age_limit': int_or_none(video.get('age_limit', 0)),