grooveshark 0.2.10 → 0.2.11
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 +61 -38
- data/grooveshark.gemspec +7 -7
- data/lib/grooveshark.rb +2 -0
- data/lib/grooveshark/broadcast.rb +38 -0
- data/lib/grooveshark/client.rb +29 -14
- data/lib/grooveshark/errors.rb +3 -3
- data/lib/grooveshark/playlist.rb +4 -4
- data/lib/grooveshark/song.rb +3 -3
- data/lib/grooveshark/user.rb +17 -17
- data/lib/grooveshark/version.rb +1 -1
- data/spec/broadcast_spec.rb +39 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b22e2adb61445f3b5c0253a93cd2a8e012a6c8b
|
4
|
+
data.tar.gz: f93bd8afcc2b20b0de542127067226228b5a1014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0538198b0cf8a836731ca3c467a9ad455d68d7a3c61368fd768c6cd5080d0b6490e79156ba4341b7027c1a132c82e0e28fc6596393eb24e393b615b2129358b
|
7
|
+
data.tar.gz: b1fecfb1371885c65b9bb0a09c641b1a6e1fc217074de4f44a5fa88f7c14b973c9a322dd84996acc82506ab4303111baabd6de0cfdf6241456a5ccb841436f12
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Grooveshark API
|
2
2
|
|
3
|
-
Unofficial grooveshark API ruby library gives your ability to search and stream songs,
|
3
|
+
Unofficial grooveshark API ruby library gives your ability to search and stream songs,
|
4
4
|
manage playlists, media library and favorites.
|
5
5
|
API was discovered using http proxy and does not pretend to be always valid due to website API changes.
|
6
6
|
|
@@ -23,10 +23,10 @@ And install bundle:
|
|
23
23
|
```
|
24
24
|
bundle install
|
25
25
|
```
|
26
|
-
|
26
|
+
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
First, you'll need to create a session. Grooveshark's session is a
|
29
|
+
First, you'll need to create a session. Grooveshark's session is a
|
30
30
|
regular PHP session with expiration date of 7 days.
|
31
31
|
|
32
32
|
```ruby
|
@@ -34,24 +34,24 @@ require 'grooveshark'
|
|
34
34
|
|
35
35
|
client = Grooveshark::Client.new
|
36
36
|
```
|
37
|
-
|
37
|
+
|
38
38
|
To get session key just call
|
39
39
|
|
40
40
|
```
|
41
41
|
session = client.session
|
42
42
|
```
|
43
|
-
|
43
|
+
|
44
44
|
You can store this key for 7 days after creation and use it like this:
|
45
45
|
|
46
46
|
```
|
47
47
|
client = Grooveshark::Client.new(SESSION_KEY)
|
48
48
|
```
|
49
|
-
|
49
|
+
|
50
50
|
Now we can find some songs:
|
51
|
-
|
51
|
+
|
52
52
|
```ruby
|
53
53
|
songs = client.search_songs('Nirvana')
|
54
|
-
|
54
|
+
|
55
55
|
songs.each do |s|
|
56
56
|
s.id # Song ID
|
57
57
|
s.name # Song name
|
@@ -60,7 +60,7 @@ songs.each do |s|
|
|
60
60
|
s.duration # Song duration in seconds (not always present, 0 by default)
|
61
61
|
end
|
62
62
|
```
|
63
|
-
|
63
|
+
|
64
64
|
We got collection of songs. Check Song object for additional attributes.
|
65
65
|
In order to stream song we need to get the authorization
|
66
66
|
|
@@ -71,7 +71,7 @@ url = client.get_song_url(song)
|
|
71
71
|
|
72
72
|
Given url is valid only for current session and cannot be shared or stored permanently.
|
73
73
|
Also, it probably violates terms of service.
|
74
|
-
|
74
|
+
|
75
75
|
### User Authentication
|
76
76
|
|
77
77
|
To get your user account you need to provide username and password.
|
@@ -79,7 +79,7 @@ If username or password is not valid InvalidAuthentication exception will be rai
|
|
79
79
|
|
80
80
|
```ruby
|
81
81
|
client = Grooveshark::Client.new
|
82
|
-
|
82
|
+
|
83
83
|
begin
|
84
84
|
user = client.login('username', 'password')
|
85
85
|
rescue InvalidAuthentication
|
@@ -98,15 +98,15 @@ user.playlists.each do |p|
|
|
98
98
|
p.about # Playlist description (empty by default)
|
99
99
|
end
|
100
100
|
```
|
101
|
-
|
101
|
+
|
102
102
|
Get user playlist:
|
103
103
|
|
104
104
|
```ruby
|
105
105
|
playlist = user.get_playlist(PLAYLIST_ID)
|
106
106
|
```
|
107
|
-
|
107
|
+
|
108
108
|
Get all playlist songs:
|
109
|
-
|
109
|
+
|
110
110
|
```ruby
|
111
111
|
playlist = user.get_playlist(ID)
|
112
112
|
playlist.load_songs
|
@@ -126,21 +126,21 @@ Delete existing user playlist
|
|
126
126
|
playlist = user.get_playlist(ID)
|
127
127
|
playlist.delete
|
128
128
|
```
|
129
|
-
|
129
|
+
|
130
130
|
Create a new playlist. First parameter is mandatory, description and songs are optional.
|
131
131
|
For songs you can provide array of Song objects or array of IDs.
|
132
|
-
|
133
|
-
```ruby
|
132
|
+
|
133
|
+
```ruby
|
134
134
|
songs = client.search_songs('Joe Satriani')
|
135
135
|
p = user.create_playlist('NAME', 'DESCRIPTION', songs)
|
136
136
|
```
|
137
|
-
|
137
|
+
|
138
138
|
Get user favorite songs:
|
139
139
|
|
140
140
|
```ruby
|
141
141
|
songs = user.favorites
|
142
142
|
```
|
143
|
-
|
143
|
+
|
144
144
|
Add song to favorites:
|
145
145
|
|
146
146
|
```ruby
|
@@ -152,7 +152,40 @@ Remove song from favorites:
|
|
152
152
|
```ruby
|
153
153
|
user.remove_favorite(song) # Song object or song ID
|
154
154
|
```
|
155
|
-
|
155
|
+
|
156
|
+
### Broadcasts
|
157
|
+
|
158
|
+
Get top broadcasts:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
client.top_broadcasts.each do |b|
|
162
|
+
b.id # Broadcast ID
|
163
|
+
b.name # Broadcast Name
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
To reload the current status of the broadcast (e.g. currently playing song,
|
168
|
+
next song, etc.), call `reload_status` method:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
broadcast.reload_status
|
172
|
+
```
|
173
|
+
|
174
|
+
Get the current and next song for a broadcast:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
current_song = broadcast.active_song
|
178
|
+
next_song = broadcast.next_song
|
179
|
+
```
|
180
|
+
|
181
|
+
Check whether the broadcast is currently playing:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
if broadcast.is_playing
|
185
|
+
# Do something e.g. get the currently playing song.
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
156
189
|
### User library
|
157
190
|
|
158
191
|
Get all songs from library as a collection of Song objects
|
@@ -160,23 +193,23 @@ Get all songs from library as a collection of Song objects
|
|
160
193
|
```ruby
|
161
194
|
songs = user.library
|
162
195
|
```
|
163
|
-
|
196
|
+
|
164
197
|
Add songs to library:
|
165
198
|
|
166
199
|
```ruby
|
167
200
|
songs = client.search_songs('The Beatles')
|
168
201
|
user.library_add(songs)
|
169
202
|
```
|
170
|
-
|
171
|
-
Remove selected songs from library.
|
172
|
-
Unfortunately mass-deletion is not supported by Grooveshark API.
|
203
|
+
|
204
|
+
Remove selected songs from library.
|
205
|
+
Unfortunately mass-deletion is not supported by Grooveshark API.
|
173
206
|
You will have to delete each song via separate method call.
|
174
207
|
|
175
208
|
```ruby
|
176
209
|
song = user.library.first # Lest pick a first song in the library
|
177
210
|
user.library_remove(song)
|
178
211
|
```
|
179
|
-
|
212
|
+
|
180
213
|
### Explore community
|
181
214
|
|
182
215
|
Get all recently active users:
|
@@ -184,35 +217,25 @@ Get all recently active users:
|
|
184
217
|
```ruby
|
185
218
|
client.recent_users
|
186
219
|
```
|
187
|
-
|
220
|
+
|
188
221
|
Find user by ID:
|
189
222
|
|
190
223
|
```ruby
|
191
224
|
client.get_user_by_id('ID')
|
192
225
|
```
|
193
|
-
|
226
|
+
|
194
227
|
Find user by username:
|
195
228
|
|
196
229
|
```ruby
|
197
230
|
client.get_user_by_username('username')
|
198
231
|
```
|
199
|
-
|
232
|
+
|
200
233
|
Fetch recent user activity:
|
201
234
|
|
202
235
|
```ruby
|
203
236
|
user = client.get_user_by_username('user')
|
204
237
|
user.feed
|
205
238
|
```
|
206
|
-
|
207
|
-
## Known issues
|
208
|
-
|
209
|
-
- Communication token gets rejected after some time. This timeframe is always different. Additional research didnt show any results.
|
210
|
-
|
211
|
-
## TODO
|
212
|
-
|
213
|
-
- Testing
|
214
|
-
- Library management coverage
|
215
|
-
- More methods
|
216
239
|
|
217
240
|
## Testing
|
218
241
|
|
data/grooveshark.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path(
|
2
|
+
require File.expand_path("../lib/grooveshark/version", __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "grooveshark"
|
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
17
|
-
s.require_paths = [
|
17
|
+
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_development_dependency
|
20
|
-
s.add_development_dependency
|
19
|
+
s.add_development_dependency "rspec", "~> 2.12"
|
20
|
+
s.add_development_dependency "rake", "~> 10.0"
|
21
21
|
|
22
|
-
s.add_runtime_dependency
|
23
|
-
s.add_runtime_dependency
|
24
|
-
s.add_runtime_dependency
|
22
|
+
s.add_runtime_dependency "json", ">= 1.4.6"
|
23
|
+
s.add_runtime_dependency "rest-client", ">= 1.5.1"
|
24
|
+
s.add_runtime_dependency "uuid", "~> 2.0"
|
25
25
|
end
|
data/lib/grooveshark.rb
CHANGED
@@ -3,9 +3,11 @@ require 'json'
|
|
3
3
|
require 'rest-client'
|
4
4
|
require 'uuid'
|
5
5
|
|
6
|
+
require 'grooveshark/version'
|
6
7
|
require 'grooveshark/utils'
|
7
8
|
require 'grooveshark/errors'
|
8
9
|
require 'grooveshark/client'
|
9
10
|
require 'grooveshark/user'
|
10
11
|
require 'grooveshark/playlist'
|
11
12
|
require 'grooveshark/song'
|
13
|
+
require 'grooveshark/broadcast'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Grooveshark
|
2
|
+
class Broadcast
|
3
|
+
attr_reader :id, :user_ids
|
4
|
+
attr_reader :is_active, :is_playing
|
5
|
+
attr_reader :name, :usernames
|
6
|
+
attr_reader :active_song, :next_song
|
7
|
+
|
8
|
+
def initialize(client, broadcast_id=nil, data=nil)
|
9
|
+
@client = client
|
10
|
+
|
11
|
+
if broadcast_id
|
12
|
+
@id = broadcast_id
|
13
|
+
reload_status()
|
14
|
+
elsif data
|
15
|
+
@id = data['broadcast_id'] || broadcast_id
|
16
|
+
@name = data['name']
|
17
|
+
@is_playing = data['is_playing'] == 1 ? true : false
|
18
|
+
@is_active = data['is_active']
|
19
|
+
@active_song = Song.new(data['active_song'])
|
20
|
+
@next_song = Song.new(data['next_song'])
|
21
|
+
@usernames = data['usernames']
|
22
|
+
@user_ids = data['owner_user_i_ds']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Reload broadcast status
|
27
|
+
# Returns true on success. Otherwise false.
|
28
|
+
def reload_status
|
29
|
+
initialize(
|
30
|
+
@client, nil,
|
31
|
+
@client.request('broadcastStatusPoll', {:broadcastID => id})
|
32
|
+
)
|
33
|
+
true
|
34
|
+
rescue
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/grooveshark/client.rb
CHANGED
@@ -2,13 +2,13 @@ module Grooveshark
|
|
2
2
|
class Client
|
3
3
|
attr_accessor :session, :comm_token
|
4
4
|
attr_reader :user, :comm_token_ttl, :country
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(params = {})
|
7
7
|
@ttl = params[:ttl] || 120 # 2 minutes
|
8
8
|
@uuid = UUID.new.generate.upcase
|
9
9
|
get_token_data
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# Authenticate user
|
13
13
|
def login(user, password)
|
14
14
|
data = request('authenticateUser', {:username => user, :password => password}, true)
|
@@ -16,47 +16,62 @@ module Grooveshark
|
|
16
16
|
raise InvalidAuthentication, 'Wrong username or password!' if @user.id == 0
|
17
17
|
return @user
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Find user by ID
|
21
21
|
def get_user_by_id(id)
|
22
22
|
resp = request('getUserByID', {:userID => id})['user']
|
23
23
|
resp['username'].empty? ? nil : User.new(self, resp)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Find user by username
|
27
27
|
def get_user_by_username(name)
|
28
28
|
resp = request('getUserByUsername', {:username => name})['user']
|
29
29
|
resp['username'].empty? ? nil : User.new(self, resp)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# Get recently active users
|
33
33
|
def recent_users
|
34
34
|
request('getRecentlyActiveUsers', {})['users'].map { |u| User.new(self, u) }
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# Get popular songs
|
38
38
|
# type => daily, monthly
|
39
39
|
def popular_songs(type='daily')
|
40
40
|
raise ArgumentError, 'Invalid type' unless ['daily', 'monthly'].include?(type)
|
41
41
|
request('popularGetSongs', {:type => type})['songs'].map { |s| Song.new(s) }
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
|
+
# Get top broadcasts
|
45
|
+
# count => specifies how many broadcasts to get
|
46
|
+
def top_broadcasts(count=10)
|
47
|
+
top_broadcasts = []
|
48
|
+
request('getTopBroadcastsCombined').each do |key,val|
|
49
|
+
broadcast_id = key.split(':')[1]
|
50
|
+
top_broadcasts.push(Broadcast.new(self, broadcast_id))
|
51
|
+
count -= 1
|
52
|
+
if count == 0
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
return top_broadcasts
|
57
|
+
end
|
58
|
+
|
44
59
|
# Perform search request for query
|
45
60
|
def search(type, query)
|
46
61
|
results = request('getResultsFromSearch', {:type => type, :query => query})['result']
|
47
62
|
results.map { |song| Song.new song }
|
48
63
|
end
|
49
|
-
|
64
|
+
|
50
65
|
# Perform songs search request for query
|
51
66
|
def search_songs(query)
|
52
67
|
search('Songs', query)
|
53
68
|
end
|
54
|
-
|
69
|
+
|
55
70
|
# Return raw response for songs search request
|
56
71
|
def search_songs_pure(query)
|
57
72
|
request('getSearchResultsEx', {:type => 'Songs', :query => query})
|
58
73
|
end
|
59
|
-
|
74
|
+
|
60
75
|
# Get stream authentication by song ID
|
61
76
|
def get_stream_auth_by_songid(song_id)
|
62
77
|
result = request('getStreamKeyFromSongIDEx', {
|
@@ -71,7 +86,7 @@ module Grooveshark
|
|
71
86
|
end
|
72
87
|
result
|
73
88
|
end
|
74
|
-
|
89
|
+
|
75
90
|
# Get stream authentication for song object
|
76
91
|
def get_stream_auth(song)
|
77
92
|
get_stream_auth_by_songid(song.id)
|
@@ -82,7 +97,7 @@ module Grooveshark
|
|
82
97
|
resp = get_stream_auth_by_songid(id)
|
83
98
|
"http://#{resp['ip']}/stream.php?streamKey=#{resp['stream_key']}"
|
84
99
|
end
|
85
|
-
|
100
|
+
|
86
101
|
# Get song stream
|
87
102
|
def get_song_url(song)
|
88
103
|
get_song_url_by_id(song.id)
|
@@ -105,7 +120,7 @@ module Grooveshark
|
|
105
120
|
@country = config['country']
|
106
121
|
@session = config['sessionID']
|
107
122
|
end
|
108
|
-
|
123
|
+
|
109
124
|
# Sign method
|
110
125
|
def create_token(method)
|
111
126
|
rnd = get_random_hex_chars(6)
|
@@ -153,7 +168,7 @@ module Grooveshark
|
|
153
168
|
data['result']
|
154
169
|
end
|
155
170
|
end
|
156
|
-
|
171
|
+
|
157
172
|
# Refresh communications token on ttl
|
158
173
|
def refresh_token
|
159
174
|
get_token_data if Time.now.to_i - @comm_token_ttl > @ttl
|
data/lib/grooveshark/errors.rb
CHANGED
@@ -2,15 +2,15 @@ module Grooveshark
|
|
2
2
|
class InvalidAuthentication < Exception ; end
|
3
3
|
class ReadOnlyAccess < Exception ; end
|
4
4
|
class GeneralError < Exception ; end
|
5
|
-
|
5
|
+
|
6
6
|
class ApiError < Exception
|
7
7
|
attr_reader :code
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(fault)
|
10
10
|
@code = fault['code']
|
11
11
|
@message = fault['message']
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def to_s
|
15
15
|
"#{@code} - #{@message}"
|
16
16
|
end
|
data/lib/grooveshark/playlist.rb
CHANGED
@@ -3,11 +3,11 @@ module Grooveshark
|
|
3
3
|
attr_reader :id, :user_id
|
4
4
|
attr_reader :name, :about, :picture, :username
|
5
5
|
attr_reader :songs
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(client, data=nil, user_id=nil)
|
8
8
|
@client = client
|
9
9
|
@songs = []
|
10
|
-
|
10
|
+
|
11
11
|
if data
|
12
12
|
@id = data['playlist_id']
|
13
13
|
@name = data['name']
|
@@ -23,7 +23,7 @@ module Grooveshark
|
|
23
23
|
@songs = @client.request('getPlaylistByID', :playlistID => @id)['songs']
|
24
24
|
@songs.map! { |s| Song.new(s) }
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Rename playlist
|
28
28
|
def rename(name, description)
|
29
29
|
begin
|
@@ -35,7 +35,7 @@ module Grooveshark
|
|
35
35
|
return false
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# Delete existing playlist
|
40
40
|
def delete
|
41
41
|
@client.request('deletePlaylist', {:playlistID => @id, :name => @name})
|
data/lib/grooveshark/song.rb
CHANGED
@@ -4,7 +4,7 @@ module Grooveshark
|
|
4
4
|
attr_reader :id, :artist_id, :album_id
|
5
5
|
attr_reader :name, :artist, :album, :track, :year
|
6
6
|
attr_reader :duration, :artwork, :playcount
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(data=nil)
|
9
9
|
unless data.nil?
|
10
10
|
@data = data
|
@@ -21,12 +21,12 @@ module Grooveshark
|
|
21
21
|
@year = data['year']
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Presentable format
|
26
26
|
def to_s
|
27
27
|
[@id, @name, @artist].join(' - ')
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Hash export for API usage
|
31
31
|
def to_hash
|
32
32
|
{
|
data/lib/grooveshark/user.rb
CHANGED
@@ -18,64 +18,64 @@ module Grooveshark
|
|
18
18
|
end
|
19
19
|
@client = client
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Get user avatar URL
|
23
23
|
def avatar
|
24
24
|
"http://images.grooveshark.com/static/userimages/#{@id}.jpg"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Get user activity for the date (COMES AS RAW RESPONSE)
|
28
28
|
def feed(date=nil)
|
29
29
|
date = Time.now if date.nil?
|
30
30
|
@client.request('getProcessedUserFeedData', {:userID => @id, :day => date.strftime("%Y%m%d")})
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# --------------------------------------------------------------------------
|
34
34
|
# User Library
|
35
35
|
# --------------------------------------------------------------------------
|
36
|
-
|
37
|
-
# Fetch songs from library
|
36
|
+
|
37
|
+
# Fetch songs from library
|
38
38
|
def library(page=0)
|
39
39
|
resp = @client.request('userGetSongsInLibrary', {:userID => @id, :page => page.to_s})['songs']
|
40
40
|
resp.map { |s| Song.new(s) }
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# Add songs to user's library
|
44
44
|
def library_add(songs=[])
|
45
45
|
@client.request('userAddSongsToLibrary', {:songs => songs.map { |s| s.to_hash }})
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# Remove song from user library
|
49
49
|
def library_remove(song)
|
50
50
|
raise ArgumentError, 'Song object required' unless song.kind_of?(Song)
|
51
51
|
req = {:userID => @id, :songID => song.id, :albumID => song.album_id, :artistID => song.artist_id}
|
52
52
|
@client.request('userRemoveSongFromLibrary', req)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# Get library modification time
|
56
56
|
def library_ts_modified
|
57
57
|
@client.request('userGetLibraryTSModified', {:userID => @id})
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# --------------------------------------------------------------------------
|
61
61
|
# User Playlists
|
62
62
|
# --------------------------------------------------------------------------
|
63
|
-
|
63
|
+
|
64
64
|
# Fetch user playlists
|
65
65
|
def playlists
|
66
66
|
return @playlists if @playlists
|
67
67
|
results = @client.request('userGetPlaylists', :userID => @id)
|
68
68
|
@playlists = results['playlists'].map { |list| Playlist.new(@client, list, @id) }
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# Get playlist by ID
|
72
72
|
def get_playlist(id)
|
73
73
|
result = playlists.select { |p| p.id == id }
|
74
74
|
result.nil? ? nil : result.first
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
alias :playlist :get_playlist
|
78
|
-
|
78
|
+
|
79
79
|
# Create new user playlist
|
80
80
|
def create_playlist(name, description='', songs=[])
|
81
81
|
@client.request('createPlaylist', {
|
@@ -84,24 +84,24 @@ module Grooveshark
|
|
84
84
|
'songIDs' => songs.map { |s| s.kind_of?(Song) ? s.id : s.to_s }
|
85
85
|
})
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# --------------------------------------------------------------------------
|
89
89
|
# User Favorites
|
90
90
|
# --------------------------------------------------------------------------
|
91
|
-
|
91
|
+
|
92
92
|
# Get user favorites
|
93
93
|
def favorites
|
94
94
|
return @favorites if @favorites
|
95
95
|
resp = @client.request('getFavorites', :ofWhat => 'Songs', :userID => @id)
|
96
96
|
@favorites = resp.map { |s| Song.new(s) }
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
# Add song to favorites
|
100
100
|
def add_favorite(song)
|
101
101
|
song_id = song.kind_of?(Song) ? song.id : song
|
102
102
|
@client.request('favorite', {:what => 'Song', :ID => song_id})
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Remove song from favorites
|
106
106
|
def remove_favorite(song)
|
107
107
|
song_id = song.kind_of?(Song) ? song.id : song
|
data/lib/grooveshark/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Grooveshark::Broadcast do
|
4
|
+
let(:client) { Grooveshark::Client.new }
|
5
|
+
|
6
|
+
describe "search" do
|
7
|
+
let(:result) { client.top_broadcasts(10) }
|
8
|
+
|
9
|
+
it "returns an array" do
|
10
|
+
expect(result).to be_an Array
|
11
|
+
expect(result.size).to eq 10
|
12
|
+
end
|
13
|
+
|
14
|
+
it "includes brodcasts" do
|
15
|
+
all = result.all? { |item| item.kind_of?(Grooveshark::Broadcast) }
|
16
|
+
expect(all).to be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "broadcast" do
|
21
|
+
let(:broadcast) { client.top_broadcasts.first }
|
22
|
+
|
23
|
+
it "has a valid id" do
|
24
|
+
expect(broadcast.id).to match /^[abcdef\d]{24}$/i
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#active_song" do
|
28
|
+
it "is a song instance" do
|
29
|
+
expect(broadcast.active_song).to be_a Grooveshark::Song
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#next_song" do
|
34
|
+
it "is a song instance" do
|
35
|
+
expect(broadcast.active_song).to be_a Grooveshark::Song
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
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.11
|
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-
|
11
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- grooveshark.gemspec
|
96
96
|
- lib/grooveshark.rb
|
97
|
+
- lib/grooveshark/broadcast.rb
|
97
98
|
- lib/grooveshark/client.rb
|
98
99
|
- lib/grooveshark/errors.rb
|
99
100
|
- lib/grooveshark/playlist.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- lib/grooveshark/user.rb
|
102
103
|
- lib/grooveshark/utils.rb
|
103
104
|
- lib/grooveshark/version.rb
|
105
|
+
- spec/broadcast_spec.rb
|
104
106
|
- spec/client_spec.rb
|
105
107
|
- spec/helper.rb
|
106
108
|
- spec/utils_spec.rb
|
@@ -129,6 +131,7 @@ signing_key:
|
|
129
131
|
specification_version: 4
|
130
132
|
summary: Grooveshark API
|
131
133
|
test_files:
|
134
|
+
- spec/broadcast_spec.rb
|
132
135
|
- spec/client_spec.rb
|
133
136
|
- spec/helper.rb
|
134
137
|
- spec/utils_spec.rb
|