alexa_remotectl 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: bfe02b279946e6fa20e4615f417bbfa52e8128987b630338ae08d86d3e82374e
4
- data.tar.gz: f8be3e2e607a59f7592a36810455ae49383750f1e8755cb7fab28edbf83ba219
3
+ metadata.gz: b87386430128ab1ce213a4cd52575053a590ed2434db563f47d0040d1ad6895a
4
+ data.tar.gz: 1c41066bff31ad20906dea4d73a60d015033d44a25030e22f149303c2948e83f
5
5
  SHA512:
6
- metadata.gz: add9df3f63dc5f001ce55703de6e7b579ce646bf713a40a541843eca6ca6fc752a03209209f15c3cdc714bc5a066477381f2f746e6d0d1608c096e9cfcf35973
7
- data.tar.gz: 00a8dc58950293d74b42b924c83e4fadfea64f4a70eff6a42489c0d2b8048deac4e76ede59f4c6da594355a44a9c70c3dfe1a5d0f2ea07ebe8a08582713bd04f
6
+ metadata.gz: 211a820b58b377520c8f08861b04641a0ca6c8624f69f9bca67e79a5ef17555aa61debd3e35a5c550bd662bb4801650f7a2039fb78b0cf4738f96d756b41daab
7
+ data.tar.gz: 9565b73cdcf8609d313f5ea5a53bfa0556fad0f65c48f8b0f14e1c8794774caf517e6f8ee2f454df9c6c4aa35b33644d7ed40083b803f591a7d5f35643177165
checksums.yaml.gz.sig CHANGED
Binary file
@@ -8,6 +8,7 @@
8
8
  require 'net/http'
9
9
  require 'uri'
10
10
  require 'clipboard'
11
+ require 'json'
11
12
 
12
13
  # Use the CodeWizard with the cURL command you've copied using Developer
13
14
  # tools on Alexa's SPA page (within the web browser).
@@ -63,33 +64,96 @@ class AlexaRemoteCtl
63
64
 
64
65
  end
65
66
 
67
+ def info()
68
+ device_player()[:playerInfo]
69
+ end
70
+
71
+ def mute?()
72
+ info()[:volume][:muted]
73
+ end
74
+
75
+ alias muted? mute?
76
+
77
+ # skip to the next music track
78
+ def next
79
+ pp_cmd('Next')
80
+ end
81
+
66
82
  def pause
67
- device_cmd('Pause')
83
+ pp_cmd('Pause')
68
84
  end
69
85
 
70
86
  def play
71
- device_cmd('Play')
87
+ pp_cmd('Play')
88
+ end
89
+
90
+ # Artist name
91
+ #
92
+ def text1()
93
+ info()[:infoText][:subText1]
94
+ end
95
+
96
+ # music station
97
+ #
98
+ def text2()
99
+ info()[:infoText][:subText2]
100
+ end
101
+
102
+ # music track title
103
+ #
104
+ def title()
105
+ info()[:infoText][:title]
106
+ end
107
+
108
+ def vol()
109
+ info()[:volume][:volume]
110
+ end
111
+
112
+ def vol=(n)
113
+
114
+ return unless n.between? 0, 40
115
+
116
+ body = '{"type":"VolumeLevelCommand","volumeLevel":' + n.to_s \
117
+ + ',"contentFocusClientId":null}'
118
+ device_cmd(body)
72
119
  end
73
120
 
74
121
  private
75
122
 
76
- def device_cmd(cmd)
123
+ # play, pause, or next
124
+ #
125
+ def pp_cmd(s)
126
+ body = '{"type":"' + s + 'Command","contentFocusClientId":null}'
127
+ device_cmd body
128
+ end
129
+
130
+ def device_cmd(body)
77
131
 
78
132
  serialno = @device[:serialno]
79
133
  type = @device[:type]
80
134
 
81
135
  url = "https://#{@domain}/api/np/command?deviceSerialNumber=#{serialno}&deviceType=#{type}"
82
- uri = URI.parse(url)
83
- request = Net::HTTP::Post.new(uri)
84
- request.body = '{"type":"' + cmd + 'Command","contentFocusClientId":null}'
85
- request.content_type = "application/x-www-form-urlencoded; charset=UTF-8"
136
+ post_command url, body
137
+
138
+ end
139
+
140
+ def device_player()
141
+ serialno = @device[:serialno]
142
+ type = @device[:type]
143
+
144
+ url = "https://#{@domain}/api/np/player?deviceSerialNumber=#{serialno}&deviceType=#{type}"
145
+ r = post_request url
146
+ JSON.parse(r.body, symbolize_names: true)
147
+ end
148
+
149
+ def make_response(uri, request)
86
150
 
87
151
  request["Accept"] = "application/json, text/javascript, */*; q=0.01"
88
152
  request["Accept-Language"] = "en-GB,en-US;q=0.9,en;q=0.8"
89
153
  request["Connection"] = "keep-alive"
90
154
  request["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
91
155
  request["Cookie"] = @cookie
92
- request["Origin"] = "https://" + @domain
156
+
93
157
  request["Referer"] = "https://#{@domain}/spa/index.html"
94
158
  request["Sec-Fetch-Dest"] = "empty"
95
159
  request["Sec-Fetch-Mode"] = "cors"
@@ -110,8 +174,30 @@ class AlexaRemoteCtl
110
174
  http.request(request)
111
175
  end
112
176
 
177
+ end
178
+
179
+ def post_command(url, body='')
180
+ uri = URI.parse(url)
181
+ request = Net::HTTP::Post.new(uri)
182
+ request.body = body
183
+ request.content_type = "application/x-www-form-urlencoded; charset=UTF-8"
184
+ request["Origin"] = "https://" + @domain
185
+
186
+ response = make_response(uri, request)
187
+
188
+ # response.code
189
+ # response.body
190
+ end
191
+
192
+ def post_request(url)
193
+
194
+ uri = URI.parse(url)
195
+ request = Net::HTTP::Get.new(uri)
196
+ response = make_response(uri, request)
197
+
113
198
  # response.code
114
199
  # response.body
115
200
 
116
201
  end
202
+
117
203
  end
data.tar.gz.sig CHANGED
Binary file
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.2.0
4
+ version: 0.3.0
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-18 00:00:00.000000000 Z
38
+ date: 2022-05-21 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: clipboard
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- u�_&���`TnK�����a��j�%�u�v�j��������N�nmXW�-���# �F���Ƶ��)-/�_x��
2
- �<��X-�;ɺ�p
1
+ 7UN���ht��gl���ږ������٤_�xe�}P9�������^�,����>�m������8ʖUž[��+-9Qo�a��(>��_4 �vVo��2/�4���L����J���xi�*������PX��1n(R�;��mJ�� �ȉ�͖��LX d�A_8+����EkX+1��m!n+F��z �k��i�P$Ed� �z�[���aU�wh����v)H��\L��/"���J��U:"�W������e��*�>�a΅��yzh7u���B�b���������vt'��r�X;�WW� U��$��Z�&����
2
+ �K