spotilocal 0.2.0 → 0.3.0
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 +4 -4
- data/README.md +4 -2
- data/lib/spotilocal.rb +1 -0
- data/lib/spotilocal/client.rb +14 -7
- data/lib/spotilocal/version.rb +1 -1
- data/spotilocal.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9024ff189cda39e9cdfedc960f2af360a4b72fad
|
4
|
+
data.tar.gz: 36d400bc168d54a9a19a78a02dbe857641ab92aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d6cdcff47c4a5504375e8d7630377976be69b20d8f952182be6cff52754e6a595ec6cc59522b6c4ca80ac981b768dfddcec7e52ab94d639c52b2aa08df0d4b
|
7
|
+
data.tar.gz: 79e63aa8f02c8919378df1a394e17032d918f79e45e2aba455d58e4ecbe03a009f65e150a4b8260aa95d0c5fd66b96f0fdc6c345d2c354fd2300ffd149c78449
|
data/README.md
CHANGED
@@ -21,15 +21,17 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
24
|
+
You can specify a port to create the instance faster. Otherwise spotilocal will try to discover the port.
|
25
25
|
```ruby
|
26
26
|
# Create a new spotify object
|
27
|
-
s = Spotilocal::
|
27
|
+
s = Spotilocal::Client.new port: 4382
|
28
28
|
```
|
29
29
|
|
30
30
|
After that you can simply fetch some informations.
|
31
31
|
```ruby
|
32
32
|
s.status
|
33
|
+
s.pause # true if paused
|
34
|
+
s.unpause # true if playing
|
33
35
|
```
|
34
36
|
|
35
37
|
## Development
|
data/lib/spotilocal.rb
CHANGED
data/lib/spotilocal/client.rb
CHANGED
@@ -4,7 +4,7 @@ module Spotilocal
|
|
4
4
|
|
5
5
|
HEADERS = { Origin: 'https://open.spotify.com' }.freeze
|
6
6
|
|
7
|
-
def initialize(port:
|
7
|
+
def initialize(port: discover_port)
|
8
8
|
raise 'Port required' unless port
|
9
9
|
@url = "http://localhost:#{port}"
|
10
10
|
@csrf = csrf_token
|
@@ -12,17 +12,15 @@ module Spotilocal
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def status
|
15
|
-
|
16
|
-
params: { csrf: csrf, oauth: oauth })
|
17
|
-
puts JSON.parse(req.response_body)
|
15
|
+
lcall(:status)
|
18
16
|
end
|
19
17
|
|
20
18
|
def pause
|
21
|
-
!lcall(:pause, params: { pause: 'true' })
|
19
|
+
!lcall(:pause, params: { pause: 'true' }).playing
|
22
20
|
end
|
23
21
|
|
24
22
|
def unpause
|
25
|
-
lcall(:pause, params: { pause: 'false' })
|
23
|
+
lcall(:pause, params: { pause: 'false' }).playing
|
26
24
|
end
|
27
25
|
|
28
26
|
private
|
@@ -30,7 +28,7 @@ module Spotilocal
|
|
30
28
|
def lcall(loc, params: {}, resource: :remote)
|
31
29
|
req = Typhoeus.get("#{url}/#{resource}/#{loc}.json",
|
32
30
|
params: params.merge(csrf: csrf, oauth: oauth))
|
33
|
-
JSON.parse(req.response_body)
|
31
|
+
JSON.parse(req.response_body, object_class: OpenStruct)
|
34
32
|
end
|
35
33
|
|
36
34
|
def oauth_token
|
@@ -42,5 +40,14 @@ module Spotilocal
|
|
42
40
|
req = Typhoeus.get("#{url}/simplecsrf/token.json", headers: HEADERS)
|
43
41
|
JSON.parse(req.response_body)['token']
|
44
42
|
end
|
43
|
+
|
44
|
+
def discover_port
|
45
|
+
(4370..4390).each do |port|
|
46
|
+
if Typhoeus.get("http://localhost:#{port}",
|
47
|
+
timeout: 1).return_code == :ok
|
48
|
+
return port
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/spotilocal/version.rb
CHANGED
data/spotilocal.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = 'Remote control your spotify client'
|
13
13
|
spec.description = 'Wrapper to remote control a local spotify client'
|
14
|
-
spec.homepage = 'https://
|
14
|
+
spec.homepage = 'https://github.com/Flipez/spotilocal'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spotilocal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flipez
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- lib/spotilocal/client.rb
|
102
102
|
- lib/spotilocal/version.rb
|
103
103
|
- spotilocal.gemspec
|
104
|
-
homepage: https://
|
104
|
+
homepage: https://github.com/Flipez/spotilocal
|
105
105
|
licenses:
|
106
106
|
- MIT
|
107
107
|
metadata: {}
|