grooveshark 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grooveshark/client.rb +12 -18
- data/lib/grooveshark/version.rb +1 -1
- data/spec/client_spec.rb +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: 4d602ca3fbcfdc5d9812fb69bd45e890f25f5b36
|
4
|
+
data.tar.gz: fd049697921040644c38404c77374c2b625622fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d345fbb7bf7e58eaf8ceb38c9c2b32d604f8e5e60be3461acacb4dc1028d9f23c31b46f766d64b6ca2b2501dcd4e904a2940f727163841991ef03a0dfdca84
|
7
|
+
data.tar.gz: 5c1a411ae739e3c352ab7c0df69eff39e7234644860619cce1221edf0aa1b19cb48616adf90f194c50540b64fc67bf21452346437699838d26401f985d99d44c
|
data/lib/grooveshark/client.rb
CHANGED
@@ -5,9 +5,8 @@ module Grooveshark
|
|
5
5
|
|
6
6
|
def initialize(params = {})
|
7
7
|
@ttl = params[:ttl] || 120 # 2 minutes
|
8
|
-
@session, @country = get_session_and_country
|
9
8
|
@uuid = UUID.new.generate.upcase
|
10
|
-
|
9
|
+
get_token_data
|
11
10
|
end
|
12
11
|
|
13
12
|
# Authenticate user
|
@@ -89,32 +88,28 @@ module Grooveshark
|
|
89
88
|
get_song_url_by_id(song.id)
|
90
89
|
end
|
91
90
|
|
92
|
-
def
|
91
|
+
def get_token_data
|
93
92
|
response = RestClient.get('http://grooveshark.com')
|
94
|
-
session = response.headers[:set_cookie].to_s.scan(/PHPSESSID=([a-z\d]{32});/i).flatten.first
|
95
93
|
|
96
94
|
preload_regex = /gsPreloadAjax\(\{url: '\/preload.php\?(.*)&hash=' \+ clientPage\}\)/
|
97
95
|
preload_id = response.to_s.scan(preload_regex).flatten.first
|
98
96
|
preload_url = "http://grooveshark.com/preload.php?#{preload_id}&getCommunicationToken=1&hash=%2F"
|
99
97
|
preload_response = RestClient.get(preload_url)
|
100
98
|
|
101
|
-
|
102
|
-
raise GeneralError, "
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
# Get communication token
|
108
|
-
def get_comm_token
|
109
|
-
@comm_token = nil # request() uses it
|
110
|
-
@comm_token = request('getCommunicationToken', {:secretKey => Digest::MD5.hexdigest(@session)}, true)
|
99
|
+
token_data_json = preload_response.to_s.scan(/window.tokenData = (.*);/).flatten.first
|
100
|
+
raise GeneralError, "token data not found" if not token_data_json
|
101
|
+
token_data = JSON.parse(token_data_json)
|
102
|
+
@comm_token = token_data['getCommunicationToken']
|
111
103
|
@comm_token_ttl = Time.now.to_i
|
104
|
+
config = token_data['getGSConfig']
|
105
|
+
@country = config['country']
|
106
|
+
@session = config['sessionID']
|
112
107
|
end
|
113
108
|
|
114
109
|
# Sign method
|
115
110
|
def create_token(method)
|
116
111
|
rnd = get_random_hex_chars(6)
|
117
|
-
salt =
|
112
|
+
salt = "gooeyFlubber"
|
118
113
|
plain = [method, @comm_token, salt, rnd].join(':')
|
119
114
|
hash = Digest::SHA1.hexdigest(plain)
|
120
115
|
"#{rnd}#{hash}"
|
@@ -128,7 +123,7 @@ module Grooveshark
|
|
128
123
|
# Perform API request
|
129
124
|
def request(method, params={}, secure=false)
|
130
125
|
refresh_token if @comm_token
|
131
|
-
|
126
|
+
|
132
127
|
url = "#{secure ? 'https' : 'http'}://grooveshark.com/more.php?#{method}"
|
133
128
|
body = {
|
134
129
|
'header' => {
|
@@ -143,7 +138,6 @@ module Grooveshark
|
|
143
138
|
'parameters' => params
|
144
139
|
}
|
145
140
|
body['header']['token'] = create_token(method) if @comm_token
|
146
|
-
|
147
141
|
begin
|
148
142
|
data = RestClient.post(url, body.to_json, {'Content-Type' => 'application/json'})
|
149
143
|
rescue Exception => ex
|
@@ -162,7 +156,7 @@ module Grooveshark
|
|
162
156
|
|
163
157
|
# Refresh communications token on ttl
|
164
158
|
def refresh_token
|
165
|
-
|
159
|
+
get_token_data if Time.now.to_i - @comm_token_ttl > @ttl
|
166
160
|
end
|
167
161
|
end
|
168
162
|
end
|
data/lib/grooveshark/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grooveshark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|