def setUp(self): hub_name = "PiliSDKTest" access_key = env("QINIU_ACCESS_KEY") secret_key = env("QINIU_SECRET_KEY") if access_key == "" or secret_key == "": raise unittest.SkipTest("need set access_key or secret_key") if env("PILI_API_HOST") != "": pili.conf.API_HOST = env("PILI_API_HOST") client = pili.Client(pili.Mac(access_key, secret_key)) self.hub = client.hub(hub_name)
def gen_url(): mac = pili.Mac('illyLZP9RlWGikwwITutZvqqZTz73B8kTceDJ1gG', 'Qi3iL46RypaqivLD0_D7zRkijgD1jQEPdstMNh2w') hub = 'raspi' key = 'raspi_key' publish = 'pili-publish.raspi-live.buhuipao.com' rtmp = 'pili-live-rtmp.raspi-live.buhuipao.com' hls = 'pili-live-hls.raspi-live.buhuipao.com' publish_url = pili.rtmp_publish_url(publish, hub, key, mac, 3600) rtmp_url = pili.rtmp_play_url(rtmp, hub, key) print('rtmp player url: %s' % rtmp_url) hls_url = pili.hls_play_url(hls, hub, key) print('hls player url: %s' % hls_url) return publish_url
def expirySkRtmpUrl(access_key, secret_key, domain, hub, stream_title, expiry): """ 限时鉴权sk(expiry_sk) 推流地址 https://developer.qiniu.com/pili/api/6678/push-the-current-authentication#4 :param domain: 推流域名 :param hub: 直播空间 :param stream_title: 流名 :param expiry: 过期时间 :return: 推流地址 """ mac = pili.Mac(access_key, secret_key) expireAt = int(time.time()) + expiry path = f"{hub}/{stream_title}?e={expireAt}" data = base64.urlsafe_b64decode(hmac.new(path, mac.__auth__.secret_key, hashlib.sha1).digest()) token = f"{mac.__auth__.access_key}:{data}" expirySkRtmpUrl = f"rtmp://{domain}/{path}&token={token}" return expirySkRtmpUrl
ret = {'code': 501, 'msg': 'follow not found'} return jsonify({'ret': ret}) else: db.session.delete(query_follow) db.session.commit() query_follow_new = Follow.query.filter_by( from_user_id=get['from_id'], to_user_id=get['to_id']).first() if query_follow_new == None: ret = {'code': 101, 'msg': 'delete follow success'} return jsonify({'ret': ret}) else: ret = {'code': 501, 'msg': 'delete follow failed'} return jsonify({'ret': ret}) mac = pili.Mac(accessKey, secretKey) client = pili.Client(mac) hub = client.hub("derya") # key = "streamKey2" # key由uid生成 # 1.生成带授权凭证的 RTMP 推流地址 # 参数:key @app.route('/huli/getRTMPPublishURL/', methods=['POST']) def get_rtmp_publish(): if not request.json: abort(400) key = request.json['key'] rtmp_publish = pili.rtmp_publish_url("pili-publish.pearapple.net", hubName, key, mac, 60)
# 替换成自己 Qiniu 账号的 AccessKey access_key = "..." # 替换成自己 Qiniu 账号的 SecretKey secret_key = "..." domain = '...' hub_name = '...' stream_title = '...' expire = 3600 mac = pili.Mac(access_key, secret_key) client = pili.Client(mac) hub = client.hub(hub_name) stream = hub.get("...") print pili.rtmp_publish_url(domain, hub_name, stream_title, mac, expire) print pili.rtmp_play_url(domain, hub_name, stream_title) print pili.hls_play_url(domain, hub_name, stream_title) print pili.hdl_play_url(domain, hub_name, stream_title) print pili.snapshot_play_url(domain, hub_name, stream_title)