Wednesday, November 15, 2006

Get Genre's from Last.fm and Tag with Last.fm Using RubyOSA

I’ve always hated genre’s. They always place a constriction on the acceptance of an artist. However, they do come in handy in certain situations. For instance, I like to tag all my ambient stuff so that I may quickly choose an artist to fall asleep to. Now, I’m on a tagging rampage, however there are some artists where I have no idea how to “genrealize” it. Ah, but the ever-growing community on Last.fm tags artists! Most of the time, the genre is agreeable upon a majority and therefore acceptable to me. I was growing sick of searching Last.fm for each artist, then choosing the most popular tag and tagging it in iTunes. If it weren’t for RubyOSA, I could not have accomplished what I wanted to do.

This is a perfect project for me that I hope to evolve into a more interactive process. Currently, the script is very basic in that you run it, it grabs the tag feed from Last.fm and sets the genre of the artist that you’re listening to. Check it out:




require 'rubygems'
require 'rbosa'
require 'net/http'
require 'cgi'
require 'rexml/document'

include REXML

itunes = OSA.app('iTunes')
track = itunes.current_track
feed = "http://ws.audioscrobbler.com/1.0/artist/#{CGI::escape(track.artist)}/toptags.xml"
doc = Document.new(Net::HTTP.get(URI(feed)))
track.genre = doc.root[1][1].text


In the future, I would like to provide a list of the top 10 tags in which you choose which to tag this song with and ultimately, I’d like to tag the whole artist with the genre. Maybe I could also provide album tagging, since some artists deviate in style across multiple albums.

Labels: , , ,


Comments:
This is very cool! Would you be willing to contribute this piece of code as an official RubyOSA sample?
Thanks in advance,
Laurent (RubyOSA's author)
 
Post a Comment



Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]