alexa_remotectl 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: d3641c9d28ab824390ab0dc3aebec594eb204fdb0d09f8536ded7a7efd541e62
4
- data.tar.gz: 8afb412ab356140e1289d1df7b49487bbc72e2b0d0593f43106f32dc8e643683
3
+ metadata.gz: 9b1f56f3518e257c26d3d00ac9e63dde021474827abb5461fdb11114f95196a2
4
+ data.tar.gz: 3dbe1a051f41b9b11f77e0f82c392f90c72d23ee4ba0314cc6ebc3c0deb31adc
5
5
  SHA512:
6
- metadata.gz: 7bf863c6ae5e8d4426a32d0b57b0c763aaff8534a0bc379eb3a30e0aaaebb564317d6463b4ab0025133d8b720721315a10c7dc00473c70bb79f4567d1961d1d9
7
- data.tar.gz: eb8b72c82327e56afc915dbe0ed2400a05db3ea061c5ae478e61b9cfc7f8e36e3f0f0c4b73908a97e45280f618bab40a9645a7d6f02429bc8f7400675d92e0f1
6
+ metadata.gz: ff774816c05f4c379b0563f83ff5b9036161c58975438898723d2460aadbb29fe554fa6b84f6c5c12208fb1e375ccdaccac5d006944b7262c321c9a5b4abe724
7
+ data.tar.gz: 236d52c95e7421ee51af2d425523ddb85d193290398b4886bfae7c718a8e16f6b1450a316301dc8a077ba0436d59ecb2b7faa301041865ff179505a3001c3594
checksums.yaml.gz.sig CHANGED
Binary file
@@ -58,9 +58,10 @@ end
58
58
 
59
59
  class AlexaRemoteCtl
60
60
 
61
- def initialize(domain: 'alexa.amazon.co.uk', device: {}, cookie: '')
61
+ def initialize(domain: 'alexa.amazon.co.uk', device: {}, cookie: '',
62
+ customerid: '')
62
63
 
63
- @domain, @device, @cookie = domain, device, cookie
64
+ @domain, @device, @cookie, @customerid = domain, device, cookie, customerid
64
65
 
65
66
  end
66
67
 
@@ -68,6 +69,11 @@ class AlexaRemoteCtl
68
69
  device_player()[:playerInfo]
69
70
  end
70
71
 
72
+ def list_ebooks()
73
+ get_json '/api/ebooks/library', "mediaOwnerCustomerId=#{@customerid}" +
74
+ "&nextToken=&size=50"
75
+ end
76
+
71
77
  def mute?()
72
78
  info()[:volume][:muted]
73
79
  end
@@ -87,6 +93,28 @@ class AlexaRemoteCtl
87
93
  pp_cmd('Play')
88
94
  end
89
95
 
96
+ def play_ebook(id)
97
+
98
+ serialno = @device[:serialno]
99
+ type = @device[:type]
100
+
101
+ url = "https://#{@domain}/api/ebooks/queue-and-play?"
102
+
103
+ body = {
104
+ 'asin' => id,
105
+ 'deviceType' => type,
106
+ 'deviceSerialNumber' => serialno,
107
+ 'mediaOwnerCustomerId' => @customerid
108
+ }.to_json
109
+
110
+ post_request url, body
111
+
112
+ end
113
+
114
+ def play_hq(id)
115
+ device_phq(id)
116
+ end
117
+
90
118
  def playing?()
91
119
  info()[:state] == 'PLAYING'
92
120
  end
@@ -136,18 +164,51 @@ class AlexaRemoteCtl
136
164
  serialno = @device[:serialno]
137
165
  type = @device[:type]
138
166
 
139
- url = "https://#{@domain}/api/np/command?deviceSerialNumber=#{serialno}&deviceType=#{type}"
167
+ url = "https://#{@domain}/api/np/command?deviceSerial" +
168
+ "Number=#{serialno}&deviceType=#{type}"
140
169
  post_command url, body
141
170
 
142
171
  end
143
172
 
173
+ # play historical queue (PHQ)
174
+ #
175
+ def device_phq(queueid)
176
+
177
+ serialno = @device[:serialno]
178
+ type = @device[:type]
179
+
180
+ url = "https://#{@domain}/api/media/play-historical-queue"
181
+
182
+ body = {
183
+ 'deviceType' => type,
184
+ 'deviceSerialNumber' => serialno,
185
+ 'queueId' => queueid,
186
+ 'startTime' => nil,
187
+ 'service' => nil,
188
+ 'trackSource' => nil,
189
+ 'mediaOwnerCustomerId' => @customerid
190
+ }.to_json
191
+
192
+ post_request url, body
193
+
194
+ end
195
+
144
196
  def device_player()
197
+ get_json '/api/np/player'
198
+ end
199
+
200
+ def get_json(uri, params='')
201
+
145
202
  serialno = @device[:serialno]
146
203
  type = @device[:type]
147
204
 
