# note, you need two gems installed: # sudo gem install xmlsimple # # The second gem requires the id3lib utility to be installed. # On Mac OS X via Darwin Ports: # sudo port install id3lib # sudo gem install id3lib-ruby require 'net/http' require 'uri' require 'rubygems' require 'xmlsimple' require 'id3lib' BASE_URL = URI.parse('http://www.coachella.com/') def http_get_body(remote_path) res = Net::HTTP.start(BASE_URL.host, BASE_URL.port) {|http| http.get(remote_path) } return res.body end def download(remote_path, filename) data = http_get_body(remote_path) File.open(filename, 'w') do |f| f.write(data) end end def download_image(url) remote_path = url.gsub 'http://coachella.com', '' filename = File.basename(remote_path) download(remote_path, filename) return filename end # get the xml file xml_data = http_get_body '/media/audiomp3.xml.php' # parse xml into a collection of tracks doc = XmlSimple.xml_in(xml_data) tracks = doc['audio'] count = tracks.size track_number = 0 tracks.each do |track| filename = "#{track['artist'].first} - #{track['title'].first}.mp3" track_number+=1 puts "Saving #{track_number}/#{count}: #{filename} via #{track['flv'].first}" download(track['flv'].first, filename) image_file = download_image(track['visual'].first) tag = ID3Lib::Tag.new(filename) tag.title = track['title'].first tag.artist = track['artist'].first tag.album = 'Coachella 2008' tag.part_of_set = "#{track_number}" tag.comment = 'From the Coachella 2008 Website' cover = { :id => :APIC, :mimetype => 'image/jpeg', :picturetype => 3, :description => track['artist'].first, :textenc => 0, :data => File.read(image_file) } tag << cover tag.update! end