Skip to content

Instantly share code, notes, and snippets.

@cjheath
Forked from gusgollings/Tom Wait Sampler
Created October 20, 2010 01:22
Show Gist options
  • Save cjheath/635575 to your computer and use it in GitHub Desktop.
Save cjheath/635575 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
site = "http://www.tomwaits.com"
download_to = "/Users/gus/tmp/"
index = open(site + "/songs/") { |f| Hpricot(f) }
(index/"#songs-list li a[@class='play-track']").each do |song|
page = song.attributes['href']
doc = open(site + page) { |f| Hpricot(f) }
song = (doc/"param[@name='flashvars']").first.attributes['value'].split("file=").last
songname = download_to + page.split('/').last + ".mp3"
puts "This is page: #{page}\n=> getting #{song} as #{songname}"
begin
mp3 = open(site+song)
File.open(songname, "w") { |f| f.write mp3.read }
rescue => e
p e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment