Giter VIP home page Giter VIP logo

grooveshark's Introduction

Grooveshark

GROOVESHARK.COM HAS BEEN TERMINATED ON APRIL 30, 2015

Unofficial grooveshark API ruby library gives your ability to search and stream songs, manage playlists, media library and favorites. API was discovered using http proxy and does not pretend to be always valid due to website API changes.

Build Status Gem

Installation

Install gem from rubygems:

gem install grooveshark

Or add this line to your Gemfile:

gem "grooveshark"

And install bundle:

bundle install

Usage

First, you'll need to create a session. Grooveshark's session is a regular PHP session with expiration date of 7 days.

require 'grooveshark'

client = Grooveshark::Client.new

Now we can find some songs:

songs = client.search_songs('Nirvana')

songs.each do |s|
  s.id          # Song ID
  s.name        # Song name
  s.artist      # Song artist name
  s.album       # Song album name
  s.duration    # Song duration in seconds (not always present, 0 by default)
end

We got collection of songs. Check Song object for additional attributes. In order to stream song we need to get the authorization

song = songs.first
url = client.get_song_url(song)

Given url is valid only for current session and cannot be shared or stored permanently. Also, it probably violates terms of service.

User Authentication

To get your user account you need to provide username and password. If username or password is not valid InvalidAuthentication exception will be raised.

client = Grooveshark::Client.new

begin
  user = client.login('username', 'password')
rescue InvalidAuthentication
  puts "Oooops! Wrong username or password"
end

Playlists and favorites

Get all user playlists:

user.playlists.each do |p|
  p.id          # Playlist ID
  p.name        # Playlist name
  p.about       # Playlist description (empty by default)
end

Get user playlist:

playlist = user.get_playlist(PLAYLIST_ID)

Get all playlist songs:

playlist = user.get_playlist(ID)
playlist.load_songs
songs = playlist.songs

Rename existing playlist:

playlist = user.get_playlist(ID)
playlist.rename('NEW NAME', 'NEW DESCRIPTION')

Delete existing user playlist

playlist = user.get_playlist(ID)
playlist.delete

Create a new playlist. First parameter is mandatory, description and songs are optional. For songs you can provide array of Song objects or array of IDs.

songs = client.search_songs('Joe Satriani')
p = user.create_playlist('NAME', 'DESCRIPTION', songs)

Get user favorite songs:

songs = user.favorites

Add song to favorites:

user.add_favorite(song) # Song object or song ID

Remove song from favorites:

user.remove_favorite(song) # Song object or song ID

Broadcasts

Get top broadcasts:

client.top_broadcasts.each do |b|
  b.id                # Broadcast ID
  b.name              # Broadcast Name
end

To reload the current status of the broadcast (e.g. currently playing song, next song, etc.), call reload_status method:

broadcast.reload_status

Get the current and next song for a broadcast:

current_song = broadcast.active_song
next_song = broadcast.next_song

Check whether the broadcast is currently playing:

if broadcast.is_playing
  # Do something e.g. get the currently playing song.
end

User library

Get all songs from library as a collection of Song objects

songs = user.library

Add songs to library:

songs = client.search_songs('The Beatles')
user.library_add(songs)

Remove selected songs from library. Unfortunately mass-deletion is not supported by Grooveshark API. You will have to delete each song via separate method call.

song = user.library.first # Lest pick a first song in the library
user.library_remove(song)

Explore community

Get all recently active users:

client.recent_users

Find user by ID:

client.get_user_by_id('ID')

Find user by username:

client.get_user_by_username('username')

Fetch recent user activity:

user = client.get_user_by_username('user')
user.feed

Testing

Run test suite:

bundle exec rake

Contact

License

MIT License

