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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9865e9866575afe5e7d4237d81e632fd7000a919
4
- data.tar.gz: e9c96dd71f418ce1d5d5b4fc71610b00210a0833
3
+ metadata.gz: 23353fd81b87b9123d66b1ae43ff0bcab17a1394
4
+ data.tar.gz: 26c4b2efa6956cf2807c7980e41d109aca547a89
5
5
  SHA512:
6
- metadata.gz: 53caacf8ab81601fe91c5e710b78e0da2757f362d75ab4c02296f4568b0ff12da9ef9b6da9b9301450bdead75c06ed13d4543fecdded02cded17227db36914d7
7
- data.tar.gz: 99f70ed7c9180b8c3c38bd6dbf6ed1c2c747b803f9753f450dc3279bb322f6a65bd0129e20031c2be85b9233723d5be4097110e66ceea5307ba0dc86fae4b4ba
6
+ metadata.gz: 821ade8cbfb8aa4b98238d67d7dec341dded6825a6a522a46bb59032e93d64b7f07466eee0480477211fbfda1672daf50127d7c45114df5afe9bbfb3d40c703e
7
+ data.tar.gz: afb135beccd5561a2919d0da9887fffa9b7fe6eae1278d181f65ca55f97438c6ac1322a9c534411a265193b282a71b6fd3197892c197466d170dab6a75bf5ccf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pili (0.0.1)
4
+ pili (1.5.0)
5
5
  httparty (~> 0.13.3)
6
6
 
7
7
  GEM
@@ -10,7 +10,7 @@ GEM
10
10
  httparty (0.13.3)
11
11
  json (~> 1.8)
12
12
  multi_xml (>= 0.5.2)
13
- json (1.8.2)
13
+ json (1.8.3)
14
14
  multi_xml (0.5.5)
15
15
  rake (10.4.2)
