Re: iTunes Music Library parsing help
Re: iTunes Music Library parsing help
- Subject: Re: iTunes Music Library parsing help
- From: "James B. Tuley" <email@hidden>
- Date: Sun, 6 Mar 2005 16:05:42 -0600
On Mar 6, 2005, at 3:00 PM, Dave DeLong wrote:
Hi everyone,
I've got some code that parses the iTunes Music Library.xml file by
pushing it into a dictionary:
NSURL * iTunesDatabaseLocation = [NSURL
fileURLWithPath:[@"~/music/iTunes/iTunes Music Library.xml"
stringByExpandingTildeInPath]];
NSDictionary * iTunesDatabase = [NSDictionary
dictionaryWithContentsOfURL:iTunesDatabaseLocation];
I then iterate through the dictionary with an NSEnumerator to
construct some custom Playlist objects that contain the list of all
the songs in each playlist, etc.
The problem is that it takes a VERY long time to do this -- well over
a minute. I think that's a little odd, because I wrote the exact same
method in another language and it could pull all available track
information, store each track in a seperate track object, then create
the entire and correct playlist hierarchy with references to each
track. It could do all of this in less than three seconds.
Perhaps I'm doing something wrong? Why on earth should it be taking
more than 20 times as much time? Here's all the parsing code:
An NSDictionary is basically a HashTable, this algorithm you wrote
pretty much puts the preexisting table of tracks hashed by ID it into
an array that you are using to look up songs, and causes you to have to
iterate through song library until you find the song each time,
defeating the purpose of it being already in a hashtable.
I made the slightest modification to this section of your code to
allow quick lookups of the songs by id->
NSArray * ids = [currentList objectForKey:@"Playlist Items"];
NSEnumerator * idEnumerator = [ids objectEnumerator];
NSDictionary * currentId;
NSMutableArray * playSongs = [[NSMutableArray alloc] init];
while (currentId = [idEnumerator nextObject])
{
NSString* i = [currentId objectForKey:@"Track ID"];
NSDictionary* songFromID =[tracks objectForKey: i];
[playSongs addObject:songFromID];
}
-Jay
http://indyjt.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden