Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created December 5, 2008 18:27
Show Gist options
  • Save wesrog/32441 to your computer and use it in GitHub Desktop.
Save wesrog/32441 to your computer and use it in GitHub Desktop.
begin require 'rubygems'; rescue LoadError; end
require 'rbosa'
require 'net/http'
require 'cgi'
require 'rexml/document'
include REXML
itunes = OSA.app('iTunes')
selection = itunes.selection.get
if selection.empty?
$stderr.puts "Please select some tracks."
exit 1
end
selection.each do |track|
feed = "http://ws.audioscrobbler.com/1.0/album/#{CGI::escape(track.album)}/toptags.xml"
doc = Document.new(Net::HTTP.get(URI(feed)))
track.genre = doc.root[1][1].text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment