alexa_remotectl 0.4.2 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769f37b93490b3ab472fea0e8bc15dc1ce3c2e34cb3b4c01ce0ddc6c296fdff9
4
- data.tar.gz: 66bdfb5add38d18635c34469ebd2a508a152daa76319c043ccfc81c67569781d
3
+ metadata.gz: e6f8ae020909ff7e55ed461f0abd1d5be5030f4a0a33e59bca9d679d9d317cdb
4
+ data.tar.gz: 2ca248fe25642502eb143de03d3ef64297b24618eea71b630fba347a040e6682
5
5
  SHA512:
6
- metadata.gz: 50ae6554ebe0f56317439880759316c90cfcd154d564cf45db4d517c5471115a10d0f4bad197e74090f96cc952fa9bf8f5f1dd43c0889285c78822022fd488ad
7
- data.tar.gz: ab6a5c377f4575298d29dbe02592a7a3a20949a7a88326926ab968d725cd2a3e9ec7ccc3cf71aca1300f2fa56dd14964653aff09f9d501538031639ca04fe07f
6
+ metadata.gz: 3a6b48bedafcc463138aeb96b7eb1450a048f60a8f886494bcdb7b0b7abb658a658d707b2820d6586eb4c0a776704a650b79e728d06e3a7bcea917144852ea14
7
+ data.tar.gz: 7370ca7ac96b4c72dddaa0967d24d78d0267b7746ec533a96c68062dc5b5cac487040230432bf298c85d60e316c65e26223a39bcdc1f5677011afbcf2aba4962
checksums.yaml.gz.sig CHANGED
Binary file
@@ -13,7 +13,7 @@ require 'json'
13
13
  # Use the CodeWizard with the cURL command you've copied using Developer
14
14
  # tools on Alexa's SPA page (within the web browser).
15
15
  #
16
- # note: to find the correct url to convert, try clickin on pause or play to
16
+ # note: to find the correct url to convert, try clicking on pause or play to
17
17
  # invoke an AJAX request
18
18
 
19
19
  class CodeWizard
@@ -62,20 +62,43 @@ class AlexaRemoteCtl
62
62
 
63
63
  # note: Added the Cross-site request forgery (crsf) variable
64
64
  #
65
- def initialize(domain: 'alexa.amazon.co.uk', device: {}, cookie: '', customerid: '', csrf: '')
65
+ def initialize(domain: 'alexa.amazon.co.uk', device: {}, cookie: '',
66
+ customerid: '', csrf: '')
66
67
 
67
68
  @domain, @device, @cookie, @customerid = domain, device, cookie, customerid
68
69
  @csrf = csrf
69
70
 
70
71
  end
71
72
 
73
+ # Some audio streams can't be paused through the SPA API. Playing a
74
+ # historical queue, and then pausing it, is the best next option.
75
+ #
76
+ def force_pause()
77
+
78
+ r = list_hq()
79
+ queueid = r[:media][0][:queueId]
80
+
81
+ play_hq queueid
82
+ sleep 1
83
+
84
+ pause()
85
+
86
+ end
87
+
72
88
  def info()
73
89
  device_player()[:playerInfo]
74
90
  end
75
91
 
76
92
  def list_ebooks()
77
- get_json '/api/ebooks/library', "mediaOwnerCustomerId=#{@customerid}" +
93
+ r = get_json '/api/ebooks/library', "mediaOwnerCustomerId=#{@customerid}" +
78
94
  "&nextToken=&size=50"
95
+ r[:metadataList]
96
+ end
97
+
98
+ # list historical queue (hq)
99
+ #
100
+ def list_hq()
101
+ get_json '/api/media/historical-queue', "size=50&offset=-1"
79
102
  end
80
103
 
81
104
  def mute?()
@@ -97,7 +120,13 @@ class AlexaRemoteCtl
97
120
  pp_cmd('Play')
98
121
  end
99
122
 
100
- def play_ebook(id)
123
+ def play_ebook(obj)
124
+
125
+ id = if obj.is_a? Integer then
126
+ list_ebook()[obj][:asin]
127
+ else
128
+ obj
129
+ end
101
130
 
102
131
  serialno = @device[:serialno]
103
132
  type = @device[:type]
@@ -115,8 +144,19 @@ class AlexaRemoteCtl
115
144
 
116
145
  end
117
146
 
118
- def play_hq(id)
119
- device_phq(id)
147
+ # play historical queue
148
+ # note: You can find the queueid from an entry in the list_hq() result
149
+ #
150
+ def play_hq(obj)
151
+
152
+ queueid = if obj.is_a? Integer then
153
+ r = list_hq()
154
+ r[:media][obj][:queueId]
155
+ else
156
+ obj
157
+ end
158
+
159
+ device_phq(queueid)
120
160
  end
121
161
 
122
162
  def playing?()
@@ -154,6 +194,8 @@ class AlexaRemoteCtl
154
194
  device_cmd(body)
155
195
  end
156
196
 
197
+ alias setvol vol=
198
+
157
199
  private
158
200
 
159
201
  # play, pause, or next
@@ -293,70 +335,85 @@ class AlexaDevices
293
335
  #
