class SpotifyToMp3::Grooveshark
Public Class Methods
new(client)
click to toggle source
# File lib/spotify_to_mp3/grooveshark.rb, line 6 def initialize(client) @client = client end
Public Instance Methods
download(options)
click to toggle source
# File lib/spotify_to_mp3/grooveshark.rb, line 15 def download(options) track = options.fetch(:track) on_response = options.fetch(:on_response) on_body_chunk = options.fetch(:on_body_chunk) url = URI(@client.get_song_url(track.client_track)) Net::HTTP.start(url.host) do |http| http.request_post("#{url.path}?#{url.query}", "") do |response| on_response.call(response) File.open(track.filename, 'w') do |f| response.read_body do |chunk| on_body_chunk.call(chunk) f.write(chunk) end end end end end
get_track(query)
click to toggle source
# File lib/spotify_to_mp3/grooveshark.rb, line 10 def get_track(query) client_track = @client.search_songs(query).first or raise "Track not found" Track.new(client_track) end