Created
November 19, 2010 04:33
-
-
Save davelyon/706125 to your computer and use it in GitHub Desktop.
Parse an itunes XML file to something html-ish
This file contains hidden or 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
require 'rubygems' | |
require 'plist' | |
r = Plist::parse_xml("/Users/dave/Desktop/ItunesLibrary.xml") | |
lib = Hash.new() | |
r["Tracks"].each do |track| | |
album = track[1]["Album"] | |
artist= track[1]["Artist"] | |
trknum= track[1]["Track Number"] | |
title = track[1]["Name"] | |
if(!lib.has_key?(artist)) | |
lib[artist] = Hash.new() | |
end | |
if(!lib[artist].has_key?(album)) | |
lib[artist][album] = Hash.new() | |
end | |
lib[artist][album][trknum.to_i] = title | |
end | |
puts "<style>h1 {font-size: 16px; font-weight: bold;}</style>" | |
lib.each_pair do |key,value| | |
puts "<h1>#{key}</h1>" | |
puts "<ul>" | |
value.each_pair do |artkey, artvalue| | |
puts "<li><a href=\"\##{artkey}\"style=\"margin-left: 35px;\">#{artkey}</a></li>" | |
end | |
puts "</ul>" | |
end | |
lib.each_pair do |key,value| | |
puts "<h1>#{key}</h1>" | |
value.each_pair do |artkey, artvalue| | |
puts "<a name=\"#{artkey}\" />" | |
puts "<h2>#{artkey}</h2>" | |
puts "<table>" | |
artvalue.each_pair do |albkey,albvalue| | |
puts "<tr><td>#{albkey}</td><td> : </td><td>#{albvalue}</td></tr>" | |
end | |
puts "</table>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment