Skip to content

Instantly share code, notes, and snippets.

@track8
Last active August 29, 2015 14:14
Show Gist options
  • Save track8/f2dfc9b4fcaadeb93c8c to your computer and use it in GitHub Desktop.
Save track8/f2dfc9b4fcaadeb93c8c to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'open_uri_redirections'
require 'soundcloud'
OUTDIR = 'user48736353001'
Dir.mkdir(OUTDIR) unless Dir.exists? OUTDIR
def save(title, download_url)
puts title
file_name = "#{OUTDIR}/#{title}.mp3"
return if File.exist? file_name
open(file_name, 'wb') do |f|
open(download_url, :allow_redirections => :all) { |data| f.write(data.read) }
end
end
client = SoundCloud.new(:client_id => 'YOUR_CLIENT_ID')
tracks = client.get('/users/user48736353001/tracks', :limit => 200)
tracks.each do |track|
t = client.get("/tracks/#{track.id}")
save(t.title, "#{t.download_url}?client_id=#{client.client_id}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment