piliv2 2.0.3 → 2.1.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: 2643209525e556871da60fe435a569d00c23f03b
4
- data.tar.gz: fb958350192aa3591012600b169dc293e0dcca7a
3
+ metadata.gz: e29f840b9bfc8601baef9f0eeb269f749f44bf9b
4
+ data.tar.gz: 11edb606403b266ab39019f8d333e5c9bfa930d1
5
5
  SHA512:
6
- metadata.gz: dfe92138ee5ca7725c62ed93b322010bf01c5c96c3a17295e19d24fc529a14b77748bf0b4fc022b973631075e33fe6e4932ecacc0f69adc9c7c328d7630dea83
7
- data.tar.gz: cbf120c03cc122ae563d24b4dc878639745450d5a4ed5f502163d91627cf864fddb37342ba639bebd5fb57c038ef322f8f56f9b7cb0479335d836ae32a923a7d
6
+ metadata.gz: 94f7c701a0cb574b2d6416de406c000101463dbaa30d84e173a1eba0342f6eb75c30c71d805e99f66ea81fcd9a2357671138bfc25a673effe7c756d6bc20e087
7
+ data.tar.gz: f2b9006641bd119ef7ece200293e9c64c1ef368e67590f86b42d4bd102ca635bb33e14da5e64548ea7d2e7611544105a2fbb9d656e0dd1ccb11cb82218d14479
@@ -1,5 +1,12 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v2.1.0
4
+ [#35](https://github.com/pili-engineering/pili-sdk-ruby/pull/35)
5
+ - 增加批量查询直播信息接口
6
+ - 回放保存增加更多的配置项
7
+ - 增加保存截图接口
8
+ - 增加更改流转码规格接口
9
+
3
10
  ### v2.0.3
4
11
 
5
12
  - 修复 README 错误和修改 `RPCError` 继承自 `RuntimeError`。[#33](https://github.com/pili-engineering/pili-sdk-ruby/pull/33)
data/README.md CHANGED
@@ -3,22 +3,26 @@
3
3
  ## Features
4
4
 
5
5
  - URL
6
- - [x] RTMP推流地址: rtmp_publish_url(domain, hub, stream_key, mac, expire_after_seconds)
7
- - [x] RTMP直播地址: rtmp_play_url(domain, hub, stream_key)
8
- - [x] HLS直播地址: hls_play_url(domain, hub, stream_key)
9
- - [x] HDL直播地址: hdl_play_url(domain, hub, stream_key)
10
- - [x] 截图直播地址: snapshot_play_url(domain, hub, stream_key)
6
+ - [x] RTMP推流地址: rtmp_publish_url(domain, hub, stream_title, mac, expire_after_seconds)
7
+ - [x] RTMP直播地址: rtmp_play_url(domain, hub, stream_title)
8
+ - [x] HLS直播地址: hls_play_url(domain, hub, stream_title)
9
+ - [x] HDL直播地址: hdl_play_url(domain, hub, stream_title)
10
+ - [x] 直播封面地址: snapshot_play_url(domain, hub, stream_title)
11
11
  - Hub
12
- - [x] 创建流: hub.create(stream_key)
13
- - [x] 获得流: hub.stream(stream_key)
12
+ - [x] 创建流: hub.create(stream_title)
13
+ - [x] 获得流: hub.stream(stream_title)
14
14
  - [x] 列出流: hub.list(...)
15
15
  - [x] 列出正在直播的流: hub.list_live(...)
16
+ - [x] 批量查询直播信息: hub.batch_query_live_status(stream_titles)
16
17
  - Stream
17
18
  - [x] 流信息: stream.info()
18
- - [x] 禁用流: stream.disable()
19
+ - [x] 无限期禁用流: stream.disable()
20
+ - [x] 禁用流: stream.disable_till(timestamp)
19
21
  - [x] 启用流: stream.enable()
20
22
  - [x] 查询直播状态: stream.live_status()
21
- - [x] 保存直播回放: stream.save(...)
23
+ - [x] 保存直播回放: stream.saveas(...)
24
+ - [x] 保存直播截图: stream.snapshot(...)
25
+ - [x] 更改流的实时转码规格: stream.update_converts(profiles)
22
26
  - [x] 查询直播历史: stream.history_activity(...)
23
27
 
24
28
  ## Contents
@@ -38,13 +42,17 @@
38
42
  - [Get a Stream](#get-a-stream)
39
43
  - [List Streams](#list-streams)
40
44
  - [List live Streams](#list-live-streams)
45
+ - [Batch query live status](#batch-query-live-status)
41
46
  - [Stream](#stream)
42
47
  - [Get Stream info](#get-stream-info)
43
48
  - [Disable a Stream](#disable-a-stream)
49
+ - [Disable a Stream with timestamp](#disable-a-stream-with-timestamp)
44
50
  - [Enable a Stream](#enable-a-stream)
45
51
  - [Get Stream live status](#get-stream-live-status)
46
- - [Get Stream history activity](#get-stream-history-activity)
47
52
  - [Save Stream live playback](#save-stream-live-playback)
53
+ - [Save Stream snapshot](#save-stream-snapshot)
54
+ - [Update converts](#update-converts)
55
+ - [Get Stream history activity](#get-stream-history-activity)
48
56
 
49
57
  ## Installation
50
58
 
@@ -82,41 +90,41 @@ hub = client.hub(hub_name)
82
90
  #### Generate RTMP publish URL
83
91
 
84
92
  ```ruby
85
- url = Pili.rtmp_publish_url("publish-rtmp.test.com", "PiliSDKTest", "streamkey", mac, 60)
93
+ url = Pili.rtmp_publish_url("publish-rtmp.test.com", "PiliSDKTest", "streamtitle", mac, 60)
86
94
  puts(url)
87
- # rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
95
+ # rtmp://publish-rtmp.test.com/PiliSDKTest/streamtitle?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
88
96
  ```
89
97
 
90
98
  #### Generate RTMP play URL
91
99
 
92
100
  ```ruby
93
- url = Pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamkey")
101
+ url = Pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamtitle")
94
102
  puts(url)
95
- # rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
103
+ # rtmp://live-rtmp.test.com/PiliSDKTest/streamtitle
96
104
  ```
97
105
 
98
106
  #### Generate HLS play URL
99
107
 
100
108
  ```ruby
101
- url = Pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamkey")
109
+ url = Pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamtitle")
102
110
  puts(url)
103
- # http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
111
+ # http://live-hls.test.com/PiliSDKTest/streamtitle.m3u8
104
112
  ```
105
113
 
106
114
  #### Generate HDL play URL
107
115
 
108
116
  ```ruby
109
- url = Pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamkey")
117
+ url = Pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamtitle")
110
118
  puts(url)
111
- # http://live-hdl.test.com/PiliSDKTest/streamkey.flv
119
+ # http://live-hdl.test.com/PiliSDKTest/streamtitle.flv
112
120
  ```
113
121
 
114
122
  #### Generate Snapshot play URL
115
123
 
116
124
  ```ruby
117
- url = Pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamkey")
125
+ url = Pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamtitle")
118
126
  puts(url)
119
- # http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
127
+ # http://live-snapshot.test.com/PiliSDKTest/streamtitle.jpg
120
128
  ```
121
129
 
122
130
  ### Hub
@@ -132,33 +140,42 @@ hub = client.hub("PiliSDKTest")
132
140
  #### Create a new Stream
133
141
 
134
142
  ```ruby
135
- stream = hub.create("streamkey")
143
+ stream = hub.create("streamtitle")
136
144
  puts(stream.info.to_json)
137
- # {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
145
+ # {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
138
146
  ```
139
147
 
140
148
  #### Get a Stream
141
149
 
142
150
  ```ruby
143
- stream = hub.stream("streamkey")
151
+ stream = hub.stream("streamtitle")
144
152
  puts(stream.info.to_json)
145
- # {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
153
+ # {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
146
154
  ```
147
155
 
148
156
  #### List Streams
149
157
 
150
158
  ```ruby
151
- keys, marker = hub.list(:prefix=>"str", :limit=>10)
152
- puts keys.to_s, marker
153
- # [<keys...>], <marker>
159
+ titles, marker = hub.list(:prefix=>"str", :limit=>10)
160
+ puts titles.to_s, marker
161
+ # [<titles...>], <marker>
154
162
  ```
155
163
 
156
164
  #### List live Streams
157
165
 
158
166
  ```ruby
159
- keys, marker = hub.list_live(:prefix=>"str", :limit=>10)
160
- puts keys.to_s, marker
161
- # [<keys...>], <marker>
167
+ titles, marker = hub.list_live(:prefix=>"str", :limit=>10)
168
+ puts titles.to_s, marker
169
+ # [<titles...>], <marker>
170
+ ```
171
+
172
+ #### Batch query live status
173
+
174
+ ```ruby
175
+ live_statuses = hub.batch_query_live_status(["stream1", "stream2"])
176
+ puts live_statuses
177
+ # {"startAt"=>1488798455, "clientIP"=>"119.130.107.231:35018", "bps"=>921960, "fps"=>{"audio"=>44, "video"=>29, "data"=>0}, "key"=>"stream1"}
178
+ # {"startAt"=>1488798287, "clientIP"=>"119.130.107.231:55924", "bps"=>867328, "fps"=>{"audio"=>42, "video"=>9, "data"=>0}, "key"=>"stream2"}
162
179
  ```
163
180
 
164
181
  ### Stream
@@ -166,37 +183,56 @@ puts keys.to_s, marker
166
183
  #### Get Stream info
167
184
 
168
185
  ```ruby
169
- stream = hub.stream(key)
186
+ stream = hub.stream(title)
170
187
  puts(stream.info.to_json)
171
- # {"hub": "PiliSDKTest", "key": "streamkey", "disabled": false}
188
+ # {"hub": "PiliSDKTest", "key": "streamtitle", "disabled": false}
172
189
  ```
173
190
 
174
191
  #### Disable a Stream
175
192
 
176
193
  ```ruby
177
- stream = hub.stream("streamkey")
194
+ stream = hub.stream("streamtitle")
178
195
  puts("before disable: #{stream.info.to_json}")
179
196
 
180
197
  stream.disable()
181
198
 
182
- stream = hub.stream("streamkey")
199
+ stream = hub.stream("streamtitle")
183
200
  puts("after disable: #{stream.info.to_json}")
184
- # before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
185
- # after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}
201
+ # before disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
202
+ # after disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":true}
203
+ ```
204
+
205
+ #### Disable a Stream with timestamp
206
+
207
+ ```ruby
208
+ stream = hub.stream("streamtitle")
209
+ puts("before disable: #{stream.info.to_json}")
210
+
211
+ stream.disable_till(Time.now.to_i + 10)
212
+
213
+ puts("after disable: #{stream.info.to_json}")
214
+
215
+ sleep(10)
216
+
217
+ puts("after 10 seconds: #{stream.info.to_json}")
218
+
219
+ # before disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
220
+ # after disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":true}
221
+ # before 10 seconds: {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
186
222
  ```
187
223
 
188
224
  #### Enable a Stream
189
225
 
190
226
  ```ruby
191
- stream = hub.stream("streamkey")
227
+ stream = hub.stream("streamtitle")
192
228
  puts("before enable: #{stream.info.to_json}")
193
229
 
194
230
  stream.enable()
195
231
 
196
- stream = hub.get("streamkey")
232
+ stream = hub.get("streamtitle")
197
233
  puts("after enable: #{stream.info.to_json}")
198
- # before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}
199
- # after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
234
+ # before disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":true}
235
+ # after disable: {"hub":"PiliSDKTest","key":"streamtitle","disabled":false}
200
236
  ```
201
237
 
202
238
  #### Get Stream live status
@@ -207,18 +243,36 @@ puts(status.to_json)
207
243
  # {"startAt":1463022236,"clientIP":"222.73.202.226","bps":248,"fps":{"audio":45,"vedio":28,"data":0}}
208
244
  ```
209
245
 
210
- #### Get Stream history activity
246
+ #### Save Stream live playback
211
247
 
212
248
  ```ruby
213
- activity = stream.history_activity()
214
- puts(activity.to_json)
215
- # [{"start":1463022236,"end":1463022518}]
249
+ fname, persistentID = stream.saveas(:format => "mp4")
250
+ puts(fname, persistentID)
251
+ # recordings/z1.PiliSDKTest.streamtitle/1463156847_1463157463.mp4
252
+ # z1.58bd753a8a3c0c3794a1d6ff
253
+ ```
254
+ #### Save Stream snapshot
255
+ ```ruby
256
+ fname = stream.snapshot()
257
+ puts(fname)
258
+ # stream-title-4532162526321415963.jpg
216
259
  ```
217
260
 
218
- #### Save Stream live playback
261
+ #### Update converts
219
262
 
220
263
  ```ruby
221
- fname = stream.save()
222
- puts(fname)
223
- # recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8
264
+ stream = hub.stream("streamtitle")
265
+ puts stream.info.to_json
266
+ stream.update_converts(["720p", "480p"])
267
+ puts stream.info.to_json
268
+ # {"hub":"PiliSDKTest","key":"streamtitle","disabled":false,"converts":[]}
269
+ # {"hub":"PiliSDKTest","key":"streamtitle","disabled":false,"converts":["720p","480p"]}
224
270
  ```
271
+
272
+ #### Get Stream history activity
273
+
274
+ ```ruby
275
+ activity = stream.history_activity()
276
+ puts(activity.to_json)
277
+ # [{"start":1463022236,"end":1463022518}]
278
+ ```
@@ -10,7 +10,7 @@ if access_key == nil || secret_key == nil
10
10
  end
11
11
 
12
12
  srand
13
- stream_key_prefix = "ruby-sdkexample-#{rand 1000000000}"
13
+ stream_title_prefix = "ruby-sdkexample-#{rand 1000000000}"
14
14
 
15
15
  puts "初始化 client."
16
16
  mac = Pili::Mac.new access_key, secret_key
@@ -18,50 +18,54 @@ client = Pili::Client.new mac
18
18
  hub = client.hub hub_name
19
19
 
20
20
  puts "获得不存在的流."
21
- key_a = stream_key_prefix + "-a"
21
+ title_a = stream_title_prefix + "-a"
22
22
  begin
23
- stream_a = hub.stream key_a
23
+ stream_a = hub.stream title_a
24
24
  stream_a.info
25
25
  rescue Pili::ResourceNotExist => e
26
26
  puts e
27
27
  end
28
28
 
29
29
  puts "创建流."
30
- stream_a = hub.create(key_a)
30
+ stream_a = hub.create(title_a)
31
31
  puts stream_a.info
32
32
 
33
33
  puts "获得流."
34
- stream_a = hub.stream(key_a)
34
+ stream_a = hub.stream(title_a)
35
35
  puts "to_json: #{stream_a.info.to_json}"
36
36
 
37
37
  puts "创建重复的流."
38
38
  begin
39
- hub.create(key_a)
39
+ hub.create(title_a)
40
40
  rescue Pili::ResourceConflict => e
41
41
  puts e
42
42
  end
43
43
 
44
44
  puts "创建另一路流."
45
- key_b = stream_key_prefix + "-b"
46
- stream_b = hub.create(key_b)
45
+ title_b = stream_title_prefix + "-b"
46
+ stream_b = hub.create(title_b)
47
47
  puts stream_b.info
48
48
 
49
49
  puts "列出所有流."
50
50
  begin
51
- keys, marker = hub.list(:prefix=>stream_key_prefix)
52
- puts keys.to_s, marker
51
+ titles, marker = hub.list(:prefix=>stream_title_prefix)
52
+ puts titles.to_s, marker
53
53
  rescue Pili::ResourceNotExist => e
54
54
  puts e
55
55
  end
56
56
 
57
57
  puts "列出正在直播的流."
58
58
  begin
59
- keys, marker = hub.list_live(:prefix=>stream_key_prefix)
60
- puts keys.to_s, marker
59
+ titles, marker = hub.list_live(:prefix=>stream_title_prefix)
60
+ puts titles.to_s, marker
61
61
  rescue Pili::ResourceNotExist => e
62
62
  puts e
63
63
  end
64
64
 
65
+ puts "批量查询直播信息."
66
+ live_statuses = hub.batch_query_live_status([title_a, title_b])
67
+ puts live_statuses
68
+
65
69
  puts "禁用流."
66
70
  stream_a.disable()
67
71
  puts stream_a.info
@@ -70,42 +74,70 @@ puts "启用流."
70
74
  stream_a.enable()
71
75
  puts stream_a.info
72
76
 
77
+ puts "禁用流 10 秒"
78
+ begin
79
+ puts("before disable: #{stream_a.info.to_json}")
80
+ stream_a.disable_till(Time.now.to_i + 10)
81
+ puts("after disable: #{stream_a.info.to_json}")
82
+ sleep(10)
83
+ puts("after 10 seconds: #{stream_a.info.to_json}")
84
+ rescue Pili::ResourceNotExist => e
85
+ puts e
86
+ end
87
+
73
88
  puts "查询直播状态."
74
89
  begin
75
90
  status = stream_a.live_status()
76
- puts keys, marker
91
+ puts status
77
92
  rescue Pili::ResourceNotExist => e
78
93
  puts e
79
94
  end
80
95
 
96
+ puts "更改流的实时转码规格"
97
+ begin
98
+ puts stream_a.info.to_json
99
+ stream_a.update_converts(["720p", "480p"])
100
+ puts stream_a.info.to_json
101
+ rescue => e
102
+ puts e
103
+ end
104
+
81
105
  puts "查询推流历史."
82
106
  activity = stream_a.history_activity()
83
107
  puts activity
84
108
 
85
109
  puts "保存直播数据."
86
110
  begin
87
- fname = stream_a.save()
88
- puts fname
111
+ fname, persistentID = stream_a.saveas(:format => "mp4")
112
+ puts fname, persistentID
113
+ rescue => e
114
+ puts e
115
+ end
116
+
117
+ puts "保存直播截图."
118
+ begin
119
+ fname = stream_a.snapshot()
120
+ puts(fname)
89
121
  rescue => e
90
122
  puts e
91
123
  end
92
124
 
93
125
  puts "RTMP 推流地址."
94
- url = Pili.rtmp_publish_url("publish-rtmp.test.com", hub_name, key_a, mac, 3600)
126
+ url = Pili.rtmp_publish_url("publish-rtmp.test.com", hub_name, title_a, mac, 3600)
95
127
  puts url
96
128
 
97
129
  puts "RTMP 直播放址."
98
- url = Pili.rtmp_play_url("live-rtmp.test.com", hub_name, key_a)
130
+ url = Pili.rtmp_play_url("live-rtmp.test.com", hub_name, title_a)
99
131
  puts url
100
132
 
101
133
  puts "HLS 直播地址."
102
- url = Pili.hls_play_url("live-hls.test.com", hub_name, key_a)
134
+ url = Pili.hls_play_url("live-hls.test.com", hub_name, title_a)
103
135
  puts url
104
136
 
105
137
  puts "HDL 直播地址."
106
- url = Pili.hdl_play_url("live-hdl.test.com", hub_name, key_a)
138
+ url = Pili.hdl_play_url("live-hdl.test.com", hub_name, title_a)
107
139
  puts url
108
140
 
109
141
  puts "截图直播地址"
110
- url = Pili.snapshot_play_url("live-snapshot.test.com", hub_name, key_a)
142
+ url = Pili.snapshot_play_url("live-snapshot.test.com", hub_name, title_a)
111
143
  puts url
@@ -18,31 +18,31 @@ module Pili
18
18
  class << self
19
19
  # 生成 RTMP 推流地址.
20
20
  # +expire_after_seconds+ 表示 URL 在多久之后失效.
21
- def rtmp_publish_url(domain, hub, stream_key, mac, expire_after_seconds)
21
+ def rtmp_publish_url(domain, hub, stream_title, mac, expire_after_seconds)
22
22
  expire = Time.new.to_i + expire_after_seconds
23
- path = "/#{hub}/#{stream_key}?e=#{expire}"
23
+ path = "/#{hub}/#{stream_title}?e=#{expire}"
24
24
  token = mac.sign(path)
25
25
  "rtmp://#{domain}#{path}&token=#{token}"
26
26
  end
27
27
 
28
28
  # 生成 RTMP 直播地址.
29
- def rtmp_play_url(domain, hub, stream_key)
30
- "rtmp://#{domain}/#{hub}/#{stream_key}"
29
+ def rtmp_play_url(domain, hub, stream_title)
30
+ "rtmp://#{domain}/#{hub}/#{stream_title}"
31
31
  end
32
32
 
33
33
  # 生成 HLS 直播地址.
34
- def hls_play_url(domain, hub, stream_key)
35
- "http://#{domain}/#{hub}/#{stream_key}.m3u8"
34
+ def hls_play_url(domain, hub, stream_title)
35
+ "http://#{domain}/#{hub}/#{stream_title}.m3u8"
36
36
  end
37
37
 
38
38
  # 生成 HDL 直播地址.
39
- def hdl_play_url(domain, hub, stream_key)
40
- "http://#{domain}/#{hub}/#{stream_key}.flv"
39
+ def hdl_play_url(domain, hub, stream_title)
40
+ "http://#{domain}/#{hub}/#{stream_title}.flv"
41
41
  end
42
42
 
43
43
  # 生成截图直播地址.
44
- def snapshot_play_url(domain, hub, stream_key)
45
- "http://#{domain}/#{hub}/#{stream_key}.jpg"
44
+ def snapshot_play_url(domain, hub, stream_title)
45
+ "http://#{domain}/#{hub}/#{stream_title}.jpg"
46
46
  end
47
47
  end
48
48
  end
@@ -14,14 +14,14 @@ module Pili
14
14
  # 创建一个流对象.
15
15
  # 使用一个合法 rtmp_publish_url 发起推流就会自动创建流对象.
16
16
  # 一般情况下不需要调用这个 API, 除非是想提前对这一个流做一些特殊配置.
17
- def create(stream_key)
18
- @client.rpc.call_with_json("POST", "#{@base_url}/streams", {:key => stream_key})
19
- Stream.new(@hub, stream_key, @client)
17
+ def create(stream_title)
18
+ @client.rpc.call_with_json("POST", "#{@base_url}/streams", {:key => stream_title})
19
+ Stream.new(@hub, stream_title, @client)
20
20
  end
21
21
 
22
22
  # 初始化一个流对象.
23
- def stream(stream_key)
24
- Stream.new(@hub, stream_key, @client)
23
+ def stream(stream_title)
24
+ Stream.new(@hub, stream_title, @client)
25
25
  end
26
26
 
27
27
  def plist(opt = {})
@@ -47,8 +47,8 @@ module Pili
47
47
  #
48
48
  # marker = ""
49
49
  # while true
50
- # keys, marker = hub.list(:marker=> marker)
51
- # # do something with keys.
50
+ # titles, marker = hub.list(:marker=> marker)
51
+ # # do something with titles.
52
52
  # if marker == ""
53
53
  # break
54
54
  # end
@@ -70,8 +70,8 @@ module Pili
70
70
  #
71
71
  # marker = ""
72
72
  # while true
73
- # keys, marker = hub.list_live(:marker=> marker)
74
- # # do something with keys.
73
+ # titles, marker = hub.list_live(:marker=> marker)
74
+ # # do something with titles.
75
75
  # if marker == ""
76
76
  # break
77
77
  # end
@@ -80,6 +80,34 @@ module Pili
80
80
  opt[:liveonly] = true
81
81
  plist(opt)
82
82
  end
83
+
84
+ # 批量查询直播实时信息
85
+ #
86
+ # 参数:
87
+ #
88
+ # stream_titles 字符串数组,其中元素是想要查询的流的标题。
89
+ #
90
+ # 返回:
91
+ #
92
+ # {
93
+ # "key" => <String>, # 流标题
94
+ # "startAt" => <Integer>, # 直播开始的 Unix 时间戳, 0 表示当前没在直播.
95
+ # "clientIp" => <String>, # 直播的客户端 IP.
96
+ # "bps" => <Integer>, # 直播的码率、帧率信息.
97
+ # "fps" => {
98
+ # "audio" => <Integer>,
99
+ # "video" => <Integer>,
100
+ # "data" => <Integer>
101
+ # }
102
+ # }
103
+ #
104
+ # 注意:
105
+ #
106
+ # 查询的流不存在或不在直播不会出现在返回结果里。
107
+ def batch_query_live_status(stream_titles)
108
+ ret = @client.rpc.call_with_json("POST", "#{@base_url}/livestreams", {:items=>stream_titles})
109
+ ret["items"]
110
+ end
83
111
 
84
112
  def to_s
85
113
  "#<#{self.class} #{@hub}>"
@@ -4,15 +4,19 @@ require "base64"
4
4
 
5
5
  module Pili
6
6
  class StreamInfo
7
- attr_reader :hub, :key
7
+ attr_reader :hub, :title
8
8
 
9
9
  # 表示禁用结束的时间, 0 表示不禁用, -1 表示永久禁用.
10
10
  attr_reader :disabled_till
11
+
12
+ # 流转码配置数组
13
+ attr_reader :converts
11
14
 
12
- def initialize(hub, key, disabled_till)
15
+ def initialize(hub, title, disabled_till, converts)
13
16
  @hub = hub
14
- @key = key
17
+ @title = title
15
18
  @disabled_till = disabled_till
19
+ @converts = converts
16
20
  end
17
21
 
18
22
  def disabled?
@@ -20,22 +24,22 @@ module Pili
20
24
  end
21
25
 
22
26
  def to_s
23
- "#<#{self.class} #{@hub}/#{@key} disabled:#{disabled?}>"
27
+ "#<#{self.class} #{@hub}/#{@title} disabled:#{disabled?} converts:#{@converts}>"
24
28
  end
25
29
 
26
30
  def to_json
27
- {:hub=>@hub, :key=>@key, :disabled=>disabled?}.to_json
31
+ {:hub=>@hub, :key=>@title, :disabled=>disabled?, :converts=>@converts}.to_json
28
32
  end
29
33
  end
30
34
 
31
35
  class Stream
32
- attr_reader :hub, :key
36
+ attr_reader :hub, :title
33
37
 
34
- def initialize(hub, key, client)
38
+ def initialize(hub, title, client)
35
39
  @hub = hub
36
- @key = key
40
+ @title = title
37
41
 
38
- ekey = Base64.urlsafe_encode64(key)
42
+ ekey = Base64.urlsafe_encode64(title)
39
43
  @base_url = "#{Config.api_base_url}/hubs/#{hub}/streams/#{ekey}"
40
44
 
41
45
  @client = client
@@ -44,12 +48,19 @@ module Pili
44
48
  # Info 获得流信息.
45
49
  def info
46
50
  ret = @client.rpc.call_with_json("GET", @base_url, nil)
47
- StreamInfo.new @hub, @key, ret["disabledTill"]
51
+ StreamInfo.new @hub, @title, ret["disabledTill"], ret["converts"]
48
52
  end
49
53
 
50
- # 禁用一个流.
54
+ # 无限期禁用一个流.
51
55
  def disable
52
- @client.rpc.call_with_json("POST", "#{@base_url}/disabled", {:disabledTill=>-1})
56
+ disable_till(-1)
57
+ end
58
+
59
+ # 禁用一个流.
60
+ # 参数:
61
+ # timestamp 解除禁用的时间戳
62
+ def disable_till(timestamp)
63
+ @client.rpc.call_with_json("POST", "#{@base_url}/disabled", {:disabledTill=>timestamp})
53
64
  end
54
65
 
55
66
  # 启用一个流.
@@ -77,13 +88,45 @@ module Pili
77
88
 
78
89
  # 保存直播回放.
79
90
  #
80
- # 参数: start, end 是 Unix 时间戳, 限定了保存的直播的时间范围, 0 值表示不限定, 系统会默认保存最近一次直播的内容.
81
- #
82
- # 返回保存的文件名, 由系统生成.
83
- def save(opt = {})
91
+ # 参数:
92
+ # fname: 保存到存储空间的文件名,可选,不指定系统会随机生成
93
+ # start: 整数,可选,Unix 时间戳,要保存的直播的起始时间,不指定或 0 值表示从第一次直播开始
94
+ # end: 整数,可选,Unix 时间戳,要保存的直播的结束时间,不指定或 0 值表示当前时间
95
+ # format: 保存的文件格式,可选,默认为m3u8,如果指定其他格式,则保存动作为异步模式
96
+ # pipeline: 异步模式时,dora的私有队列,可选,不指定则使用公共队列
97
+ # notify: 异步模式时,保存成功回调通知地址,可选,不指定则不通知
98
+ # expireDays: 更改ts文件的过期时间,可选,默认为永久保存 -1表示不更改ts文件的生命周期,正值表示修改ts文件的生命周期为expireDays
99
+ #
100
+ # 返回:
101
+ # fname: 字符串,表示保存后在存储空间里的文件名。
102
+ # persistentID: 字符串,持久化异步处理任务ID,异步模式才会返回该字段,通常用不到该字段
103
+ def saveas(opt = {})
84
104
  ret = @client.rpc.call_with_json("POST", "#{@base_url}/saveas", opt)
105
+ [ret["fname"], ret["persistentID"]]
106
+ end
107
+
108
+ # 保存直播截图
109
+ #
110
+ # 参数:
111
+ # fname 保存到存储空间的文件名,可选,不指定系统会随机生成。
112
+ # time 整数,可选,Unix 时间戳,要保存截图的时间点,不指定则为当前时间。
113
+ # format 保存的文件格式,可选,默认为jpg。
114
+ #
115
+ # 返回:
116
+ # fname => <String> # 字符串,表示保存后在存储空间里的文件名。
117
+ def snapshot(opt = {})
118
+ ret = @client.rpc.call_with_json("POST", "#{@base_url}/snapshot", opt)
85
119
  ret["fname"]
86
120
  end
121
+
122
+ # 修改流转码配置
123
+ #
124
+ # 参数:
125
+ # profiles 字符串数组,元素为转码的分辨率如:720p, 480p
126
+ #
127
+ def update_converts(profiles)
128
+ ret = @client.rpc.call_with_json("POST", "#{@base_url}/converts", :converts => profiles)
129
+ end
87
130
 
88
131
  # 查询直播历史.
89
132
  #
@@ -105,11 +148,11 @@ module Pili
105
148
  end
106
149
 
107
150
  def to_s
108
- "#<#{self.class} #{@hub}/#{@key}>"
151
+ "#<#{self.class} #{@hub}/#{@title}>"
109
152
  end
110
153
 
111
154
  def to_json
112
- {:hub=>@hub, :key=>@key}.to_json
155
+ {:hub=>@hub, :key=>@title}.to_json
113
156
  end
114
157
  end
115
158
  end
@@ -1,3 +1,3 @@
1
1
  module Pili
2
- VERSION = "2.0.3"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piliv2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pili Engineer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.5.1
87
+ rubygems_version: 2.6.8
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Pili Streaming Cloud Server-Side Library For Ruby.