2 from __future__ import unicode_literals
7 from .common import InfoExtractor
21 class ZattooBaseIE(InfoExtractor):
22 _NETRC_MACHINE = 'zattoo'
23 _HOST_URL = 'https://zattoo.com'
25 _power_guide_hash = None
28 username, password = self._get_login_info()
29 if not username or not password:
30 self.raise_login_required(
31 'A valid %s account is needed to access this media.'
32 % self._NETRC_MACHINE)
35 data = self._download_json(
36 '%s/zapi/v2/account/login' % self._HOST_URL, None, 'Logging in',
37 data=urlencode_postdata({
42 'Referer': '%s/login' % self._HOST_URL,
43 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
45 except ExtractorError as e:
46 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
48 'Unable to login: incorrect username and/or password',
52 self._power_guide_hash = data['session']['power_guide_hash']
54 def _real_initialize(self):
55 webpage = self._download_webpage(
56 self._HOST_URL, None, 'Downloading app token')
57 app_token = self._html_search_regex(
58 r'appToken\s*=\s*(["\'])(?P<token>(?:(?!\1).)+?)\1',
59 webpage, 'app token', group='token')
60 app_version = self._html_search_regex(
61 r'<!--\w+-(.+?)-', webpage, 'app version', default='2.8.2')
63 # Will setup appropriate cookies
64 self._request_webpage(
65 '%s/zapi/v2/session/hello' % self._HOST_URL, None,
66 'Opening session', data=urlencode_postdata({
67 'client_app_token': app_token,
68 'uuid': compat_str(uuid4()),
70 'app_version': app_version,
76 def _extract_cid(self, video_id, channel_name):
77 channel_groups = self._download_json(
78 '%s/zapi/v2/cached/channels/%s' % (self._HOST_URL,
79 self._power_guide_hash),
80 video_id, 'Downloading channel list',
81 query={'details': False})['channel_groups']
83 for chgrp in channel_groups:
84 channel_list.extend(chgrp['channels'])
87 chan['cid'] for chan in channel_list
88 if chan.get('cid') and (
89 chan.get('display_alias') == channel_name or
90 chan.get('cid') == channel_name))
92 raise ExtractorError('Could not extract channel id')
94 def _extract_cid_and_video_info(self, video_id):
95 data = self._download_json(
96 '%s/zapi/v2/cached/program/power_details/%s' % (
97 self._HOST_URL, self._power_guide_hash),
99 'Downloading video information',
101 'program_ids': video_id,
105 p = data['programs'][0]
110 'title': p.get('t') or p['et'],
111 'description': p.get('d'),
112 'thumbnail': p.get('i_url'),
113 'creator': p.get('channel_name'),
114 'episode': p.get('et'),
115 'episode_number': int_or_none(p.get('e_no')),
116 'season_number': int_or_none(p.get('s_no')),
117 'release_year': int_or_none(p.get('year')),
118 'categories': try_get(p, lambda x: x['c'], list),
119 'tags': try_get(p, lambda x: x['g'], list)
122 return cid, info_dict
124 def _extract_formats(self, cid, video_id, record_id=None, is_live=False):
126 'https_watch_urls': True,
130 postdata_common.update({'timeshift': 10800})
131 url = '%s/zapi/watch/live/%s' % (self._HOST_URL, cid)
133 url = '%s/zapi/watch/recording/%s' % (self._HOST_URL, record_id)
135 url = '%s/zapi/watch/recall/%s/%s' % (self._HOST_URL, cid, video_id)
138 for stream_type in ('dash', 'hls', 'hls5', 'hds'):
139 postdata = postdata_common.copy()
140 postdata['stream_type'] = stream_type
142 data = self._download_json(
143 url, video_id, 'Downloading %s formats' % stream_type.upper(),
144 data=urlencode_postdata(postdata), fatal=False)
148 watch_urls = try_get(
149 data, lambda x: x['stream']['watch_urls'], list)
153 for watch in watch_urls:
154 if not isinstance(watch, dict):
156 watch_url = url_or_none(watch.get('url'))
159 format_id_list = [stream_type]
160 maxrate = watch.get('maxrate')
162 format_id_list.append(compat_str(maxrate))
163 audio_channel = watch.get('audio_channel')
165 format_id_list.append(compat_str(audio_channel))
166 preference = 1 if audio_channel == 'A' else None
167 format_id = '-'.join(format_id_list)
168 if stream_type in ('dash', 'dash_widevine', 'dash_playready'):
169 this_formats = self._extract_mpd_formats(
170 watch_url, video_id, mpd_id=format_id, fatal=False)
171 elif stream_type in ('hls', 'hls5', 'hls5_fairplay'):
172 this_formats = self._extract_m3u8_formats(
173 watch_url, video_id, 'mp4',
174 entry_protocol='m3u8_native', m3u8_id=format_id,
176 elif stream_type == 'hds':
177 this_formats = self._extract_f4m_formats(
178 watch_url, video_id, f4m_id=format_id, fatal=False)
179 elif stream_type == 'smooth_playready':
180 this_formats = self._extract_ism_formats(
181 watch_url, video_id, ism_id=format_id, fatal=False)
184 for this_format in this_formats:
185 this_format['preference'] = preference
186 formats.extend(this_formats)
187 self._sort_formats(formats)
190 def _extract_video(self, channel_name, video_id, record_id=None, is_live=False):
192 cid = self._extract_cid(video_id, channel_name)
195 'title': self._live_title(channel_name),
199 cid, info_dict = self._extract_cid_and_video_info(video_id)
200 formats = self._extract_formats(
201 cid, video_id, record_id=record_id, is_live=is_live)
202 info_dict['formats'] = formats
206 class QuicklineBaseIE(ZattooBaseIE):
207 _NETRC_MACHINE = 'quickline'
208 _HOST_URL = 'https://mobiltv.quickline.com'
211 class QuicklineIE(QuicklineBaseIE):
212 _VALID_URL = r'https?://(?:www\.)?mobiltv\.quickline\.com/watch/(?P<channel>[^/]+)/(?P<id>[0-9]+)'
215 'url': 'https://mobiltv.quickline.com/watch/prosieben/130671867-maze-runner-die-auserwaehlten-in-der-brandwueste',
216 'only_matching': True,
219 def _real_extract(self, url):
220 channel_name, video_id = re.match(self._VALID_URL, url).groups()
221 return self._extract_video(channel_name, video_id)
224 class QuicklineLiveIE(QuicklineBaseIE):
225 _VALID_URL = r'https?://(?:www\.)?mobiltv\.quickline\.com/watch/(?P<id>[^/]+)'
228 'url': 'https://mobiltv.quickline.com/watch/srf1',
229 'only_matching': True,
233 def suitable(cls, url):
234 return False if QuicklineIE.suitable(url) else super(QuicklineLiveIE, cls).suitable(url)
236 def _real_extract(self, url):
237 channel_name = video_id = self._match_id(url)
238 return self._extract_video(channel_name, video_id, is_live=True)
241 class ZattooIE(ZattooBaseIE):
242 _VALID_URL = r'https?://(?:www\.)?zattoo\.com/watch/(?P<channel>[^/]+?)/(?P<id>[0-9]+)[^/]+(?:/(?P<recid>[0-9]+))?'
244 # Since regular videos are only available for 7 days and recorded videos
245 # are only available for a specific user, we cannot have detailed tests.
247 'url': 'https://zattoo.com/watch/prosieben/130671867-maze-runner-die-auserwaehlten-in-der-brandwueste',
248 'only_matching': True,
250 'url': 'https://zattoo.com/watch/srf_zwei/132905652-eishockey-spengler-cup/102791477/1512211800000/1514433500000/92000',
251 'only_matching': True,
254 def _real_extract(self, url):
255 channel_name, video_id, record_id = re.match(self._VALID_URL, url).groups()
256 return self._extract_video(channel_name, video_id, record_id)
259 class ZattooLiveIE(ZattooBaseIE):
260 _VALID_URL = r'https?://(?:www\.)?zattoo\.com/watch/(?P<id>[^/]+)'
263 'url': 'https://zattoo.com/watch/srf1',
264 'only_matching': True,
268 def suitable(cls, url):
269 return False if ZattooIE.suitable(url) else super(ZattooLiveIE, cls).suitable(url)
271 def _real_extract(self, url):
272 channel_name = video_id = self._match_id(url)
273 return self._extract_video(channel_name, video_id, is_live=True)