Here is the full Ruby code:
require 'rexml/document'
include REXML
class DeliciousLibrary
#usual_path is the path of the DL XML file (until v2). Unless this
script is on a server, this works.
@@usual_path = "#{ENV['HOME']}/Library/Application Support/Delicious
Library/Library Media Data.xml"
@@medium_covers = "#{ENV['HOME']}/Library/Application
Support/Delicious Library/Medium Covers/" #requires UUID for
identification
def initialize(file = @@usual_path)
@library = Document.new(File.new(file))
@movies = Array.new
end
def get_library_as_xml
@library.root
end
def get_movies
temp = @library.root
temp.elements.each('items/movie') { |movie|
@movies.push(Movie.new(movie.attributes['uuid'].to_str,
movie.attributes['fullTitle'], movie.attributes['asin'],
movie.attributes['mpaarating'], movie.attributes['minutes'],
movie.attributes['published'], movie.attributes['price']))
puts movie.attributes['fullTitle']
}
end
def get_shelves
@library.root.elements['items/shelves']
end
end
class Movie
#Some Supplimental Classes
def initialize(uuid, fullTitle, asin, mpaarating, minutes, published,
price)
@uuid = uuid
@fullTitle = fullTitle
@asin = asin
@mpaarating = mpaarating
@minutes = minutes
@published = published
@price = price
end
attr_reader :uuid, :fullTitle, :asin, :mpaarating, :minutes,
:published, :price
end
The XML file is about 7000 lines long, os here's a snippet. i don't
think you really want 7000 lines of code listed anyway.
<movie asin="B000BW7QWW" aspect="DVD" country="us" created="188189008"
currentValue="$9.96"
features="AC-3
Animated
Color
Dolby
Dubbed
Subtitled
Widescreen
NTSC
2.35:1"
fullTitle="Serenity (Widescreen Edition)" genre="Sci-Fi
Action
Futuristic
Space Adventure
Action &
Adventure
Science Fiction & Fantasy"
lastLookupTime="188189024" minutes="119" mpaarating="PG-13"
netrating="4.5" price="$19.98" published="20-12-2005"
publisher="Universal Studios Home Entertainment"
purchaseDate="18-12-2006" stars="Chiwetel Ejiofor
Nathan
Fillion
Gina Torres
Morena Baccarin
Adam
Baldwin
Raphael Feldman
Yan Feldman
Ron
Glass
Summer Glau
Michael Hitchcock
Glenn
Howerton
David Krumholtz
Sean Maher
Sarah
Paulson
Nectar Rose
Jewel Staite
Tamara
Taylor
Alan Tudyk
Hunter Ansley Wryn"
theatricalDate="30-09-2005" title="Serenity" upc="0025192632723"
uuid="0CEA2670-C438-4C35-95A6-35F2E21DD05E">
...
</movie>
Thanks for the help.
Bob Hutchison wrote:
···
On 21-Dec-06, at 3:05 AM, Peter Szinek wrote:
> Can you send the full code? Are you sure that e.g. Movie.new does
> not return a REXML::Element for example? Anyway, I can not really
> figure this out without seeing the full code.
>
And the XML as well.
Cheers,
Bob
> Cheers,
> Peter
----
Bob Hutchison -- blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc. -- <http://www.recursive.ca/>
Raconteur -- <http://www.raconteur.info/>
xampl for Ruby -- <http://rubyforge.org/projects/xampl/>