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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/alexa_remotectl.rb +99 -12
- data.tar.gz.sig +3 -2
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1f56f3518e257c26d3d00ac9e63dde021474827abb5461fdb11114f95196a2
|
4
|
+
data.tar.gz: 3dbe1a051f41b9b11f77e0f82c392f90c72d23ee4ba0314cc6ebc3c0deb31adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff774816c05f4c379b0563f83ff5b9036161c58975438898723d2460aadbb29fe554fa6b84f6c5c12208fb1e375ccdaccac5d006944b7262c321c9a5b4abe724
|
7
|
+
data.tar.gz: 236d52c95e7421ee51af2d425523ddb85d193290398b4886bfae7c718a8e16f6b1450a316301dc8a077ba0436d59ecb2b7faa301041865ff179505a3001c3594
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/alexa_remotectl.rb
CHANGED
@@ -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?
|
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}
|
149
|
-
|
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)
|
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
|
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 =
|
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 =
|
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 =
|
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
|
-
|
2
|
-
|
1
|
+
W2f���Kv��/-k8�嘯�
|
2
|
+
d��{�S�Uq�'�ʆ�FE���e"��H��&��~���ҡ������
|
3
|
+
�����S:�HͯƖ���
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|