Created
December 3, 2008 05:54
-
-
Save kjell/31434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w(rubygems open-uri hpricot ruby-debug prettyprint rbosa activesupport).each {|lib| require lib} | |
$KCODE = 'u' | |
class Track | |
attr_accessor :title, :composer, :artist | |
def initialize(*args) | |
@title = args.shift | |
@composer = args.shift | |
@artist = case args.size | |
when 1 then args.shift | |
when 2 then "#{args.last} (#{args.first})" | |
when 3 then "#{args[1]} (#{args.first}, #{args.last})" | |
end | |
end | |
end | |
page = Hpricot(open("amzn-violin.html")) # http://www.amazon.com/Violin-Adagios/dp/B000058BGY | |
raw_tracks = (page/".content ol li") | |
tracks = raw_tracks.inject([]) do |tracks, t| | |
a = [] | |
t.traverse_element(*%w(b br a)) {|e| a << e } | |
tracks << Track.new(*a.map(&:inner_html).map(&:strip).join('-').split('--')) | |
end | |
itunes = OSA.app('iTunes') | |
playlist = itunes.sources[0].playlists.select{|p| p.name =~ /violin/}.pop | |
playlist.tracks.each do |t| | |
track = tracks[t.track_number - 1] | |
%w(name artist composer).each {|field| t.send("#{field}=", track.send(field))} | |
end | |
# I have a CD and it had shitty track names. Fuck that! | |
# So grab the bonified names from amazon and throw them into itunes. | |
# Spend 25 minutes writing a script (kind of fun…) you could've manually | |
# done in 7 by hand (tedious). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment