Skip to content

Instantly share code, notes, and snippets.

@deathbob
Created February 21, 2011 01:59
Show Gist options
  • Select an option

  • Save deathbob/836569 to your computer and use it in GitHub Desktop.

Select an option

Save deathbob/836569 to your computer and use it in GitHub Desktop.
Little script to help me catch up on my mashups!
#!ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'fileutils'
prefix = Time.new.strftime("%F")
FileUtils.mkdir(prefix) unless File.exists?(prefix)
pages = (2..14).to_a
pages.each do |page|
doc = open("http://mashuptown.com/page/#{page}/")
as = Hpricot(doc)/'a'
mp3s = as.map{|x| x.attributes['href'] if x.attributes['href'].match(/\.mp3/)}.compact.uniq
mp3s.each{|x|
file = File.join(prefix, x.split('/').last)
unless File.exists?(file)
writeOut = open(file, "wb")
writeOut.write(open(x).read)
writeOut.close
puts "downloaded #{x}"
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment