Mon 18th Jul 2005
Archived Entry
- Post Date :
- Monday, Jul 18th, 2005 at 8:51 pm
- Category :
- Languages and iTunes
- Do More :
- You can leave a response, or trackback from your own site.
Sponsored Links
Archives
Design Downloaded from www.vanillamist.com
All content unless noted © Matt Schinckel, and may not be used without proper attribution.
That means scraping the data from my site and reposting it is prohibited.
All of the stuff I did with PyObjC is pretty much available in the standard library. There’s a (cross-platform, but only shipped with Mac OS X) plistlib module that can read this flavor of XML files and parse them into similar data structures, and you already know about urllib’s method for converting file URLs.
However, plistlib in Python 2.3 was horribly broken and won’t read any plist with dates in it (the iTunes library has dates). JvR and I fixed it for 2.4, but it’s still a hell of a lot slower than Apple’s highly optimized and specialized not-really-an-XML-parser implemented in Objective-C (well, C really… technically that code is in CoreFoundation).
It’s also easier to say “install PyObjC” than “install Python 2.4, set up your PATH appropriately, etc.”.
The find-forking is a little heinous, I’d have used os.walk() and os.path.isfile() to poke at the file system. os.path.exists() is a bit nicer than urlopen(), too.
Oh, and there’s a set datatype built-in to Python 2.4 which you could’ve used (or the Set type from the set module in Python 2.3). It’s a LOT faster at being a set than a list is. A dict would be fast too just not with the nice set API.
1 hour, 2 minutes after the fact.
Thanks for the tips.
I take it you mean calling the
findline? It was about an order of magnitude faster that the python version. Perhaps this has something to do with the fact that my iTunes Library is stored on a remote volume, served via SMB.I found the
urlopen()was easier to implement (IIRC, it was a month ago!) than converting the url to a filename. Of course, I’ll do that in the future.Oh, and I’m on Panther, with 2.3, so no joy there (on the
setfront, but also the plistlib, not that I’d come across this.)1 hour, 11 minutes after the fact.
Do’h, obviously I did’t read the comment properly, re: Set.
1 hour, 24 minutes after the fact.