What are your iTunes habits? [code included]

Filed under: PHP | 3 Comments

iTunesSometimes I have way too much stuff to do, but get stuck on an idea that really is useless. A few nights ago was one of those times. We all know that iTunes uses XML to organize the library, and that it tracks how many times we finish listening to a song. So I told myself….

  1. iTunes knows how many times I’ve finished (doesn’t count if you stop the song before it finishes) all my songs.
  2. iTunes knows how long said songs are
  3. Why can’t iTunes tell me how long I have listened to my music?

Well folks, it can. It just isn’t built in. There is probably some shareware app that does it, but I figured I’d give it a stab in PHP. Why PHP? I like it. Yes ,Perl would be better because all OS X users have it without screwing around, but I don’t like Perl.

Ergo, I wrote some code to massage iTunes’ library in a web scripting language. Most of the code came from here–it’s well written and open source. I just edited to my uses.

IF YOU DO NOT HAVE PHP WORKING DO NOT COMPLAIN THAT THIS DOES NOT WORK. IF YOU NEED HELP, TRY MY WEB SERVING MADE EASY ARTICLES

The .zip file includes a [tiny] demo “library.xml” file that you can try right off the bat. Before long you should copy your file (~/Music/iTunes/iTunes Music Library.xml) to the folder you just decompressed. Rename it library.xml. Put the folder (it should be called itunes) in your web directory and pop up your browser to http://localhost/itunes/. Depending on your machine speed and your library size, before long should pop-up how long you have listened to iTunes, how many songs you have listened to and how many songs you haven’t. Neat!

Remember that you surely have listened longer, this only tracks SONGS COMPLETED.

Read the latest posts

3 Responses to “What are your iTunes habits? [code included]”

  1. Mike Cohen says:

    You do realize that PHP can be run from the command line.

    the first line of the file should be #!/usr/bin/php and it should have the standard php tags.

  2. RickMacMerc says:

    This is too cool. I’m not sure how or if I would use this, but I like it. I just like it.

  3. Jon Gales says:

    Mike:

    Yes, I do realize that, but some people will surely run this on their shared web server. Just easier to give one set of directions.

Leave a Reply