1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- # coding=utf-8
- # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +
- # ┏┓ ┏┓+ +
- # ┏┛┻━━━┛┻┓ + +
- # ┃ ┃
- # ┃ ━ ┃ ++ + + +
- # ████━████ ┃+
- # ┃ ┃ +
- # ┃ ┻ ┃
- # ┃ ┃ + +
- # ┗━┓ ┏━┛
- # ┃ ┃
- # ┃ ┃ + + + +
- # ┃ ┃ Codes are far away from bugs with the animal protecting
- # ┃ ┃ + 神兽保佑,代码无bug
- # ┃ ┃
- # ┃ ┃ +
- # ┃ ┗━━━┓ + +
- # ┃ ┣┓
- # ┃ ┏┛
- # ┗┓┓┏━┳┓┏┛ + + + +
- # ┃┫┫ ┃┫┫
- # ┗┻┛ ┗┻┛+ + + +
- # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +"""
- """
- """
- import base64
- import hashlib
- import time
- def md5(text, isBackByte=False):
- """md5加密函数"""
- md5 = hashlib.md5()
- if isinstance(text, bytes):
- md5.update(text)
- else:
- md5.update(text.encode('utf-8'))
- if isBackByte:
- # 返回二进制的加密结果
- return md5.digest()
- # 返回十六进制的机密结果
- return md5.hexdigest()
- def base64_encode(text, isBytes=False):
- """进行base64编码处理"""
- if isBytes:
- return base64.b64encode(text)
- return base64.b64encode(bytes(text, encoding="utf-8"))
- def get_timestamp10():
- """获取当前时间长度为10位长度的时间戳"""
- return int(time.time())
- secret = 'ansjer'; # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址 secure_link_md5 xiaozhong.com$uri$arg_e;
- # path = '/hls/5553.mp4/index.m3u8' # 下载文件
- # path = '/L59KVYDAEPHR1T6M111A_0/555666.mp4' # 下载文件
- path = '/5553.mp4' # 下载文件
- # path = '/444.mp4' # 下载文件
- # 下载到期时间,time是当前时间,300表示300秒,也就是说从现在到300秒之内文件不过期
- expire = get_timestamp10() + 3600;
- res = md5(str(secret) + str(path) + str(expire), True)
- md5 = str(base64_encode(res, True))
- md5 = md5.replace('b\'', '').replace('\'', '').replace('+', '-').replace('/', '_').replace('=', '')
- # print('生成代相关认证签名的地址:','http://52.8.197.107/444.mp4.m3u8?' + 'st=' + str(md5) + '&e=' + str(expire))
- print('io:','http://52.8.197.107/5553.mp4.m3u8?' + 'st=' + str(md5) + '&e=' + str(expire))
|