pili 1.3.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +420 -129
- data/example/example.rb +181 -0
- data/lib/pili/api.rb +87 -42
- data/lib/pili/config.rb +14 -11
- data/lib/pili/{auth.rb → credentials.rb} +11 -1
- data/lib/pili/hub.rb +29 -0
- data/lib/pili/rpc.rb +80 -0
- data/lib/pili/stream.rb +57 -51
- data/lib/pili/version.rb +1 -1
- data/lib/pili.rb +3 -2
- metadata +6 -4
- data/lib/pili/client.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23353fd81b87b9123d66b1ae43ff0bcab17a1394
|
4
|
+
data.tar.gz: 26c4b2efa6956cf2807c7980e41d109aca547a89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 821ade8cbfb8aa4b98238d67d7dec341dded6825a6a522a46bb59032e93d64b7f07466eee0480477211fbfda1672daf50127d7c45114df5afe9bbfb3d40c703e
|
7
|
+
data.tar.gz: afb135beccd5561a2919d0da9887fffa9b7fe6eae1278d181f65ca55f97438c6ac1322a9c534411a265193b282a71b6fd3197892c197466d170dab6a75bf5ccf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,51 @@
|
|
1
|
-
# Pili server-side library for Ruby
|
1
|
+
# Pili Streaming Cloud server-side library for Ruby
|
2
2
|
|
3
3
|
## Features
|
4
4
|
|
5
|
-
-
|
6
|
-
- [x]
|
7
|
-
- [x]
|
8
|
-
- [x]
|
9
|
-
-
|
10
|
-
- [x]
|
11
|
-
- [x]
|
12
|
-
|
13
|
-
|
5
|
+
- Stream Create,Get,List
|
6
|
+
- [x] hub.create_stream()
|
7
|
+
- [x] hub.get_stream()
|
8
|
+
- [x] hub.list_streams()
|
9
|
+
- Stream operations else
|
10
|
+
- [x] stream.to_json()
|
11
|
+
- [x] stream.update()
|
12
|
+
- [x] stream.disable()
|
13
|
+
- [x] stream.enable()
|
14
|
+
- [x] stream.status()
|
15
|
+
- [x] stream.rtmp_publish_url()
|
16
|
+
- [x] stream.rtmp_live_urls()
|
17
|
+
- [x] stream.hls_live_urls()
|
18
|
+
- [x] stream.http_flv_live_urls()
|
19
|
+
- [x] stream.segments()
|
20
|
+
- [x] stream.hls_playback_urls()
|
21
|
+
- [x] stream.save_as()
|
22
|
+
- [x] stream.snapshot()
|
23
|
+
- [x] stream.delete()
|
24
|
+
|
25
|
+
## Contents
|
14
26
|
|
15
27
|
- [Installation](#installation)
|
16
28
|
- [Usage](#usage)
|
17
29
|
- [Configuration](#configuration)
|
18
|
-
- [
|
19
|
-
- [
|
20
|
-
- [Create a
|
21
|
-
- [Get a
|
22
|
-
- [List
|
30
|
+
- [Hub](#hub)
|
31
|
+
- [Instantiate a Pili Hub object](#instantiate-a-pili-hub-object)
|
32
|
+
- [Create a new Stream](#create-a-new-stream)
|
33
|
+
- [Get a Stream](#get-a-stream)
|
34
|
+
- [List Streams](#list-streams)
|
23
35
|
- [Stream](#stream)
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
- [
|
27
|
-
- [
|
36
|
+
- [To JSON String](#to-json-string)
|
37
|
+
- [Update a Stream](#update-a-stream)
|
38
|
+
- [Disable a Stream](#disable-a-stream)
|
39
|
+
- [Enable a Stream](#enable-a-stream)
|
28
40
|
- [Generate RTMP publish URL](#generate-rtmp-publish-url)
|
29
41
|
- [Generate RTMP live play URLs](#generate-rtmp-live-play-urls)
|
30
42
|
- [Generate HLS live play URLs](#generate-hls-live-play-urls)
|
43
|
+
- [Generate HTTP-FLV live play URLs](#generate-http-flv-live-play-urls)
|
44
|
+
- [Get Stream segments](#get-stream-segments)
|
31
45
|
- [Generate HLS playback URLs](#generate-hls-playback-urls)
|
32
|
-
- [
|
33
|
-
- [
|
46
|
+
- [Save Stream as a file](#save-stream-as-a-file)
|
47
|
+
- [Snapshot Stream](#snapshot-stream)
|
48
|
+
- [Delete a stream](#delete-a-stream)
|
34
49
|
- [History](#history)
|
35
50
|
|
36
51
|
## Installation
|
@@ -55,191 +70,467 @@ Or install it yourself as:
|
|
55
70
|
```ruby
|
56
71
|
require 'pili'
|
57
72
|
|
58
|
-
ACCESS_KEY
|
59
|
-
SECRETE_KEY = '
|
73
|
+
ACCESS_KEY = 'Qiniu_AccessKey'
|
74
|
+
SECRETE_KEY = 'Qiniu_SecretKey'
|
75
|
+
|
76
|
+
HUB_NAME = 'Pili_Hub_Name' # The Hub must be exists before use
|
60
77
|
|
61
|
-
|
78
|
+
# Change API host as necessary
|
79
|
+
# pili.qiniuapi.com as deafult
|
80
|
+
# pili-lte.qiniuapi.com is the latest RC version
|
81
|
+
Pili::Config.init api_host: 'pili-lte.qiniuapi.com'
|
62
82
|
```
|
63
83
|
|
64
|
-
### Client
|
65
84
|
|
66
|
-
|
85
|
+
## Hub
|
67
86
|
|
87
|
+
### Instantiate a Pili Hub object
|
68
88
|
```ruby
|
69
|
-
|
70
|
-
|
89
|
+
credentials = Pili::Credentials.new(ACCESS_KEY, SECRETE_KEY)
|
90
|
+
hub = Pili::Hub.new(credentials, HUB_NAME)
|
91
|
+
puts "Hub initialize =>\n#{hub.inspect}\n\n"
|
71
92
|
```
|
72
93
|
|
73
|
-
|
94
|
+
|
95
|
+
### Create a new Stream
|
74
96
|
|
75
97
|
```ruby
|
76
|
-
|
77
|
-
#
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
98
|
+
begin
|
99
|
+
title = nil # optional, auto-generated as default
|
100
|
+
publish_key = nil # optional, auto-generated as default
|
101
|
+
publish_security = nil # optional, can be "dynamic" or "static", "dynamic" as default
|
102
|
+
|
103
|
+
# stream = hub.create_stream()
|
104
|
+
# or
|
105
|
+
stream = hub.create_stream(title: title, publish_key: publish_key, publish_security: publish_security)
|
106
|
+
|
107
|
+
puts "Hub create_stream() =>\n#{stream.inspect}\n\n"
|
108
|
+
rescue Exception => e
|
109
|
+
puts "Hub create_stream() failed. Caught exception:\n#{e.http_body}\n\n"
|
110
|
+
end
|
111
|
+
|
112
|
+
##<Pili::Stream:0x007fdf9413ab98
|
113
|
+
# @credentials=#<Pili::Credentials:0x007fdf939392c8 @access_key="0QxleRjH-IGYystrYdeY5w6KdkSdJVa5SaBUbJkY", @secret_key="Vg3u2240H6JL78sfjsgLohGLjk_jO5e0cdief0g3">,
|
114
|
+
# @id="z1.hub1.55d886b5e3ba571322003121",
|
115
|
+
# @title="55d886b5e3ba571322003121",
|
116
|
+
# @hub="hub1",
|
117
|
+
# @publish_key="0e18061751841053",
|
118
|
+
# @publish_security="dynamic",
|
119
|
+
# @disabled=false,
|
120
|
+
# @hosts={
|
121
|
+
# "publish"=>{
|
122
|
+
# "rtmp"=>"eksg7h.publish.z1.pili.qiniup.com"
|
123
|
+
# },
|
124
|
+
# "live"=>{
|
125
|
+
# "http"=>"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
126
|
+
# "rtmp"=>"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
127
|
+
# },
|
128
|
+
# "playback"=>{
|
129
|
+
# "http"=>"eksg7h.playback1.z1.pili.qiniucdn.com"
|
130
|
+
# }
|
131
|
+
# },
|
132
|
+
# @created_at="2015-08-22T14:27:01.62Z",
|
133
|
+
# @updated_at="2015-08-22T14:27:01.62Z"
|
134
|
+
#>
|
83
135
|
```
|
84
136
|
|
85
|
-
|
137
|
+
|
138
|
+
### Get a Stream
|
86
139
|
|
87
140
|
```ruby
|
88
|
-
|
89
|
-
|
90
|
-
|
141
|
+
begin
|
142
|
+
stream = hub.get_stream(stream.id)
|
143
|
+
puts "Hub get_stream() =>\n#{stream.inspect}\n\n"
|
144
|
+
rescue Exception => e
|
145
|
+
puts "Hub get_stream() failed. Caught exception:\n#{e.http_body}\n\n"
|
146
|
+
end
|
147
|
+
|
148
|
+
##<Pili::Stream:0x007fdf6413ab67
|
149
|
+
# @credentials=#<Pili::Credentials:0x007fdf939c2238 @access_key="0QxleRjH-IGYystrYdeY5w6KdkSdJVa5SaBUbJkY", @secret_key="Vg3u2240H6JL78sfjsgLohGLjk_jO5e0cdief0g3">,
|
150
|
+
# @id="z1.hub1.55d886b5e3ba571322003121",
|
151
|
+
# @title="55d886b5e3ba571322003121",
|
152
|
+
# @hub="hub1",
|
153
|
+
# @publish_key="0e18061751841053",
|
154
|
+
# @publish_security="dynamic",
|
155
|
+
# @disabled=false,
|
156
|
+
# @hosts={
|
157
|
+
# "publish"=>{
|
158
|
+
# "rtmp"=>"eksg7h.publish.z1.pili.qiniup.com"
|
159
|
+
# },
|
160
|
+
# "live"=>{
|
161
|
+
# "http"=>"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
162
|
+
# "rtmp"=>"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
163
|
+
# },
|
164
|
+
# "playback"=>{
|
165
|
+
# "http"=>"eksg7h.playback1.z1.pili.qiniucdn.com"
|
166
|
+
# }
|
167
|
+
# },
|
168
|
+
# @created_at="2015-08-22T14:27:01.62Z",
|
169
|
+
# @updated_at="2015-08-22T14:27:01.62Z"
|
170
|
+
#>
|
91
171
|
```
|
92
172
|
|
93
|
-
|
173
|
+
|
174
|
+
### List Streams
|
94
175
|
|
95
176
|
```ruby
|
96
|
-
|
97
|
-
|
98
|
-
|
177
|
+
begin
|
178
|
+
marker = nil # optional
|
179
|
+
limit = nil # optional
|
180
|
+
title = nil # optional
|
181
|
+
streams = hub.list_streams(marker: marker, limit: limit, title: title)
|
182
|
+
puts "Hub list_streams() =>\n#{streams.inspect}\n\n"
|
183
|
+
rescue Exception => e
|
184
|
+
puts "Hub list_streams() failed. Caught exception:\n#{e.http_body}\n\n"
|
185
|
+
end
|
186
|
+
|
187
|
+
#[
|
188
|
+
# #<Pili::Stream:0x007fdf94108f58>,
|
189
|
+
# #<Pili::Stream:0x007fdf94108f30>,
|
190
|
+
# #<Pili::Stream:0x007fdf94108f08>,
|
191
|
+
# #<Pili::Stream:0x007fdf94108ee0>,
|
192
|
+
# #<Pili::Stream:0x007fdf94108eb8>,
|
193
|
+
# #<Pili::Stream:0x007fdf94108e90>,
|
194
|
+
# #<Pili::Stream:0x007fdf94108e68>,
|
195
|
+
# #<Pili::Stream:0x007fdf94108e40>,
|
196
|
+
# #<Pili::Stream:0x007fdf94108e18>,
|
197
|
+
# #<Pili::Stream:0x007fdf94108df0>
|
198
|
+
#]
|
99
199
|
```
|
100
200
|
|
101
|
-
### Stream
|
102
201
|
|
103
|
-
|
202
|
+
## Stream
|
203
|
+
|
204
|
+
### To JSON String
|
104
205
|
|
105
206
|
```ruby
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
207
|
+
json_string = stream.to_json()
|
208
|
+
puts "Stream stream.to_json() =>\n#{json_string}\n\n"
|
209
|
+
|
210
|
+
#'{
|
211
|
+
# "id":"z1.hub1.55d886b5e3ba571322003121",
|
212
|
+
# "title":"55d886b5e3ba571322003121",
|
213
|
+
# "hub":"hub1",
|
214
|
+
# "publish_key":"0e18061751841053",
|
215
|
+
# "publish_security":"dynamic",
|
216
|
+
# "disabled":false,
|
217
|
+
# "hosts":{
|
218
|
+
# "publish":{
|
219
|
+
# "rtmp":"eksg7h.publish.z1.pili.qiniup.com"
|
220
|
+
# },
|
221
|
+
# "live":{
|
222
|
+
# "http":"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
223
|
+
# "rtmp":"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
224
|
+
# },
|
225
|
+
# "playback":{
|
226
|
+
# "http":"eksg7h.playback1.z1.pili.qiniucdn.com"
|
227
|
+
# }
|
228
|
+
# },
|
229
|
+
# "created_at":"2015-08-22T10:27:01.62-04:00",
|
230
|
+
# "updated_at":"2015-08-22T10:27:01.62-04:00"
|
231
|
+
#}'
|
111
232
|
```
|
112
233
|
|
113
|
-
|
234
|
+
### Update a Stream
|
114
235
|
|
115
236
|
```ruby
|
116
|
-
|
237
|
+
begin
|
238
|
+
stream.publish_key = "new_secret_words" # optional
|
239
|
+
stream.publish_security = "static" # optional, can be "dynamic" or "static", "dynamic" as default
|
240
|
+
stream.disabled = nil # optional, can be true or false
|
241
|
+
stream = stream.update()
|
242
|
+
puts "Stream update() =>\n#{stream.inspect}\n\n"
|
243
|
+
rescue Exception => e
|
244
|
+
puts "Stream update() failed. Caught exception:\n#{e.http_body}\n\n"
|
245
|
+
end
|
246
|
+
|
247
|
+
##<Pili::Stream:0x007fdf6413ab67
|
248
|
+
# @credentials=#<Pili::Credentials:0x007fdf939c2238 @access_key="0QxleRjH-IGYystrYdeY5w6KdkSdJVa5SaBUbJkY", @secret_key="Vg3u2240H6JL78sfjsgLohGLjk_jO5e0cdief0g3">,
|
249
|
+
# @id="z1.hub1.55d886b5e3ba571322003121",
|
250
|
+
# @title="55d886b5e3ba571322003121",
|
251
|
+
# @hub="hub1",
|
252
|
+
# @publish_key="new_secret_words",
|
253
|
+
# @publish_security="static",
|
254
|
+
# @disabled=false,
|
255
|
+
# @hosts={
|
256
|
+
# "publish"=>{
|
257
|
+
# "rtmp"=>"eksg7h.publish.z1.pili.qiniup.com"
|
258
|
+
# },
|
259
|
+
# "live"=>{
|
260
|
+
# "http"=>"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
261
|
+
# "rtmp"=>"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
262
|
+
# },
|
263
|
+
# "playback"=>{
|
264
|
+
# "http"=>"eksg7h.playback1.z1.pili.qiniucdn.com"
|
265
|
+
# }
|
266
|
+
# },
|
267
|
+
# @created_at="2015-08-22T14:27:01.62Z",
|
268
|
+
# @updated_at="2015-08-22T14:27:01.62Z"
|
269
|
+
#>
|
117
270
|
```
|
118
271
|
|
119
|
-
|
272
|
+
### Disable a Stream
|
120
273
|
|
121
274
|
```ruby
|
122
|
-
|
123
|
-
|
124
|
-
stream.
|
125
|
-
|
126
|
-
|
275
|
+
begin
|
276
|
+
stream = stream.disable()
|
277
|
+
puts "Stream disable() =>\n#{stream.inspect}\n\n"
|
278
|
+
rescue Exception => e
|
279
|
+
puts "Stream disable() failed. Caught exception:\n#{e.http_body}\n\n"
|
280
|
+
end
|
281
|
+
|
282
|
+
##<Pili::Stream:0x007fdf6413ab67
|
283
|
+
# @credentials=#<Pili::Credentials:0x007fdf939c2238 @access_key="0QxleRjH-IGYystrYdeY5w6KdkSdJVa5SaBUbJkY", @secret_key="Vg3u2240H6JL78sfjsgLohGLjk_jO5e0cdief0g3">,
|
284
|
+
# @id="z1.hub_name.55d886b5e3ba571322003121",
|
285
|
+
# @title="55d886b5e3ba571322003121",
|
286
|
+
# @hub="hub1",
|
287
|
+
# @publish_key="new_secret_words",
|
288
|
+
# @publish_security="static",
|
289
|
+
# @disabled=true,
|
290
|
+
# @hosts={
|
291
|
+
# "publish"=>{
|
292
|
+
# "rtmp"=>"eksg7h.publish.z1.pili.qiniup.com"
|
293
|
+
# },
|
294
|
+
# "live"=>{
|
295
|
+
# "http"=>"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
296
|
+
# "rtmp"=>"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
297
|
+
# },
|
298
|
+
# "playback"=>{
|
299
|
+
# "http"=>"eksg7h.playback1.z1.pili.qiniucdn.com"
|
300
|
+
# }
|
301
|
+
# },
|
302
|
+
# @created_at="2015-08-22T14:27:01.62Z",
|
303
|
+
# @updated_at="2015-08-22T14:27:01.62Z"
|
304
|
+
#>
|
305
|
+
```
|
127
306
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
#
|
135
|
-
|
136
|
-
#
|
137
|
-
|
138
|
-
|
307
|
+
|
308
|
+
### Enable a Stream
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
begin
|
312
|
+
stream = stream.enable()
|
313
|
+
puts "Stream enable() =>\n#{stream.inspect}\n\n"
|
314
|
+
rescue Exception => e
|
315
|
+
puts "Stream enable() failed. Caught exception:\n#{e.http_body}\n\n"
|
316
|
+
end
|
317
|
+
|
318
|
+
##<Pili::Stream:0x007fdf6413ab67
|
319
|
+
# @credentials=#<Pili::Credentials:0x007fdf939c2238 @access_key="0QxleRjH-IGYystrYdeY5w6KdkSdJVa5SaBUbJkY", @secret_key="Vg3u2240H6JL78sfjsgLohGLjk_jO5e0cdief0g3">,
|
320
|
+
# @id="z1.hub1.55d886b5e3ba571322003121",
|
321
|
+
# @title="55d886b5e3ba571322003121",
|
322
|
+
# @hub="hub1",
|
323
|
+
# @publish_key="new_secret_words",
|
324
|
+
# @publish_security="static",
|
325
|
+
# @disabled=false,
|
326
|
+
# @hosts={
|
327
|
+
# "publish"=>{
|
328
|
+
# "rtmp"=>"eksg7h.publish.z1.pili.qiniup.com"
|
329
|
+
# },
|
330
|
+
# "live"=>{
|
331
|
+
# "http"=>"eksg7h.live1-http.z1.pili.qiniucdn.com",
|
332
|
+
# "rtmp"=>"eksg7h.live1-rtmp.z1.pili.qiniucdn.com"
|
333
|
+
# },
|
334
|
+
# "playback"=>{
|
335
|
+
# "http"=>"eksg7h.playback1.z1.pili.qiniucdn.com"
|
336
|
+
# }
|
337
|
+
# },
|
338
|
+
# @created_at="2015-08-22T14:27:01.62Z",
|
339
|
+
# @updated_at="2015-08-22T14:27:01.62Z"
|
340
|
+
#>
|
139
341
|
```
|
140
342
|
|
141
|
-
|
343
|
+
|
344
|
+
# Get Stream status
|
142
345
|
|
143
346
|
```ruby
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
#
|
347
|
+
begin
|
348
|
+
status_info = stream.status()
|
349
|
+
puts "Stream status() =>\n#{status_info.inspect}\n\n"
|
350
|
+
rescue Exception => e
|
351
|
+
puts "Stream status() failed. Caught exception:\n#{e.http_body}\n\n"
|
352
|
+
end
|
353
|
+
|
354
|
+
#{
|
355
|
+
# "addr"=>"222.73.202.226:2572",
|
356
|
+
# "status"=>"connected",
|
357
|
+
# "bytesPerSecond"=>16870.200000000001,
|
358
|
+
# "framesPerSecond"=>{
|
359
|
+
# "audio"=>42.200000000000003,
|
360
|
+
# "video"=>14.733333333333333,
|
361
|
+
# "data"=>0.066666666666666666
|
362
|
+
# }
|
363
|
+
#}
|
149
364
|
```
|
150
365
|
|
151
|
-
|
366
|
+
|
367
|
+
### Generate RTMP publish URL
|
152
368
|
|
153
369
|
```ruby
|
154
|
-
stream.rtmp_publish_url()
|
155
|
-
|
370
|
+
publish_url = stream.rtmp_publish_url()
|
371
|
+
puts "Stream rtmp_publish_url() =>\n#publish_url}\n\n"
|
372
|
+
|
373
|
+
# "rtmp://eksg7h.publish.z1.pili.qiniup.com/hub1/55d886b5e3ba571322003121?nonce=1440256178&token=ikRpJBxr4qkfRJkAz4dtiaWITAQ="
|
156
374
|
```
|
157
375
|
|
158
|
-
|
376
|
+
|
377
|
+
### Generate RTMP live play URLs
|
159
378
|
|
160
379
|
```ruby
|
161
380
|
urls = stream.rtmp_live_urls()
|
162
|
-
|
381
|
+
puts "Stream rtmp_live_urls() =>\n#{urls.inspect}\n\n"
|
382
|
+
|
163
383
|
# {
|
164
|
-
# "ORIGIN"
|
165
|
-
# "240p" => "rtmp://test.qiniucdn.com/hubname/test@240p",
|
166
|
-
# ...
|
384
|
+
# "ORIGIN"=>"rtmp://eksg7h.live1-rtmp.z1.pili.qiniucdn.com/hub_name/55d886b5e3ba571322003121"
|
167
385
|
# }
|
168
|
-
|
169
|
-
# Get original RTMP live url
|
170
|
-
original_url = urls['ORIGIN']
|
171
386
|
```
|
172
387
|
|
173
|
-
|
388
|
+
|
389
|
+
### Generate HLS live play URLs
|
174
390
|
|
175
391
|
```ruby
|
176
|
-
stream.hls_live_urls()
|
177
|
-
|
392
|
+
urls = stream.hls_live_urls()
|
393
|
+
puts "Stream hls_live_urls() =>\n#{urls.inspect}\n\n"
|
394
|
+
|
178
395
|
# {
|
179
|
-
# "ORIGIN"
|
180
|
-
# "240p" => "http://test.qiniucdn.com/hubname/test@240p.m3u8"
|
181
|
-
# ...
|
396
|
+
# "ORIGIN"=>"http://eksg7h.live1-http.z1.pili.qiniucdn.com/hub1/55d886b5e3ba571322003121.m3u8"
|
182
397
|
# }
|
183
|
-
|
184
|
-
# Get original HLS live url
|
185
|
-
original_url = urls['ORIGIN']
|
186
398
|
```
|
187
399
|
|
188
|
-
|
400
|
+
|
401
|
+
### Generate HTTP-FLV live play URLs
|
189
402
|
|
190
403
|
```ruby
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
# return hls playback urls, eg.
|
404
|
+
urls = stream.http_flv_live_urls()
|
405
|
+
puts "Stream http_flv_live_urls() =>\n#{urls.inspect}\n\n"
|
406
|
+
|
195
407
|
# {
|
196
|
-
# "ORIGIN"
|
197
|
-
# "240p" => "http://test.qiniucdn.com/hubname/test@240p.m3u8?start=1436843430&end=1436846938"
|
198
|
-
# ...
|
408
|
+
# "ORIGIN"=>"http://eksg7h.live1-http.z1.pili.qiniucdn.com/hub1/55d886b5e3ba571322003121.flv"
|
199
409
|
# }
|
410
|
+
```
|
200
411
|
|
201
|
-
|
202
|
-
|
412
|
+
|
413
|
+
### Get Stream segments
|
414
|
+
|
415
|
+
```ruby
|
416
|
+
begin
|
417
|
+
start_time = nil # optional, integer, in second, unix timestamp
|
418
|
+
end_time = nil # optional, integer, in second, unix timestamp
|
419
|
+
limit = nil # optional, uint
|
420
|
+
|
421
|
+
segments = stream.segments(start_time: start_time, end_time: end_time, limit: limit)
|
422
|
+
|
423
|
+
puts "Stream segments() =>\n#{segments.inspect}\n\n"
|
424
|
+
rescue Exception => e
|
425
|
+
puts "Stream segments() failed. Caught exception:\n#{e.http_body}\n\n"
|
426
|
+
end
|
427
|
+
|
428
|
+
# {
|
429
|
+
# "segments":[
|
430
|
+
# {
|
431
|
+
# "start":1440256809,
|
432
|
+
# "end":1440256842
|
433
|
+
# },
|
434
|
+
# {
|
435
|
+
# "start":1440256842,
|
436
|
+
# "end":1440256852
|
437
|
+
# }
|
438
|
+
# ]
|
439
|
+
# }
|
203
440
|
```
|
204
441
|
|
205
|
-
|
442
|
+
|
443
|
+
### Generate HLS playback URLs
|
444
|
+
|
206
445
|
```ruby
|
207
|
-
|
446
|
+
start_time = 1440196065 # required, integer, in second, unix timestamp
|
447
|
+
end_time = 1440196105 # required, integer, in second, unix timestamp
|
448
|
+
urls = stream.hls_playback_urls(start_time, end_time)
|
449
|
+
puts "Stream hls_playback_urls() =>\n#{urls.inspect}\n\n"
|
450
|
+
# {
|
451
|
+
# "ORIGIN"=>"http://eksg7h.playback1.z1.pili.qiniucdn.com/hub1/55d886b5e3ba571322003121.m3u8?start=1440196065&end=1440196105"
|
452
|
+
# }
|
208
453
|
```
|
209
454
|
|
210
|
-
|
455
|
+
|
456
|
+
### Save Stream as a file
|
457
|
+
|
211
458
|
```ruby
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
#
|
217
|
-
|
218
|
-
|
459
|
+
begin
|
460
|
+
name = "videoName.mp4" # required, string
|
461
|
+
format = "mp4" # required, string
|
462
|
+
start_time = 1440067100 # required, int64, in second, unix timestamp
|
463
|
+
end_time = 1440068104 # required, int64, in second, unix timestamp
|
464
|
+
notify_url = nil # optional
|
465
|
+
result = stream.save_as(name, format, start_time, end_time, notify_url)
|
466
|
+
puts "Stream save_as() =>\n#{result.inspect}\n\n"
|
467
|
+
rescue Exception => e
|
468
|
+
puts "Stream save_as() failed. Caught exception:\n#{e.http_body}\n\n"
|
469
|
+
end
|
219
470
|
|
220
|
-
|
471
|
+
# {
|
472
|
+
# "url"=>"http://eksg7h.vod1.z1.pili.qiniucdn.com/recordings/z1.hub1.55d886b5e3ba571322003121/videoName.m3u8",
|
473
|
+
# "targetUrl"=>"http://eksg7h.vod1.z1.pili.qiniucdn.com/recordings/z1.hub1.55d886b5e3ba571322003121/videoName.mp4",
|
474
|
+
# "persistentId"=>"z1.55d894f77823de5a49b52a16"
|
475
|
+
# }
|
476
|
+
```
|
477
|
+
|
478
|
+
While invoking `saveAs()` and `snapshot()`, you can get processing state via Qiniu FOP Service using `persistentId`.
|
479
|
+
API: `curl -D GET http://api.qiniu.com/status/get/prefop?id={PersistentId}`
|
480
|
+
Doc reference: <http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status>
|
481
|
+
|
482
|
+
|
483
|
+
### Snapshot Stream
|
484
|
+
|
485
|
+
```ruby
|
486
|
+
begin
|
487
|
+
name = "imageName.jpg" # required, string
|
488
|
+
format = "jpg" # required, string
|
489
|
+
options = {
|
490
|
+
:time => 1440067100, # optional, int64, in second, unix timestamp
|
491
|
+
:notify_url => nil # optional
|
492
|
+
}
|
493
|
+
result = stream.snapshot(name, format, options)
|
494
|
+
puts "Stream snapshot() =>\n#{result.inspect}\n\n"
|
495
|
+
rescue Exception => e
|
496
|
+
puts "Stream snapshot() failed. Caught exception:\n#{e.http_body}\n\n"
|
497
|
+
end
|
221
498
|
|
222
|
-
# return a dictionary:
|
223
499
|
# {
|
224
|
-
# "
|
225
|
-
# "
|
226
|
-
# "persistentId": <PersistentId>
|
500
|
+
# "targetUrl"=>"http://eksg7h.static1.z1.pili.qiniucdn.com/snapshots/z1.hub1.55d886b5e3ba571322003121/imageName.jpg",
|
501
|
+
# "persistentId"=>"z1.55d8948f7823de5a49b52561"
|
227
502
|
# }
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
503
|
+
```
|
504
|
+
|
505
|
+
|
506
|
+
### Delete a Stream
|
507
|
+
|
508
|
+
```ruby
|
509
|
+
begin
|
510
|
+
result = stream.delete()
|
511
|
+
puts "Stream delete() =>\n#{result.inspect}\n\n"
|
512
|
+
rescue Exception => e
|
513
|
+
puts "Stream delete() failed. Caught exception:\n#{e.http_body}\n\n"
|
514
|
+
end
|
515
|
+
|
516
|
+
# nil
|
232
517
|
```
|
233
518
|
|
234
519
|
|
235
520
|
## History
|
521
|
+
|
522
|
+
- 1.5.0
|
523
|
+
- Add stream.http_flv_live_urls()
|
524
|
+
- Add stream.disable()
|
525
|
+
- Add stream.enable()
|
526
|
+
- Add stream.snapshot()
|
236
527
|
- 1.3.0
|
237
|
-
- Add stream
|
528
|
+
- Add stream.saveas()
|
238
529
|
- 1.2.0
|
239
530
|
- Add Client, Stream class
|
240
531
|
- 1.0.1
|
241
|
-
- Add
|
242
|
-
- Update
|
532
|
+
- Add stream.status()
|
533
|
+
- Update stream.update()
|
243
534
|
- 1.0.0
|
244
535
|
- Update README create stream example code.
|
245
536
|
- 0.1.3
|
@@ -252,4 +543,4 @@ stream.save_as(name, format, start_time, end_time, options)
|
|
252
543
|
- 0.0.1
|
253
544
|
- Init SDK
|
254
545
|
- Add Stream API
|
255
|
-
- Add publish and play policy
|
546
|
+
- Add publish and play policy
|