- URL
- RTMP推流地址: rtmp_publish_url(domain, hub, key, mac, expire_after_seconds)
- RTMP直播地址: rtmp_play_url(domain, hub, key)
- HLS直播地址: hls_play_url(domain, hub, key)
- HDL直播地址: hdl_play_url(domain, hub, key)
- 截图直播地址: snapshot_play_url(domain, hub, key)
- Hub
- 创建流: hub.create(key)
- 获得流: hub.get(key)
- 列出流: hub.list(prefix, limit, marker, liveonly)
- Stream
- 流信息: stream.Info()
- 禁用流: stream.disable()
- 启用流: stream.dnable()
- 查询直播状态: stream.status()
- 保存直播回放: stream.save(start, end)
- 查询直播历史: stream.history(start, end)
before next step, install git.
# install latest version
$ pip install pili2
import pili
mac = pili.Mac(AccessKey, SecretKey)
client = pili.Client(mac)
# ...
url = pili.rtmp_publish_url("publish-rtmp.test.com", "PiliSDKTest", "streamkey", mac, 60)
print url
# rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
url = pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamkey")
print url
# rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
url = pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
url = pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-hdl.test.com/PiliSDKTest/streamkey.flv
url = pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
mac = pili.Mac(AccessKey, SecretKey)
client = pili.Client(mac)
hub = client.hub("PiliSDKTest")
# ...
stream = hub.create(key)
print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
stream = hub.get(key)
print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
for s in hub.list()["items"]:
print s.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# ...
for s in hub.list(liveonly=True)["items"]:
print s.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# ...
print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
stream.disable()
print stream.to_json()
# before disable: {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# after disable: {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": -1, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
stream.enable()
print stream.to_json()
# before disable: {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": -1, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# after disable: {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
print stream.status
# {"startAt": 1463382400, "clientIP": "172.21.1.214:52897" "bps": 128854, "fps": {"audio": 38, "video": 23, "data": 0}}
print stream.history
# {"items": [{"start": 1463382401, "end": 1463382441}]}
print stream.save_as()
# {"fname": "recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8"}