16
16
 
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
- - [x] Stream operations (Create, Delete, Update, Get)
6
- - [x] Get Streams list
7
- - [x] Get Stream status
8
- - [x] Get Stream segments
9
- - [x] Generate RTMP publish URL
10
- - [x] Generate RTMP / HLS live play URL
11
- - [x] Generate HLS playback URL
12
-
13
- ## Content
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
- - [Client](#client)
19
- - [Create a Pili client](#create-a-pili-client)
20
- - [Create a stream](#create-a-stream)
21
- - [Get a stream](#get-a-stream)
22
- - [List streams](#list-streams)
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
- - [Update a stream](#update-a-stream)
25
- - [Delete a stream](#delete-a-stream)
26
- - [Get stream segments](#get-stream-segments)
27
- - [Get stream status](#get-stream-status)
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
- - [To JSON String](#to-json-string)
33
- - [Save Stream as](#save-stream-as)
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 = 'qiniu_access_key'
59
- SECRETE_KEY = 'qiniu_secret_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
- HUB_NAME = 'hub_name'
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
- #### Create a Pili client
85
+ ## Hub
67
86
 
87
+ ### Instantiate a Pili Hub object
68
88
  ```ruby
69
- client = Pili::Client.new(ACCESS_KEY, SECRETE_KEY, HUB_NAME)
70
- # return client object...
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
- #### Create a stream
94
+
95
+ ### Create a new Stream
74
96
 
75
97
  ```ruby
76
- # title: optional, default is auto-generated
77
- # publish_key: optional, a secret key for signing the <publishToken>
78
- # publish_security: optional, can be "dynamic" or "static", default is "dynamic"
79
- client.create_stream()
80
- # or
81
- client.create_stream(title: "title", publish_key: "publish_key", publish_security: "static")
82
- # return stream object...
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
- #### Get a stream
137
+
138
+ ### Get a Stream
86
139
 
87
140
  ```ruby
88
- # stream_id: string, required
89
- client.get_stream(stream_id)
90
- # return stream object...
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
- #### List streams
173
+
174
+ ### List Streams
94
175
 
95
176
  ```ruby
96
- # marker: string, optional
97
- # limit: integer, optional
98
- client.list_streams(marker: "marker", limit: 1000)
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
- #### Update a stream
202
+ ## Stream
203
+
204
+ ### To JSON String
104
205
 
105
206
  ```ruby
106
- # publish_key: optional, a secret key for signing the <publishToken>
107
- # publish_security: optional, can be "dynamic" or "static", default is "dynamic"
108
- # disabled: optional, can be true or false
109
- stream.update(publish_key: "new_key", publish_security: "dynamic", disabled: true)
110
- # return updated stream object...
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
- #### Delete a stream
234
+ ### Update a Stream
114
235
 
115
236
  ```ruby
116
- stream.delete()
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
- #### Get stream segments
272
+ ### Disable a Stream
120
273
 
121
274
  ```ruby
122
- # start_time: optional, integer, in second, unix timestamp
123
- # end_time: optional, integer, in second, unix timestamp
124
- stream.segments()
125
- # or
126
- stream.segments(start_time, end_time)
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
- # "start": <StartSecond>,
131
- # "end": <EndSecond>
132
- # },
133
- # {
134
- # "start": <StartSecond>,
135
- # "end": <EndSecond>
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
- #### Get stream status
343
+
344
+ # Get Stream status
142
345
 
143
346
  ```ruby
144
- stream.status()
145
- # {
146
- # "addr": "106.187.43.211:51393",
147
- # "status": "disconnected"
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
- #### Generate RTMP publish URL
366
+
367
+ ### Generate RTMP publish URL
152
368
 
153
369
  ```ruby
154
- stream.rtmp_publish_url()
155
- # return a rtmp publish url, eg. "rtmp://test.qiniucdn.com/hubname/test?key=publish_test_key"
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
- #### Generate RTMP live play URLs
376
+
377
+ ### Generate RTMP live play URLs
159
378
 
160
379
  ```ruby
161
380
  urls = stream.rtmp_live_urls()
162
- # return rtmp live play urls, eg.
381
+ puts "Stream rtmp_live_urls() =>\n#{urls.inspect}\n\n"
382
+
163
383
  # {
164
- # "ORIGIN" => "rtmp://test.qiniucdn.com/hubname/test",
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
- #### Generate HLS live play URLs
388
+
389
+ ### Generate HLS live play URLs
174
390
 
175
391
  ```ruby
176
- stream.hls_live_urls()
177
- # return hls live play urls, eg.
392
+ urls = stream.hls_live_urls()
393
+ puts "Stream hls_live_urls() =>\n#{urls.inspect}\n\n"
394
+
178
395
  # {
179
- # "ORIGIN" => "http://test.qiniucdn.com/hubname/test.m3u8",
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
- #### Generate HLS playback URLs
400
+
401
+ ### Generate HTTP-FLV live play URLs
189
402
 
190
403
  ```ruby
191
- # start_time: optional, integer, in second, unix timestamp
192
- # end_time: optional, integer, in second, unix timestamp
193
- stream.hls_playback_urls(start_time, end_time)
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" => "http://test.qiniucdn.com/hubname/test.m3u8?start=1436843430&end=1436846938",
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
- # Get original HLS playback url
202
- original_url = urls['ORIGIN']
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
- #### To JSON String
442
+
443
+ ### Generate HLS playback URLs
444
+
206
445
  ```ruby
207
- stream.to_json()
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
- #### Save Stream as
455
+
456
+ ### Save Stream as a file
457
+
211
458
  ```ruby
212
- # name = "fileName" # required, string
213
- # format = "mp4" # required, string
214
- # start_time = 1439121809 # required, int64, in second, unix timestamp
215
- # end_time = 1439125409 # required, int64, in second, unix timestamp
216
- # options = {
217
- # :notify_url => "http://remote_callback_url"
218
- # } #optional
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
- stream.save_as(name, format, start_time, end_time, options)
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
- # "url": "<m3u8Url>",
225
- # "targetUrl": "<TargetFileUrl>",
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
- # You can get saving state via Qiniu fop service using persistentId.
230
- # API: `curl -D GET http://api.qiniu.com/status/get/prefop?id=<PersistentId>`
231
- # Doc reference: `http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status`
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 saveas function
528
+ - Add stream.saveas()
238
529
  - 1.2.0
239
530
  - Add Client, Stream class
240
531
  - 1.0.1
241
- - Add get stream status method.
242
- - Update update_stream method.
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