#!/usr/bin/env python import hashlib import time from optparse import OptionParser # your secret, can be overridden using the --secret parameter. secret='ADBbUSKOv5WxGCi9yEesRg8u' parser = OptionParser() parser.add_option("-d", "--dns-mask", dest="dnsmask", help="DNS mask for content.bitsontherun.com, e.g. 'videos.yoursite.com'") parser.add_option("-u", "--urlpath", dest="urlpath", help="URL path, e.g. 'videos/a1b2c3d4.mp4'") parser.add_option("-s", "--secret", dest="secret", help="Your secret key") parser.add_option("-t", "--timeout", dest="timeout", type="int", help="Timeout, in seconds, from now") (options, args) = parser.parse_args() if not options.urlpath: parser.error("You need to specify the urlpath parameter") if options.secret: secret = options.secret if not options.timeout: # default timeout is one hour. Usage of smaller timeouts is # discouraged. options.timeout = 3600 expiry_timestamp = int(time.time()) + options.timeout sign_data = '%s:%d:%s' % (options.urlpath, expiry_timestamp, secret) signature = hashlib.md5(sign_data).hexdigest() print("URL: http://%s/%s?exp=%d&sig=%s" % \ (options.dnsmask or 'content.bitsontherun.com', options.urlpath, expiry_timestamp, signature))