Copyright (c) 2011-2015 Dan Sosedoff [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

grooveshark's People

Contributors

frosas avatar ga2arch avatar isaacsanders avatar mtahmed avatar pierrerambaud avatar samvasko avatar snake-poison avatar sosedoff avatar wat1444 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grooveshark's Issues

Use Travis CI

Hi,

Travis CI is usefull for executing tests such as rubocop or rspec. If you are ok I can do a refactoring to encapsulate functional tests and add unit tests + rubocop for checkstyle.

Regards

New release

Hi,
Can you release a new version for integrating latest bugs fixes.
Regards

Cannot make new session with session key

I followed the simple instructions in the README but could not have success using a session key.
I performed the command to get stream links for a song but could not actually play the song in my browser. Any idea how to fix this?

The trace from the session key attempt is below:

2.1.2 :001 > require 'grooveshark'

=> true

2.1.2 :002 > client = Grooveshark::Client.new

=> #<Grooveshark::Client:0x00000003ec46d8 @Ttl=120, @uuid="B2F32520-0CAE-0132-2407-201A068DBB95", @comm_token="73cd9646c66d2c807862b26791e5897c572ba7b0", @comm_token_ttl=1408769330, @Country={"ID"=>223, "CC1"=>0, "CC2"=>0, "CC3"=>0, "CC4"=>1073741824, "DMA"=>807, "iso"=>"US", "region"=>"CA", "city"=>"San Francisco", "zip"=

2.1.2 :002 > client = Grooveshark::Client.new

=> #<Grooveshark::Client:0x00000003ec46d8 @Ttl=120, @uuid="B2F32520-0CAE-0132-2407-201A068DBB95", @comm_token="73cd9646c66d2c807862b26791e5897c572ba7b0", @comm_token_ttl=1408769330, @Country={"ID"=>223, "CC1"=>0, "CC2"=>0, "CC3"=>0, "CC4"=>1073741824, "DMA"=>807, "iso"=>"US", "region"=>"CA", "city"=>"San Francisco", "zip"=>"94110", "IPR"=>0}, @session="3d17c63f4ec8f7028753c4ea0c9dcfd2">

2.1.2 :003 > session = client.session

=> "3d17c63f4ec8f7028753c4ea0c9dcfd2"

2.1.2 :004 > client = Grooveshark::Client.new(session)

TypeError: no implicit conversion of Symbol into Integer
from /home/max/.rvm/gems/ruby-2.1.2/gems/grooveshark-0.2.11/lib/grooveshark/client.rb:7:in []' from /home/max/.rvm/gems/ruby-2.1.2/gems/grooveshark-0.2.11/lib/grooveshark/client.rb:7:ininitialize'
from (irb):4:in new' from (irb):4 from /home/max/.rvm/rubies/ruby-2.1.2/bin/irb:11:in

'

License?

I cannot find any specified license for this project. Is there any? It might be an idea to add file that describes it.

playlist.load_songs error

When trying to fetch any playlist I get

C:/Ruby200/lib/ruby/gems/2.0.0/gems/grooveshark-0.2.8.1/lib/grooveshark/client.rb:151:in `request': 1024 -  invalid client (Grooveshark::ApiError)
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/grooveshark-0.2.8.1/lib/grooveshark/playlist.rb:23:in `load_songs'
        from C:/Users/Samuel/Desktop/gshark.rb:10:in `<main>'

Grooveshark::Client.new returns Grooveshark:ApiError

Here's an example in IRB:

>> client = Grooveshark::Client.new
Grooveshark::ApiError: 1024 -  invalid client
    from /usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.3/lib/grooveshark/request.rb:49:in `request'
    from /usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.3/lib/grooveshark/client.rb:30:in `get_comm_token'
    from /usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.3/lib/grooveshark/client.rb:16:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from /usr/bin/irb:12:in `<main>'

I am using grooveshark-0.2.3

New maintainer

Hi,

I built a project in python to for playing with grooveshark and download song (just to learn how to python). Now and after many months of playing with ruby, I want to migrate it in Ruby (because ruby is better) and want to use your library.
I read you need a new maintainer and I think I can do some thing about tests, checkstyle, CI (Travis), etc..

As I saw, you need to see some PR, so I will ;)

Regards

New Maintainer

Hey @sosedoff,

I am working on a new startup for music streaming, and we are currently using Grooveshark for our Music.

I am interested in maintaining the gem.

Help (Ubuntu)

so basically ive installed all the files needed now i just basically require help using the files if you could help id be most appreciative im down to the usage part but have no idea how to find the things it says

Getting banned

Before this API change, I wasn't getting banned, but I've been banned on two different IPs since. Anyone else having this issue? Probably something else that we need to change/add to make the client look legitimate?

edit:
On a happier note, I've managed to route session requests through Tor and am still able to access the streams from a banned IP address. (Although this is just a huge red flag probably)

gsConfig not found

I'm getting 'get_session_and_country': gsConfig not found now when I try to create a new session. This was working fine a few days ago. Did something change?

"invalid client" error from grooveshark

I get this error when trying to make a grooveshark request:

/usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.2/lib/grooveshark/request.rb:49:in `request': 1024 -  invalid client (Grooveshark::ApiError)
    from /usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:30:in `get_comm_token'
    from /usr/lib/ruby/gems/1.9.1/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:16:in `initialize'
    ...

Looking for maintainer

I dont use this project any more (its been a while) and im looking for someone that
could maintain it and lead any future developments. Grooveshark is a great service but i've had enough with its approach to present music data. One word - horrible.

Ping me if interested.

search_songs() raises a "can't convert String into Integer" error

Test code:

require 'grooveshark'

Grooveshark::Client.new.search_songs("this is a test")

Result:

$ ruby test.rb
/Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/song.rb:11:in `[]': can't convert String into Integer (TypeError)
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/song.rb:11:in `initialize'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:80:in `new'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:80:in `block in search'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:80:in `each'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:80:in `map'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:80:in `search'
    from /Users/frosas/.rvm/gems/ruby-1.9.2-p290/gems/grooveshark-0.2.2/lib/grooveshark/client.rb:85:in `search_songs'
    from test.rb:3:in `<main>'

Search returning JSON error

following the example from the readme:

songs = client.search_songs('Nirvana')

I get the following error:

JSON::ParserError: A JSON text must at least contain two octets!

Version info:
bundler/gems/grooveshark-06e3711f5576

Shutdown

Unfortunately, Grooveshark is no longer a service, as of today. I suggest updating the README to reflect this.

It was great while it lasted. :(

Example code not working

After authenticating successfully with user = client.login('username', 'passwords'), I cannot extract the user's playlist with user.playlist. I get the following error:
NoMethodError: private method 'request' called for #<Grooveshark::Client:0x0000000286a9c8> from /var/lib/gems/1.9.1/gems/grooveshark-0.2.8/lib/grooveshark/user.rb:67:in 'playlists'

I looked at your code and it seems to be correct.

The last time something like this happened when I was using a gem, it was because I was using the incorrect version of Ruby.

I am using Ruby 1.9.3 on Ubuntu 12.04. What is the version of Ruby that this library has been tested with?

Thank you for your time.

Session authorization does not work

Grooveshark has updated their way of generating communication token.

Current method does not work any more.

This needs to be fixed right away.

Release a new version

Hi,

Can you release a new version, there are some fixes in the latests commits.

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.