Last active
August 29, 2015 14:14
-
-
Save track8/f2dfc9b4fcaadeb93c8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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