Skip to content

Commit

Permalink
Merge pull request #48 from googollee/master
Browse files Browse the repository at this point in the history
使用saveas生成hls回放
  • Loading branch information
why404 committed Feb 28, 2016
2 parents 818978f + 688e9f6 commit f392e4c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ pip install pili
```python
from pili import *

access_key = 'qiniu_access_key'
access_key = 'qiniu_access_key'
secret_key = 'qiniu_secret_key'

hub_name = 'pili_hub_name' # The Hub must be exists before use

# Change API host as necessary
#
#
# pili.qiniuapi.com as default
# pili-lte.qiniuapi.com is the latest RC version
#
#
# conf.API_HOST = 'pili.qiniuapi.com' # default
```

Expand Down Expand Up @@ -267,7 +267,7 @@ print status
# "addr": "222.73.202.226:2572",
# "status": "connected",
# "bytesPerSecond": 16870.200000000001,
# "framesPerSecond": {
# "framesPerSecond": {
# "audio": 42.200000000000003,
# "video": 14.733333333333333,
# "data": 0.066666666666666666,
Expand Down Expand Up @@ -317,7 +317,7 @@ original_url = urls["ORIGIN"]
# format : required, string, see http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
# start : required, int64, in second, unix timestamp
# end : required, int64, in second, unix timestamp
# notifyUrl : optional, string
# notifyUrl : optional, string
res = stream.save_as(name="videoName.mp4", format="mp4", start=1440282134, end=1440437833, notifyUrl=None)
print res
# {
Expand All @@ -333,7 +333,7 @@ print res
# name : required, string
# format : required, string see http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
# time : optional, int64, in second, unix timestamp
# notifyUrl : optional, string
# notifyUrl : optional, string
res = stream.snapshot(name="imageName.jpg", format="jpg", time=None, notifyUrl=None)
print res
# {
Expand All @@ -354,6 +354,8 @@ stream.delete()

## History

- 1.5.7
- Use save_as in hls_playback_urls
- 1.5.0
- Update Stream Create,Get,List
- hub.create_stream()
Expand Down
12 changes: 6 additions & 6 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
hub_name = "Pili_Hub_Name" # The Hub must be exists before use

# Change API host as necessary
#
#
# pili.qiniuapi.com as default
# pili-lte.qiniuapi.com is the latest RC version
#
#
# conf.API_HOST = 'pili.qiniuapi.com' #default

credentials = Credentials(access_key, secret_key)
Expand Down Expand Up @@ -137,7 +137,7 @@
# "addr": "222.73.202.226:2572",
# "status": "connected",
# "bytesPerSecond": 16870.200000000001,
# "framesPerSecond": {
# "framesPerSecond": {
# "audio": 42.200000000000003,
# "video": 14.733333333333333,
# "data": 0.066666666666666666,
Expand Down Expand Up @@ -185,10 +185,10 @@

# Save Stream as a file
# name : required, string
# format : required, string, see http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
# start : required, int64, in second, unix timestamp
# end : required, int64, in second, unix timestamp
# notifyUrl : optional, string
# format : optional, string, see http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
# notifyUrl : optional, string
res = stream.save_as(name="videoName.mp4", format="mp4", start=1440282134, end=1440437833, notifyUrl=None)
print res
# {
Expand All @@ -201,7 +201,7 @@
# name : required, string
# format : required, string see http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
# time : optional, int64, in second, unix timestamp
# notifyUrl : optional, string
# notifyUrl : optional, string
res = stream.snapshot(name="imageName.jpg", format="jpg", time=None, notifyUrl=None)
print res
# {
Expand Down
5 changes: 3 additions & 2 deletions pili/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def get_stream(stream_id):
def get_stream_list(**args):
keyword = ['hub', 'marker', 'limit', 'title', 'status', 'idonly']
args = normalize(args, keyword)
if args['idonly'] is not True:
del args['idonly']
if args.has_key('idonly'):
if args['idonly'] is not True:
del args['idonly']
url = "http://%s/%s/streams?" % (conf.API_HOST, conf.API_VERSION)
for k, v in args.items():
url += "&%s=%s" % (k, v)
Expand Down
11 changes: 3 additions & 8 deletions pili/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@ def hls_live_urls(self):
return res

def hls_playback_urls(self, start_second, end_second):
name = str(int(time.time()))
resp = self.save_as(name=name, start=start_second, end=end_second)
res = dict()
url = self.__base__("http", self.hosts["playback"]["hls"], "") + ".m3u8"
url += "?start=%d&end=%d" % (start_second, end_second)
res["ORIGIN"] = url
if self.profiles!=None:
for profile in self.profiles:
url = self.__base__("http", self.hosts["playback"]["hls"], profile) + ".m3u8"
url += "?start=%d&end=%d" % (start_second, end_second)
res[profile] = url
res["ORIGIN"] = resp["url"]
return res

def rtmp_publish_url(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name = 'pili',
version = '1.5.6',
version = '1.5.7',
keywords = ('pili'),
description = 'Pili Streaming Cloud server-side library for Python',
license = 'MIT License',
Expand Down

0 comments on commit f392e4c

Please sign in to comment.