Programming question: simple iTunes library analyzer
A question to all my programmer friends (and non-programmer friends who have useful suggestions):
Since making the push to get to 10,000 songs in my iTunes library, I’ve become incredibly fascinated with the idea of tracking my iTunes library data. In particular, I’d like to track the day-to-day rate of growth of the library. Now, I know that iTunes automatically stores all of the library data in an XML file, and I’ve looked at this XML file and it does indeed keep track of the date added data for each track. What would you suggest is the best way to go about grabbing this data from the XML file and doing what I’d like to do? Thanks ahead of time for the help! :-D
emma :: Jan.15.2007 :: misc, question, programming :: 4 Comments »
Any XML-parsing library will make that aspect of it relatively simple, so the big question becomes ‘what language do you want to do it in?’ I can point you to relevant resources in Emacs Lisp, Perl, PHP, JavaScript, and any of them would be a reasonable choice for the task; I could also point you towards C and Java resources, but they would not, IMO, be reasonable choices for it.
(I would do it in Emacs Lisp and this library, but that’s because Emacs Lisp is my language of choice for that sort of thing right now, which is a choice I made as an XEmacs developer, not because of any inherent superiority of the language.)
Awesome, thank you! I’ll try it out with Emacs Lisp tomorrow (maybe? :-D) and let you know how it goes :-) I’d been looking at ways to do it with PHP and Perl, but am more thrilled (of course) to do it with a Lisp-y language.
!
Okay, some caveats with Emacs Lisp:
1. The tail recursion optimisation hasn’t been implemented. That would require C-level support for lexical scope, and such a thing seems to offend Stallman’s sensibilities, and we XEmacs folk haven’t got to it yet. So loop iteratively, not declaratively, otherwise you’ll run out of stack space.
2. The most used Emacs Lisp date/time parsing functions don’t understand the most used XML time/date format. Use nnrss-normalize-date from nnrss.el — the syntax necessary for that is something like:
(autoload ‘nnrss-normalize-date “nnrss”)
at the beginning of the file, and then (parse-time-string (nnrss-normalize-date name-of-the-variable-bound-to-the-timestamp))
Also, C-h f name-of-function-or-variable RET is invaluable for learning what a function or variable does.
3. That library parses the file into a nested list, and with 10000 entries, it’ll be noticeably slower than Perl. Best run your script as a batch program, not interactively;
emacs –batch -l your-lisp-file.el
Python is my language of choice for this sort of thing.