Skip to content

Instantly share code, notes, and snippets.

@pikesley
Last active July 15, 2017 11:06
Show Gist options
  • Select an option

  • Save pikesley/b2c8fcf11ce6f20c8e13c11ca6a40e79 to your computer and use it in GitHub Desktop.

Select an option

Save pikesley/b2c8fcf11ce6f20c8e13c11ca6a40e79 to your computer and use it in GitHub Desktop.
Rescue your SoundCloud tracks

You need a client_id, but if you don't already have one you might be shit out of luck because 'register a new app' now presents you with a Google Form and the message ***Please allow up to a month to receive an update on the outcome of your application*** ¯\_(ツ)_/¯

gem install httparty
gem install soundcloud

Fill in the client_id and your username, then run it. It will only download tracks that you've already marked as downloadable because who has time to mess with Oauth?

#!/usr/bin/env ruby
require 'fileutils'
require 'soundcloud'
require 'httparty'
CLIENT_ID = 'some_client_id'
USER = 'your_username'
cloud = SoundCloud.new client_id: CLIENT_ID
id = cloud.get("/users/#{USER}").id
tracks = cloud.get("/users/#{id}/tracks")
FileUtils.mkdir_p 'soundcloud_downloads'
tracks.each do |track|
if track.downloadable
puts "Downloading '#{track.title}'"
url = "#{track.download_url}?client_id=#{CLIENT_ID}"
File.open "soundcloud_downloads/#{track.permalink}.mp3", 'wb' do |f|
f.write HTTParty.get(url).body
end
else
puts "'#{track.title}' is not downloadable. Fix it at #{track.permalink_url}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment