Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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