Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zattoo] Added support for zattoo recordings #1480

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/streamlink/plugins/zattoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Zattoo(Plugin):
API_LOGIN = '{0}/zapi/v2/account/login'
API_CHANNELS = '{0}/zapi/v2/cached/channels/{1}?details=False'
API_WATCH = '{0}/zapi/watch'
API_WATCH_REC = '{0}/zapi/watch/recording/{1}'
API_WATCH_VOD = '{0}/zapi/avod/videos/{1}/watch'

_url_re = re.compile(r'''
Expand All @@ -26,9 +27,14 @@ class Zattoo(Plugin):
tvonline\.ewe\.de
|
nettv\.netcologne\.de
)/(?:watch/(?P<channel>[^/\s]+)
|
ondemand/watch/(?P<vod_id>[^-]+)-)
)/
(?:
(?:ondemand/)?(?:watch/(?:[^/\s]+)(?:/[^/]+/(?P<recording_id>\d+)))
|
watch/(?P<channel>[^/\s]+)
|
ondemand/watch/(?P<vod_id>[^-]+)-
)
''', re.VERBOSE)

_app_token_re = re.compile(r"""window\.appToken\s+=\s+'([^']+)'""")
Expand Down Expand Up @@ -122,9 +128,11 @@ def _watch(self):
self.logger.debug('_watch ...')
match = self._url_re.match(self.url)
if not match:
self.logger.debug('_watch ... no match')
return
channel = match.group('channel')
vod_id = match.group('vod_id')
recording_id = match.group('recording_id')

cookies = {
'beaker.session.id': self._session_attributes.get('beaker.session.id'),
Expand All @@ -136,8 +144,11 @@ def _watch(self):
params, watch_url = self._watch_live(channel, cookies)
elif vod_id:
params, watch_url = self._watch_vod(vod_id)
elif recording_id:
params, watch_url = self._watch_recording(recording_id)

if not watch_url:
self.logger.debug('Missing watch_url')
return

res = []
Expand All @@ -153,6 +164,7 @@ def _watch(self):
self.logger.error(str(e))
return

self.logger.debug('Found post data')
data = http.json(res)

if data['success']:
Expand Down Expand Up @@ -194,6 +206,15 @@ def _watch_live(self, channel, cookies):
}
return params, watch_url

def _watch_recording(self, recording_id):
self.logger.debug('_watch_recording ...')
watch_url = self.API_WATCH_REC.format(self.base_url, recording_id)
params = {
'https_watch_urls': True,
'stream_type': 'hls'
}
return params, watch_url

def _watch_vod(self, vod_id):
self.logger.debug('_watch_vod ...')
watch_url = self.API_WATCH_VOD.format(self.base_url, vod_id)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_plugin_zattoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def test_can_handle_url(self):
# zattoo vod
self.assertTrue(Zattoo.can_handle_url('https://zattoo.com/ondemand/watch/ibR2fpisWFZGvmPBRaKnFnuT-alarm-am-airport'))
self.assertTrue(Zattoo.can_handle_url('https://zattoo.com/ondemand/watch/G8S7JxcewY2jEwAgMzvFWK8c-berliner-schnauzen'))
# zattoo recording
self.assertTrue(Zattoo.can_handle_url('https://zattoo.com/ondemand/watch/srf_zwei/110223896-die-schweizermacher/52845783/1455130800000/1455137700000/6900000'))
self.assertTrue(Zattoo.can_handle_url('https://zattoo.com/watch/tve/130920738-viaje-al-centro-de-la-tele/96847859/1508777100000/1508779800000/0'))

# shouldn't match
self.assertFalse(Zattoo.can_handle_url('https://ewe.de'))
Expand Down