Skip to content

Latest commit

 

History

History
207 lines (156 loc) · 5.54 KB

README.md

File metadata and controls

207 lines (156 loc) · 5.54 KB

Pili Streaming Cloud server-side library for Python

Features

  • 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)

Contents

Installation

before next step, install git.

# install latest version
$ pip install pili2

Usage

Configuration

import pili

mac = pili.Mac(AccessKey, SecretKey)
client = pili.Client(mac)

# ...

URL

Generate RTMP publish URL

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=

Generate RTMP play URL

url = pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamkey")
print url
# rtmp://live-rtmp.test.com/PiliSDKTest/streamkey

Generate HLS play URL

url = pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-hls.test.com/PiliSDKTest/streamkey.m3u8

Generate HDL play URL

url = pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-hdl.test.com/PiliSDKTest/streamkey.flv

Generate Snapshot play URL

url = pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamkey")
print url
# http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg

Hub

Instantiate a Pili Hub object

mac = pili.Mac(AccessKey, SecretKey)
client = pili.Client(mac)
hub = client.hub("PiliSDKTest")
# ...

Create a new Stream

stream = hub.create(key)

print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}

Get a Stream

stream = hub.get(key)

print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}

List Streams

for s in hub.list()["items"]:
    print s.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# ...

List live Streams

for s in hub.list(liveonly=True)["items"]:
    print s.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}
# ...

Stream

Get Stream info

print stream.to_json()
# {"expireAt": 1465271243, "hub": "PiliSDKTest", "disabledTill": 0, "key": "streamKey", "updatedAt": 1463975243, "createdAt": 1463975243}

Disable a Stream

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}

Enable a Stream

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}

Get Stream live status

print stream.status
# {"startAt": 1463382400, "clientIP": "172.21.1.214:52897" "bps": 128854, "fps": {"audio": 38, "video": 23, "data": 0}}

Get Stream history activity

print stream.history
# {"items": [{"start": 1463382401, "end": 1463382441}]}

Save Stream live playback

print stream.save_as()
# {"fname": "recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8"}