Skip to content

Instantly share code, notes, and snippets.

@dvl
Last active August 29, 2015 14:26
Show Gist options
  • Save dvl/6ea429704143907bcd55 to your computer and use it in GitHub Desktop.
Save dvl/6ea429704143907bcd55 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import base64
import hashlib
import time
HOST = 'localhost'
URL = 'http://{}:1935/'.format(HOST)
STREAM = 'live/myStream'
START_TIME = int(time.time())
END_TIME = START_TIME + 60 * 5
SECRET = 'mySharedSecret'
TOKEN_PREFIX = 'wowzatoken'
CLIENT_IP = '127.0.0.1'
parameters = [
'{0}starttime={1}'.format(TOKEN_PREFIX, START_TIME),
'{0}endtime={1}'.format(TOKEN_PREFIX, END_TIME),
SECRET,
CLIENT_IP,
]
parameters.sort()
string_to_hash = '{0}?{1}'.format(STREAM, '&'.join(parameters))
hashed = hashlib.sha256(string_to_hash).digest()
base64hash = base64.b64encode(hashed, '-_')
playback_url = '{url}{stream}/playlist.m3u8?' \
'{token_prefix}starttime={starttime}&' \
'{token_prefix}endtime={endtime}&' \
'{token_prefix}hash={base64hash}'
playback_url = playback_url.format(
url=URL,
stream=STREAM,
token_prefix=TOKEN_PREFIX,
starttime=START_TIME,
endtime=END_TIME,
base64hash=base64hash
)
print(playback_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment