Skip to content

Instantly share code, notes, and snippets.

@nilsding
Created January 17, 2016 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsding/556d55b2730acc01093b to your computer and use it in GitHub Desktop.
Save nilsding/556d55b2730acc01093b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# fetch_slam.rb - download all mp3s from comeonandsl.am
# (c) 2016 nilsding
# usage: ./fetch_slam.rb
# this script requires the HTTParty gem, install it via `gem install httparty'
require 'httparty'
require 'cgi'
AUDIO_BASE = 'http://comeonandsl.am/audio/'
slams = HTTParty.get('http://comeonandsl.am/data/slams.js').body.split(',').select{|x| x.end_with? "mp3\""}.map{|x| x.gsub(/^(?:var rgSlams=\[)?{file:"|"$/, '')}
x = 0
slams.each_with_index do |jam, i|
File.open File.join(File.expand_path('../', __FILE__), jam), 'wb' do |f|
out_str = "[#{i + 1}/#{slams.length}] #{jam}"
$stdout.print "#{' ' * x}\r#{out_str}\r"
$stdout.flush
x = out_str.length
f.write HTTParty.get(AUDIO_BASE + CGI.escape(jam)).parsed_response
end
end
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment