2006-04-16

Pennies Per Play

I've reached a milestone in per-track paid downloads from the Internet. This weekend I noticed that I am now over 1000 tracks in my Purchased Music playlist in iTunes. I figure that I have spent about $700 so far on that music. Where did the other $300 go? Well, some of those were the free downloads of the week. Some are free when you buy an album with more than 10 tracks, and at least 100 of them have come free from Mountain Dew and Gap promotions.

If you are keeping score, I now have 4 days and 6 hours worth of purchased music. If you are keeping score even closer, you might wonder how many times I have listened to these tracks and how much each play costs.

Now, I wish I had the motivation and/or the AppleScript skills to sit down and knock out an all-in-one program to do this calculation for me. I have neither of those at this time, so I have turned to the good ol' standby, the command line. I'm sure one of the fabulous readers of this blog has tighter command line kung-fu than I and will offer a more pure, a more efficient, dare I say, a distilled solution. Until that happens, here are 4 steps of a hack you can do at home.


  1. We need to get the play counts of the purchased tracks. This is easy enough. Simply open iTunes, select the Purchased playlist and then click File - Export Song List. Give it a name (Purchased.xml) and set the format to XML.

  2. The XML is fantastic, but we really only need the raw play count data. Use the following command to yank the counts out and delimit them with plus '+' signs for later.

    grep "Play Count" Purchased.xml | sed 's/[[:space:]]*Play Count<\/key>/+/' | sed 's/<\/integer>[[:space:]]*//' > add_up.txt

    I'm using grep to pull the lines containing the play counts, and then 2 runs of sed to strip away the remaining XML. (If only I had my XSLT book at home, this would have been so much easier) This all gets tossed in to a text file that I'll pass to bc in a later step. Here's your chance to show your command line fu. I know I can probably do this all with a single call to grep, but I didn't really care to sort that out right now.

  3. We now have all of the counts in a file, each on its own line. bc wants these all on one line, so crack open vi and enter this command.

    :%s/\n//g

    This will remove all new lines in the file and put everything on a single line.
    Before exiting vi, add a 0 as the very first character to make the math statement valid. If you are vi challenged, hit i to insert, 0 to type the '0', esc to get back to command mode, and wq to save and exit.

  4. Finally, feed that file to bc (basic calculator).

    bc add_up.txt

    You should get your number, and then you can type quit and enter to exit.



My play count total was 4220. If I use $700 as my expenses so far, I get 17 cents per play. It will be interesting to track that number as it goes up from buying more music, and down from more plays. To me, 17 cents is a great number. If you consider the average track in my collection is 5 minutes, I pay about $2 an hour to listen to iTMS purchased music. This would be even lower if I had a way to count the plays from CDs I burn for the car.

One final set of stats that I found interesting:
Tracks listened to only 1 time: 195 (not because I don't like them, I just buy music frequently)
Tracks not listened to at all: 2
Largest play count for a track: 20

What cool stats can you tell me about your iTMS library?

1 comment:

Jason said...

Good to see some old-fashioned Unix skills at work there. Of course, one line of sed fed to bc would do it, but even I don't want to try and create that monster.

264 songs in purchased music, but I think that leaves out some from early on when I lost my purchased list.

This machine isn't setup for generating the rest of the stats, I'll have to figure my other ones later.