# 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' _login_info = {} 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', self._generate_cookie(uuid, session_id)) response = self._request_webpage( request, None, 'Logging in') cookie = response.headers.get('Set-Cookie') pzuid = self._search_regex(r'pzuid\s*=\s*(.+?);', cookie, 'pzuid') data = self._parse_json(response.read(), None) return { 'ppid': data['session']['ppid'], 'powerhash': data['session']['power_guide_hash'], 'pzuid': pzuid, 'uuid': uuid, 'session_id': session_id } 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]+)' # Since videos are only available for 7 days, we cannot have detailed tests. _TEST = { 'url': 'https://zattoo.com/watch/prosieben/130671867-maze-runner-die-auserwaehlten-in-der-brandwueste', 'only_matching': True, } 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 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)