Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 139 lines (86 sloc) 3.207 kB
44b98b0 @sosedoff documentation, gemspec
authored
1 = Grooveshark API
2
3 Unofficial grooveshark API ruby library gives your ability to search and stream songs,
4 manage playlists, media library and favorites.
5 API was discovered using http proxy and does not pretend to be always valid due to website API changes.
6
7 = Installation
8
9 gem install grooveshark
10
11 = Getting Started
12
13 Lets first create a session.
14 Grooveshark session is a regular PHP session with expiration date of 7 days.
15
16 require 'rubygems'
17 require 'grooveshark'
18
19 client = Grooveshark::Client.new
20
21 To get session key just call
22
23 session = client.session
24
25 You can store this key for 7 days after creation and use it like this:
26
27 client = Grooveshark::Client.new(SESSION_KEY)
28
29 Now we can find some songs:
30
31 songs = client.search_songs('Nirvana')
32
33 songs.each do |s|
34 s.id # Song ID
35 s.name # Song name
36 s.artist # Song artist name
37 s.album # Song album name
38 s.duration # Song duration in seconds (not always present, 0 by default)
39 end
40
41 We got collection of songs. Check Song object for additional attributes.
42 In order to stream song we need to get the authorization
43
44 song = songs.first
45 url = client.get_song_url(song)
46
47 Given url is valid only for current session and cannot be shared or stored permanently.
48 Also, it probably violates terms of service.
49
50 = User Authentication
51
52 To get your user account you need to provide username and password.
53 If username or password is not valid InvalidAuthentication exception will be raised.
54
55 client = Grooveshark::Client.new
56
57 begin
58 user = client.login('username', 'password')
59 rescue InvalidAuthentication
60 puts "Oooops! Wrong username or password"
61 end
62
63 = Playlists and favorites
64
65 Get all user playlists
66
67 user.playlists.each do |p|
68 p.id # Playlist ID
69 p.name # Playlist name
70 p.about # Playlist description (empty by default)
71 end
72
73 Get user playlist
74
75 playlist = user.get_playlist(PLAYLIST_ID)
76
77 Get all playlist songs
78
79 playlist = user.get_playlist(ID)
80 playlist.load_songs
81 songs = playlist.songs
82
83 Rename existing playlist
84
85 playlist = user.get_playlist(ID)
86 playlist.rename('NEW NAME', 'NEW DESCRIPTION')
87
88 Delete existing user playlist
89
90 playlist = user.get_playlist(ID)
91 playlist.delete
92
93 Create a new playlist. First parameter is mandatory, description and songs are optional.
94 For songs you can provide array of Song objects or array of IDs.
95
96 songs = client.search_songs('Joe Satriani')
97 p = user.create_playlist('NAME', 'DESCRIPTION', songs)
98
99 Get user favorite songs
100
101 songs = user.favorites
102
103 Add song to favorites
104
105 user.add_favorite(song) # Song object or song ID
106
107 Remove song from favorites
108
109 user.remove_favorite(song) # Song object or song ID
fe93739 @sosedoff rdoc
authored
110
111 = Explore community
112
113 Get all recently active users
114
115 client.recent_users
116
117 Find user by ID
118
119 client.get_user_by_id('ID')
120
121 Find user by username
122
123 client.get_user_by_username('username')
124
125 Fetch recent user activity
126
127 user = client.get_user_by_username('user')
128 user.feed
44b98b0 @sosedoff documentation, gemspec
authored
129
130 = TODO
131
132 * Testing
133 * Library management coverage
134 * More methods
135
136 = Credits
137
138 * Dan Sosedoff - http://github.com/sosedoff
139 * Daniel Lamando - http://github.com/danopia
Something went wrong with that request. Please try again.