Skip to content
This repository has been archived by the owner on Jun 1, 2019. It is now read-only.

Commit

Permalink
Moved all GrooveShark module libraries into 'grooveshark' directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent authored and danopia committed Aug 17, 2010
1 parent 1406d44 commit 6654733
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
53 changes: 27 additions & 26 deletions client.rb → grooveshark/client.rb
Expand Up @@ -11,30 +11,30 @@ class Client
include DRbUndumped
attr_accessor :session, :comm_token, :queue, :now_playing, :player, :display, :use_aoss
attr_reader :user, :sock, :secure_sock, :volume

UUID = '996A915E-4C56-6BE2-C59F-96865F748EAE'
CLIENT = 'gslite'
CLIENT_REV = '20100412.09'

# "country":{"CC1":"0","CC3":"0","ID":"223","CC2":"0","CC4":"1073741824"}

COWBELL = 'cowbell.grooveshark.com'

def initialize session=nil
@session = session || get_session

@sock = JSONSock.new "http://#{COWBELL}/", @session
@secure_sock = JSONSock.new "https://#{COWBELL}/", @session

get_comm_token
@queue = create_queue

@volume = 90
@premium = false
@playlists = {}
@favorites = []
end

def request page, method, parameters=nil, secure=false
url = "/#{page}.php?#{method}"
request = {
Expand All @@ -49,72 +49,72 @@ def request page, method, parameters=nil, secure=false
'parameters' => parameters,
}
request['header']['token'] = create_token(method) if @comm_token

if secure
data = @secure_sock.post url, request
else
data = @sock.post url, request
end

# maybe they have a use :P
puts "Have #{data['header']['alerts'].size} alerts" if data['header'] && data['header']['alerts'] && data['header']['alerts'].size != 2

return data['result'] unless data['fault']

if data['fault']['code'] == 256
$sock.puts "Getting new token" if $sock
sleep 1
get_comm_token
sleep 1
return request(page, method, parameters)
end

raise "Grooveshark returned fault code #{data['fault']['code']}: #{data['fault']['message']}"
end

# These refer to the two different pages that cowbell uses.
def request_service *params
request 'service', *params
end
def request_more *params
request 'more', *params
end

def get_session
page = open('http://listen.grooveshark.com/').read
page =~ /sessionID: '([0-9a-f]+)'/
$1
end

def create_queue
Queue.new self
end

def login user, pass
@user = User.login self, user, pass
end

def get_comm_token
@comm_token = nil # so that it doesn't send a token
@comm_token = request_service 'getCommunicationToken', {:secretKey => Digest::MD5.hexdigest(@session)}, true
end

# shhhhhhh!
def create_token method
rnd = rand(256**3).to_s(16).rjust(6, '0')
plain = [method, @comm_token, 'quitStealinMahShit', rnd].join(':')
hash = Digest::SHA1.hexdigest plain
"#{rnd}#{hash}"
end

def search type, query
results = request_more 'getSearchResults', {:type => type, :query => query}
results.map {|song| Song.new song }
end
def search_songs query
search 'Songs', query
end

# streamKey, streamServer, streamServerID
def get_stream_auth song
results = request_more 'getStreamKeyFromSongIDEx', {
Expand All @@ -125,31 +125,32 @@ def get_stream_auth song
}
results#['result']
end

def play song
@display.driver.set_title song.to_s

@display.panes[:np].controls[:song_name].text = song.to_s
@display.panes[:np].controls[:cue].value = 0
@display.panes[:np].controls[:cue].maximum = 1
@display.panes[:np].controls[:cue].value2 = 0
@display.panes[:np].controls[:cue].maximum2 = song.duration
@display.dirty! :np

@now_playing = song
key = get_stream_auth song
# {"uSecs":"273000000","FileToken":"1Uz0O8","streamKey":"9b90e6f64695493ca930","streamServerID":16384,"ip":"stream36akm.grooveshark.com"}
MPlayer.stream key['ip'], key['streamKey'], self
@now_playing = nil
@player = nil
end

def volume= vol
@volume = vol

if @player
@player.process.puts "volume #{@volume} 1"
end
end
end
end

13 changes: 7 additions & 6 deletions json_sock.rb → grooveshark/json_sock.rb
Expand Up @@ -8,31 +8,32 @@ module GrooveShark
class JSONSock
attr_reader :http, :uri
attr_accessor :session

def initialize server, session=nil
@session = session

@uri = URI.parse server
@http = Net::HTTP.new @uri.host, @uri.port
@http.use_ssl = true if ssl?
end

def ssl?; @uri.scheme == 'https'; end

def post url, data
url = @uri + URI.parse(url)
req = Net::HTTP::Post.new url.request_uri, headers
res = @http.request req, data.to_json
$sock.puts res.body if $sock
JSON.parse res.body
end

def headers
{'Content-type' => 'application/json', 'Cookie' => "PHPSESSID=#{@session}"}
end

def close
@http.finish if @http.started?
end
end
end

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions remora
Expand Up @@ -39,10 +39,10 @@ end
require 'rubygems'
require 'luck'

require File.join(File.dirname(__FILE__), 'client')
require File.join(File.dirname(__FILE__), 'user')
require File.join(File.dirname(__FILE__), 'playlist')
require File.join(File.dirname(__FILE__), 'song')
require File.join(File.dirname(__FILE__), 'grooveshark', 'client')
require File.join(File.dirname(__FILE__), 'grooveshark', 'user')
require File.join(File.dirname(__FILE__), 'grooveshark', 'playlist')
require File.join(File.dirname(__FILE__), 'grooveshark', 'song')
require File.join(File.dirname(__FILE__), 'mplayer')

require File.join(File.dirname(__FILE__), 'panes', 'login')
Expand Down

0 comments on commit 6654733

Please sign in to comment.