294
336
  def initialize(devicesx=[], devices: devicesx,
295
337
  domain: 'alexa.amazon.co.uk', cookie: '', customerid: '',
296
- csrf: '')
338
+ csrf: '', debug: false)
297
339
 
298
340
  @devices, @domain, @cookie = devices, domain, cookie
299
- @customerid, @csrf = customerid, csrf
341
+ @customerid, @csrf, @debug = customerid, csrf, debug
300
342
 
301
343
  end
302
344
 
345
+ def force_pause(id) invoke(:force_pause, id) end
346
+ def info(id=nil) invoke(:info, id) end
347
+ def list_ebooks(id) invoke(:list_ebooks, id) end
348
+ def list_hq(id=nil) invoke(:list_hq, id) end
349
+ def mute?(id=nil) invoke2(:mute?, id) end
350
+ def next(id) invoke2(:next, id) end
351
+
303
352
  def playing()
304
353
 
305
- @devices.map do |device, label|
354
+ devices = @devices.map do |device, label|
355
+
356
+ puts 'label: ' + label.inspect if @debug
357
+ puts 'device: ' + device.inspect if @debug
358
+
306
359
  alexa = get_alexa device
307
360
  alexa.playing? ? [alexa, label] : nil
308
- end.compact
309
-
310
- end
311
361
 
312
- def pause(id=nil)
362
+ end.compact
313
363
 
314
- a = playing()
364
+ puts 'devices: ' + devices.inspect if @debug
365
+ return devices
315
366
 
316
- if id then
367
+ end
317
368
 
318
- alexa, _ = a.find {|_, label| label.to_sym == id.to_sym}
319
- alexa.pause
369
+ def pause(id=nil) invoke2(:pause, id) end
370
+ def play(id) invoke(:play, id) end
371
+ def play_ebook(id) invoke(:list_hq, id) end
372
+ def play_hq(id,qid) invoke(:play_hq, id, qid) end
373
+ def playing?(id=nil) invoke(:playing?, id) end
374
+ def text1(id=nil) invoke2(:text1, id) end
375
+ def text2(id=nil) invoke2(:text2, id) end
376
+ def title(id=nil) invoke2(:title, id) end
377
+ def vol(id=nil) invoke(:vol, id) end
378
+ def setvol(id=nil, level) invoke(:setvol, id, level) end
320
379
 
321
- else
380
+ private
322
381
 
323
- a.each do |alexa, label|
324
- puts 'Pausing @' + label.inspect
325
- alexa.pause
326
- end
382
+ def get_alexa(device)
327
383
 
328
- end
384
+ AlexaRemoteCtl.new(cookie: @cookie, device: device,
385
+ customerid: @customerid, csrf: @csrf)
329
386
  end
330
387
 
331
- def play(id=nil)
332
-
333
- a = @devices
388
+ def apply_cmd(a, cmd, id, args)
334
389
 
335
390
  if id then
336
391
 
337
392
  device, _ = a.find {|_, label| label.to_sym == id.to_sym}
338
393
  alexa = get_alexa device
339
- alexa.play
394
+ alexa.method(cmd).call(*args)
340
395
 
341
396
  else
342
397
 
343
- a.each do |device, label|
398
+ a.map do |device, label|
344
399
 
345
- puts 'Pausing @' + label.inspect
400
+ puts cmd.to_s + ' @' + label.inspect
346
401
  alexa = get_alexa device
347
- alexa.play
402
+ alexa.method(cmd).call(*args)
348
403
 
349
404
  end
350
405
 
351
406
  end
352
407
  end
353
408
 
354
- private
355
-
356
- def get_alexa(device)
409
+ def invoke(cmd, id, *args)
410
+ apply_cmd(@devices, cmd, id, args)
411
+ end
357
412
 
358
- AlexaRemoteCtl.new(cookie: @cookie, device: device,
359
- customerid: @customerid, csrf: @csrf)
413
+ # apply command to an Alexa device which is currently playing
414
+ #
415
+ def invoke2(cmd, id, *args)
416
+ apply_cmd(playing(), cmd, id, args)
360
417
  end
361
418
 
362
419
  end
data.tar.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- �Z�?.
2
- V�{��Ȏ��d��ïAr�Ѯp
3
- z�%79GAA���f�y�8*a���y����R��
1
+
2
+ ������\G�y<�x��yxk?8Ά��(�����E�6���-ubA�ځe##T�a.�ޟ��tC�IC�]O�E��|X��?I%@>��/�Ɗ�Q�#�I��v�́T-=��׳]����V)亏S���Xe��}���1�r
3
+ Ԙk'��1���ҕ�‘�Y��/��:E�@��8�lݫ�hu
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.2
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  d/gEwBtUmduwWZNX2NOJehf8s1cnH9OBP7s1ziHjdkZCgkQm3QewRRcdfZeYwFi6
36
36
  4kVEcApgAgd+04ctE6uiRn5o
37
37
  -----END CERTIFICATE-----
38
- date: 2022-05-22 00:00:00.000000000 Z
38
+ date: 2022-05-24 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: clipboard
metadata.gz.sig CHANGED
Binary file