# coding: utf-8 from __future__ import unicode_literals from uuid import uuid4 import re from .common import InfoExtractor from ..utils import ( compat_str, ExtractorError, sanitized_Request, urlencode_postdata, ) class ZattooBaseIE(InfoExtractor): _NETRC_MACHINE = 'zattoo' _HOST_URL = 'https://zattoo.com' _power_guide_hash = None def _login(self, uuid, session_id): (username, password) = self._get_login_info() if not username or not password: raise ExtractorError( 'A valid %s account is needed to access this media.' % self._NETRC_MACHINE, expected=True) login_form = { 'login': username, 'password': password, 'remember': True, } request = sanitized_Request( '%s/zapi/v2/account/login' % self._HOST_URL, urlencode_postdata(login_form)) request.add_header( 'Referer', '%s/login' % self._HOST_URL) request.add_header( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8') request.add_header( 'Cookie', 'uuid=%s; beaker.session.id=%s' % (uuid, session_id)) response = self._request_webpage( request, None, 'Logging in') data = self._parse_json(response.read(), None) return data['session']['power_guide_hash'] def _get_app_token_and_version(self): host_webpage = self._download_webpage( self._HOST_URL, None, 'Downloading %s' % self._HOST_URL) app_token = self._html_search_regex( r'[^/]+)/(?P[0-9]+)' def _real_extract(self, url): channel_name, video_id = re.match(self._VALID_URL, url).groups() return self._extract_video(channel_name, video_id) class QuicklineLiveIE(QuicklineBaseIE): _VALID_URL = r'https?://(?:www\.)?mobiltv\.quickline\.com/watch/(?P[^/]+)$' def _real_extract(self, url): channel_name = video_id = self._match_id(url) return self._extract_video(channel_name, video_id, is_live=True) class ZattooIE(ZattooBaseIE): _VALID_URL = r'https?://(?:www\.)?zattoo\.com/watch/(?P[^/]+?)/(?P[0-9]+)[^/]+(?:/(?P[0-9]+))?' # Since regular videos are only available for 7 days and recorded videos # are only available for a specific user, we cannot have detailed tests. _TESTS = [{ 'url': 'https://zattoo.com/watch/prosieben/130671867-maze-runner-die-auserwaehlten-in-der-brandwueste', 'only_matching': True, }, { 'url': 'https://zattoo.com/watch/srf_zwei/132905652-eishockey-spengler-cup/102791477/1512211800000/1514433500000/92000', 'only_matching': True, }] def _real_extract(self, url): channel_name, video_id, record_id = re.match(self._VALID_URL, url).groups() return self._extract_video(channel_name, video_id, record_id) class ZattooLiveIE(ZattooBaseIE): _VALID_URL = r'https?://(?:www\.)?zattoo\.com/watch/(?P[^/]+)$' _TEST = { 'url': 'https://zattoo.com/watch/srf1', 'only_matching': True, } def _real_extract(self, url): channel_name = video_id = self._match_id(url) return self._extract_video(channel_name, video_id, is_live=True)