2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
22 class ZattooPlatformBaseIE(InfoExtractor
):
23 _power_guide_hash
= None
26 return 'https://%s' % (self
._API
_HOST
if hasattr(self
, '_API_HOST') else self
._HOST
)
28 def _real_initialize(self
):
29 if not self
._power
_guide
_hash
:
30 self
.raise_login_required('An account is needed to access this media', method
='password')
32 def _perform_login(self
, username
, password
):
34 data
= self
._download
_json
(
35 '%s/zapi/v2/account/login' % self
._host
_url
(), None, 'Logging in',
36 data
=urlencode_postdata({
41 'Referer': '%s/login' % self
._host
_url
(),
42 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
44 except ExtractorError
as e
:
45 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 400:
47 'Unable to login: incorrect username and/or password',
51 self
._power
_guide
_hash
= data
['session']['power_guide_hash']
53 def _initialize_pre_login(self
):
54 webpage
= self
._download
_webpage
(
55 self
._host
_url
(), None, 'Downloading app token')
56 app_token
= self
._html
_search
_regex
(
57 r
'appToken\s*=\s*(["\'])(?P
<token
>(?
:(?
!\
1).)+?
)\
1',
58 webpage, 'app token
', group='token
')
59 app_version = self._html_search_regex(
60 r'<!--\w
+-(.+?
)-', webpage, 'app version
', default='2.8.2')
62 # Will setup appropriate cookies
63 self._request_webpage(
64 '%s/zapi
/v2
/session
/hello
' % self._host_url(), None,
65 'Opening session
', data=urlencode_postdata({
66 'client_app_token
': app_token,
67 'uuid
': compat_str(uuid4()),
69 'app_version
': app_version,
73 def _extract_cid(self, video_id, channel_name):
74 channel_groups = self._download_json(
75 '%s/zapi
/v2
/cached
/channels
/%s' % (self._host_url(),
76 self._power_guide_hash),
77 video_id, 'Downloading channel
list',
78 query={'details': False})['channel_groups
']
80 for chgrp in channel_groups:
81 channel_list.extend(chgrp['channels
'])
84 chan['cid
'] for chan in channel_list
85 if chan.get('cid
') and (
86 chan.get('display_alias
') == channel_name
87 or chan.get('cid
') == channel_name))
89 raise ExtractorError('Could
not extract channel
id')
91 def _extract_cid_and_video_info(self, video_id):
92 data = self._download_json(
93 '%s/zapi
/v2
/cached
/program
/power_details
/%s' % (
94 self._host_url(), self._power_guide_hash),
96 'Downloading video information
',
98 'program_ids
': video_id,
102 p = data['programs
'][0]
107 'title
': p.get('t
') or p['et
'],
108 'description
': p.get('d
'),
109 'thumbnail
': p.get('i_url
'),
110 'creator
': p.get('channel_name
'),
111 'episode
': p.get('et
'),
112 'episode_number
': int_or_none(p.get('e_no
')),
113 'season_number
': int_or_none(p.get('s_no
')),
114 'release_year
': int_or_none(p.get('year
')),
115 'categories
': try_get(p, lambda x: x['c
'], list),
116 'tags
': try_get(p, lambda x: x['g
'], list)
119 return cid, info_dict
121 def _extract_formats(self, cid, video_id, record_id=None, is_live=False):
123 'https_watch_urls
': True,
127 postdata_common.update({'timeshift': 10800})
128 url = '%s/zapi
/watch
/live
/%s' % (self._host_url(), cid)
130 url = '%s/zapi
/watch
/recording
/%s' % (self._host_url(), record_id)
132 url = '%s/zapi
/watch
/recall
/%s/%s' % (self._host_url(), cid, video_id)
135 for stream_type in ('dash
', 'hls
', 'hls5
', 'hds
'):
136 postdata = postdata_common.copy()
137 postdata['stream_type
'] = stream_type
139 data = self._download_json(
140 url, video_id, 'Downloading
%s formats
' % stream_type.upper(),
141 data=urlencode_postdata(postdata), fatal=False)
145 watch_urls = try_get(
146 data, lambda x: x['stream
']['watch_urls
'], list)
150 for watch in watch_urls:
151 if not isinstance(watch, dict):
153 watch_url = url_or_none(watch.get('url
'))
156 audio_channel = watch.get('audio_channel
')
157 preference = 1 if audio_channel == 'A
' else None
158 format_id = join_nonempty(stream_type, watch.get('maxrate
'), audio_channel)
159 if stream_type in ('dash
', 'dash_widevine
', 'dash_playready
'):
160 this_formats = self._extract_mpd_formats(
161 watch_url, video_id, mpd_id=format_id, fatal=False)
162 elif stream_type in ('hls
', 'hls5
', 'hls5_fairplay
'):
163 this_formats = self._extract_m3u8_formats(
164 watch_url, video_id, 'mp4
',
165 entry_protocol='m3u8_native
', m3u8_id=format_id,
167 elif stream_type == 'hds
':
168 this_formats = self._extract_f4m_formats(
169 watch_url, video_id, f4m_id=format_id, fatal=False)
170 elif stream_type == 'smooth_playready
':
171 this_formats = self._extract_ism_formats(
172 watch_url, video_id, ism_id=format_id, fatal=False)
175 for this_format in this_formats:
176 this_format['quality
'] = preference
177 formats.extend(this_formats)
178 self._sort_formats(formats)
181 def _extract_video(self, channel_name, video_id, record_id=None, is_live=False):
183 cid = self._extract_cid(video_id, channel_name)
186 'title
': channel_name,
190 cid, info_dict = self._extract_cid_and_video_info(video_id)
191 formats = self._extract_formats(
192 cid, video_id, record_id=record_id, is_live=is_live)
193 info_dict['formats
'] = formats
197 class QuicklineBaseIE(ZattooPlatformBaseIE):
198 _NETRC_MACHINE = 'quickline
'
199 _HOST = 'mobiltv
.quickline
.com
'
202 class QuicklineIE(QuicklineBaseIE):
203 _VALID_URL = r'https?
://(?
:www\
.)?
%s/watch
/(?P
<channel
>[^
/]+)/(?P
<id>[0-9]+)' % re.escape(QuicklineBaseIE._HOST)
206 'url
': 'https
://mobiltv
.quickline
.com
/watch
/prosieben
/130671867-maze
-runner
-die
-auserwaehlten
-in-der
-brandwueste
',
207 'only_matching
': True,
210 def _real_extract(self, url):
211 channel_name, video_id = self._match_valid_url(url).groups()
212 return self._extract_video(channel_name, video_id)
215 class QuicklineLiveIE(QuicklineBaseIE):
216 _VALID_URL = r'https?
://(?
:www\
.)?
%s/watch
/(?P
<id>[^
/]+)' % re.escape(QuicklineBaseIE._HOST)
219 'url
': 'https
://mobiltv
.quickline
.com
/watch
/srf1
',
220 'only_matching
': True,
224 def suitable(cls, url):
225 return False if QuicklineIE.suitable(url) else super(QuicklineLiveIE, cls).suitable(url)
227 def _real_extract(self, url):
228 channel_name = video_id = self._match_id(url)
229 return self._extract_video(channel_name, video_id, is_live=True)
232 class ZattooBaseIE(ZattooPlatformBaseIE):
233 _NETRC_MACHINE = 'zattoo
'
237 def _make_valid_url(tmpl, host):
238 return tmpl % re.escape(host)
241 class ZattooIE(ZattooBaseIE):
242 _VALID_URL_TEMPLATE = r'https?
://(?
:www\
.)?
%s/watch
/(?P
<channel
>[^
/]+?
)/(?P
<id>[0-9]+)[^
/]+(?
:/(?P
<recid
>[0-9]+))?
'
243 _VALID_URL = _make_valid_url(_VALID_URL_TEMPLATE, ZattooBaseIE._HOST)
245 # Since regular videos are only available for 7 days and recorded videos
246 # are only available for a specific user, we cannot have detailed tests.
248 'url
': 'https
://zattoo
.com
/watch
/prosieben
/130671867-maze
-runner
-die
-auserwaehlten
-in-der
-brandwueste
',
249 'only_matching
': True,
251 'url
': 'https
://zattoo
.com
/watch
/srf_zwei
/132905652-eishockey
-spengler
-cup
/102791477/1512211800000/1514433500000/92000',
252 'only_matching
': True,
255 def _real_extract(self, url):
256 channel_name, video_id, record_id = self._match_valid_url(url).groups()
257 return self._extract_video(channel_name, video_id, record_id)
260 class ZattooLiveIE(ZattooBaseIE):
261 _VALID_URL = r'https?
://(?
:www\
.)?zattoo\
.com
/watch
/(?P
<id>[^
/]+)'
264 'url
': 'https
://zattoo
.com
/watch
/srf1
',
265 'only_matching
': True,
269 def suitable(cls, url):
270 return False if ZattooIE.suitable(url) else super(ZattooLiveIE, cls).suitable(url)
272 def _real_extract(self, url):
273 channel_name = video_id = self._match_id(url)
274 return self._extract_video(channel_name, video_id, is_live=True)
277 class NetPlusIE(ZattooIE):
278 _NETRC_MACHINE = 'netplus
'
280 _API_HOST = 'www
.%s' % _HOST
281 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
284 'url
': 'https
://www
.netplus
.tv
/watch
/abc
/123-abc
',
285 'only_matching
': True,
289 class MNetTVIE(ZattooIE):
290 _NETRC_MACHINE = 'mnettv
'
291 _HOST = 'tvplus
.m
-net
.de
'
292 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
295 'url
': 'https
://tvplus
.m
-net
.de
/watch
/abc
/123-abc
',
296 'only_matching
': True,
300 class WalyTVIE(ZattooIE):
301 _NETRC_MACHINE = 'walytv
'
302 _HOST = 'player
.waly
.tv
'
303 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
306 'url
': 'https
://player
.waly
.tv
/watch
/abc
/123-abc
',
307 'only_matching
': True,
311 class BBVTVIE(ZattooIE):
312 _NETRC_MACHINE = 'bbvtv
'
314 _API_HOST = 'www
.%s' % _HOST
315 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
318 'url
': 'https
://www
.bbv
-tv
.net
/watch
/abc
/123-abc
',
319 'only_matching
': True,
323 class VTXTVIE(ZattooIE):
324 _NETRC_MACHINE = 'vtxtv
'
326 _API_HOST = 'www
.%s' % _HOST
327 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
330 'url
': 'https
://www
.vtxtv
.ch
/watch
/abc
/123-abc
',
331 'only_matching
': True,
335 class MyVisionTVIE(ZattooIE):
336 _NETRC_MACHINE = 'myvisiontv
'
337 _HOST = 'myvisiontv
.ch
'
338 _API_HOST = 'www
.%s' % _HOST
339 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
342 'url
': 'https
://www
.myvisiontv
.ch
/watch
/abc
/123-abc
',
343 'only_matching
': True,
347 class GlattvisionTVIE(ZattooIE):
348 _NETRC_MACHINE = 'glattvisiontv
'
349 _HOST = 'iptv
.glattvision
.ch
'
350 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
353 'url
': 'https
://iptv
.glattvision
.ch
/watch
/abc
/123-abc
',
354 'only_matching
': True,
358 class SAKTVIE(ZattooIE):
359 _NETRC_MACHINE = 'saktv
'
361 _API_HOST = 'www
.%s' % _HOST
362 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
365 'url
': 'https
://www
.saktv
.ch
/watch
/abc
/123-abc
',
366 'only_matching
': True,
370 class EWETVIE(ZattooIE):
371 _NETRC_MACHINE = 'ewetv
'
372 _HOST = 'tvonline
.ewe
.de
'
373 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
376 'url
': 'https
://tvonline
.ewe
.de
/watch
/abc
/123-abc
',
377 'only_matching
': True,
381 class QuantumTVIE(ZattooIE):
382 _NETRC_MACHINE = 'quantumtv
'
383 _HOST = 'quantum
-tv
.com
'
384 _API_HOST = 'www
.%s' % _HOST
385 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
388 'url
': 'https
://www
.quantum
-tv
.com
/watch
/abc
/123-abc
',
389 'only_matching
': True,
393 class OsnatelTVIE(ZattooIE):
394 _NETRC_MACHINE = 'osnateltv
'
395 _HOST = 'tvonline
.osnatel
.de
'
396 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
399 'url
': 'https
://tvonline
.osnatel
.de
/watch
/abc
/123-abc
',
400 'only_matching
': True,
404 class EinsUndEinsTVIE(ZattooIE):
405 _NETRC_MACHINE = '1und
1tv
'
407 _API_HOST = 'www
.%s' % _HOST
408 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
411 'url
': 'https
://www
.1und
1.tv
/watch
/abc
/123-abc
',
412 'only_matching
': True,
416 class SaltTVIE(ZattooIE):
417 _NETRC_MACHINE = 'salttv
'
419 _VALID_URL = _make_valid_url(ZattooIE._VALID_URL_TEMPLATE, _HOST)
422 'url
': 'https
://tv
.salt
.ch
/watch
/abc
/123-abc
',
423 'only_matching
': True,