148
- url = "https://#{@domain}/api/np/player?deviceSerialNumber=#{serialno}&deviceType=#{type}"
149
- r = post_request url
205
+ url = "https://#{@domain}#{uri}?deviceSerial" +
206
+ "Number=#{serialno}&deviceType=#{type}"
207
+ url += '&' + params if params.length > 1
208
+
209
+ r = get_request url
150
210
  JSON.parse(r.body, symbolize_names: true)
211
+
151
212
  end
152
213
 
153
214
  def make_response(uri, request)
@@ -155,14 +216,15 @@ class AlexaRemoteCtl
155
216
  request["Accept"] = "application/json, text/javascript, */*; q=0.01"
156
217
  request["Accept-Language"] = "en-GB,en-US;q=0.9,en;q=0.8"
157
218
  request["Connection"] = "keep-alive"
158
- request["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
159
219
  request["Cookie"] = @cookie
160
220
 
161
221
  request["Referer"] = "https://#{@domain}/spa/index.html"
162
222
  request["Sec-Fetch-Dest"] = "empty"
163
223
  request["Sec-Fetch-Mode"] = "cors"
164
224
  request["Sec-Fetch-Site"] = "same-origin"
165
- request["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
225
+ request["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) " +
226
+ "AppleWebKit/537.36 (KHTML, like Gecko) " +
227
+ "Chrome/101.0.4951.64 Safari/537.36"
166
228
  request["X-Requested-With"] = "XMLHttpRequest"
167
229
  request["csrf"] = "-990908140"
168
230
  request["dnt"] = "1"
@@ -181,6 +243,7 @@ class AlexaRemoteCtl
181
243
  end
182
244
 
183
245
  def post_command(url, body='')
246
+
184
247
  uri = URI.parse(url)
185
248
  request = Net::HTTP::Post.new(uri)
186
249
  request.body = body
@@ -193,7 +256,7 @@ class AlexaRemoteCtl
193
256
  # response.body
194
257
  end
195
258
 
196
- def post_request(url)
259
+ def get_request(url)
197
260
 
198
261
  uri = URI.parse(url)
199
262
  request = Net::HTTP::Get.new(uri)
@@ -204,6 +267,19 @@ class AlexaRemoteCtl
204
267
 
205
268
  end
206
269
 
270
+
271
+ def post_request(url, body='')
272
+
273
+ uri = URI.parse(url)
274
+ request = Net::HTTP::Post.new(uri)
275
+ request.body = body
276
+ response = make_response(uri, request)
277
+
278
+ # response.code
279
+ # response.body
280
+
281
+ end
282
+
207
283
  end
208
284
 
209
285
  class AlexaDevices
@@ -212,16 +288,17 @@ class AlexaDevices
212
288
  # note: label can be any identifier you choose e.g. kitchen
213
289
  #
214
290
  def initialize(devicesx=[], devices: devicesx,
215
- domain: 'alexa.amazon.co.uk', cookie: '')
291
+ domain: 'alexa.amazon.co.uk', cookie: '', customerid: '')
216
292
 
217
293
  @devices, @domain, @cookie = devices, domain, cookie
294
+ @customerid = customerid
218
295
 
219
296
  end
220
297
 
221
298
  def playing()
222
299
 
223
300
  @devices.map do |device, label|
224
- alexa = AlexaRemoteCtl.new(cookie: @cookie, device: device)
301
+ alexa = get_alexa device
225
302
  alexa.playing? ? [alexa, label] : nil
226
303
  end.compact
227
304
 
@@ -253,18 +330,28 @@ class AlexaDevices
253
330
  if id then
254
331
 
255
332
  device, _ = a.find {|_, label| label.to_sym == id.to_sym}
256
- alexa = AlexaRemoteCtl.new(cookie: @cookie, device: device)
333
+ alexa = get_alexa device
257
334
  alexa.play
258
335
 
259
336
  else
260
337
 
261
338
  a.each do |device, label|
339
+
262
340
  puts 'Pausing @' + label.inspect
263
- alexa = AlexaRemoteCtl.new(cookie: @cookie, device: device)
341
+ alexa = get_alexa device
264
342
  alexa.play
343
+
265
344
  end
266
345
 
267
346
  end
268
347
  end
269
348
 
349
+ private
350
+
351
+ def get_alexa(device)
352
+
353
+ AlexaRemoteCtl.new(cookie: @cookie, device: device,
354
+ customerid: @customerid)
355
+ end
356
+
270
357
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- q�!O��,>�n���$�}���1t�?(��y���?��Ҥ��d]R
2
- ���]�],�\]��v4#�K^²Ed�ϟ�LO��WT�ո{�|ݬrCRR� P���[�����,alxm�Ł�<�q���T���_
1
+ W2f���Kv��/-k8�嘯�
2
+ d��{�S�Uq�'�ʆ�FE���e"��H��&��~���ҡ������
3
+ �����S:�HͯƖ���
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_remotectl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file