Skip to content

Commit

Permalink
Hella messy. Basic jqTouch integration
Browse files Browse the repository at this point in the history
  • Loading branch information
melito committed Jan 6, 2010
1 parent 595f350 commit 2f1c748
Show file tree
Hide file tree
Showing 27 changed files with 665 additions and 41 deletions.
7 changes: 6 additions & 1 deletion README.mkdn
@@ -1 +1,6 @@
[melito](http://github.com/melito) is responsible for the hard parts
[melito](http://github.com/melito) is responsible for the hard parts

Status: Totally borked, don't use just yet. Have basic jqTouch integration in place.
Gonna start wiring up forms and the such right quick.
I like HAML, but it'll just get in the way right now.
Once this has better form I'll go back and clean everything up.
25 changes: 9 additions & 16 deletions groovedown.rb
Expand Up @@ -3,35 +3,28 @@
module Groovedown
class App < Sinatra::Base
helpers Groovedown::Helpers

if ENV['RACK_ENV'] == 'development'
use Rack::LessCss, :less_path => File.join(File.dirname(__FILE__), "views", "css", "less"),
:css_route => "/css"
use Rack::Evil
end

set :static, true
set :public, File.dirname(__FILE__) + "/public"

get '/' do
haml :index
erb :index
end

get '/search' do
redirect '/'
end

post '/search' do
post '/search' do
p params
@results = Result.find(params)
haml :search
end

get "/songs/:id" do
get "/songs/:id" do
@stream = Stream.new(params[:id])
if data = @stream.get
content_type "mp3"
attachment "#{params[:name]||params[:id]}.mp3"
halt data.to_s
else
"They don't like us. :("
end
throw :response, [200, {"Content-Type" => "audio/mpeg", "Content-Length" => @stream.length }, @stream]
end

end
end
1 change: 1 addition & 0 deletions libraries.rb
Expand Up @@ -5,6 +5,7 @@ def rubygem(file)
raise "** Please `gem install #{gem || file.split('/')[0]}`"
end

require "net/http"
rubygem 'sinatra/base'
rubygem 'haml'
rubygem 'rack-lesscss'
Expand Down
60 changes: 37 additions & 23 deletions models/stream.rb
Expand Up @@ -3,35 +3,49 @@ class Stream

def initialize(song_id)
@song_id = song_id
end

def get
song_id = @song_id.to_i

request = {
"header" => {
"clientRevision" => "20091209.02",
"client" => "gslite"},
"parameters" => {
"songID" => song_id,
"prefetch" => false },
"method" => "getStreamKeyFromSongID"
}
request = { "header" => { "clientRevision" => "20091209.02", "client" => "gslite"}, "parameters" => { "songID" => @song_id.to_i, "prefetch" => false }, "method" => "getStreamKeyFromSongID" }

response = RestClient.post("http://cowbell.grooveshark.com/more.php?getStreamKeyFromSongID",
request.to_json,
:content_type => "application/json")

stream_result = JSON.parse(response)["result"]["result"]
@stream_result = JSON.parse(response)["result"]["result"]
@stream_key = @stream_result["streamKey"]
@stream_server = @stream_result["streamServer"]
@stream_url = "http://#{@stream_server}/stream.php"
end

stream_key = stream_result["streamKey"]
stream_server = stream_result["streamServer"]
stream_url = "http://#{stream_server}/stream.php"
def length
@length.to_s ||= "0"
end

if stream_key
RestClient.post(stream_url,
:streamKey => stream_key,
:content_type => "application/x-www-form-urlencoded")
end
def each
url = URI.parse(@stream_url)
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'streamKey' => @stream_key})

#http = Net::HTTP.new(url.host, url.port)
#puts "curl -v -d 'streamKey=#{@stream_key}' #{@stream_url}"
#http.post(url.path, "streamKey=#{@stream_key}") do |chunk|
# @length = 0 if @length.nil?
# @length = chunk.size+4096
# #p @length
# p chunk.content_length
# yield chunk
#end

Net::HTTP.new(url.host, url.port).start do |http|
http.request(req) do |res|
@length = res.content_length

res.read_body do |chunk|
@length = @length# - chunk.size
yield chunk.to_s
end

end
end

end

end
Binary file added public/images/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/jqtouch/jqtouch.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/jqtouch/jqtouch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f1c748

Please sign in to comment.