iTunes

All posts tagged iTunes

Love it or hate it. Those are the only two terms I hear from people about iTunes. This article isn’t going to debate the pro’s and con’s of using iTunes. No matter which camp you are in, there is one undeniably missing feature – library statistics. With statistics generated from your library, you can learn a few things about yourself. I’ve used a couple of tools in the past, and even tried some different library management software that include some basic statistics. None kept my attention for various reasons ranging from size, ease of use, Java requirements, or simply not enough detail. This article explores the implementation of a standalone statistics generator that meets my needs.

To create this application, which I have called iStats, I had only a few requirements:

Must be pleasing to look at (nice colorful graphs).

Must be quick (short run time).

Must be easy to invoke (as easy as launching a program).

With that in mind, I thought about writing it in several different languages. In the end I decided that simpler was better, so why not write it in Javascript which can be encapsulated in a single html file. This would allow double clicking the html file to launch it. At the same time, I could brush up on my Javascript, learn about HTML5, and learn a charting library.

That most difficult part of the entire project was learning chart.js and configuring the graphs. While the documentation is good, there is room for improvement in a few areas. The CSS, Javascript, and HTML5 code are all enclosed in a single html file: “iStats.html”. This file has a reference to pull in chart.js and list.js.

The application once launched:

Use the “Choose file” button to open a native file selector. Locate and select the iTunes library XML file (“iTunes Music Library.xml” on a Mac):

Once selected, the application then processes the file, and updates the Document Object Model (DOM – https://www.w3schools.com/js/js_htmldom.asp) with the graph data. You won’t see any screen updates. This is due to how Javascript works within the browser. Any changes in the DOM are rendered in the browser window when the Javascript completes.

Reading a file in the local file system from the browser via Javascript was a bit tricky. This relies on the Javascript FileReader (https://developer.mozilla.org/en-US/docs/Web/API/FileReader) object. If your browser doesn’t support the API call (or its disabled), then iStats won’t work. It uses the FileReader readAsText method to read the XML file, then parses it one line at a time.

Once processing is complete, about 10 seconds for my library of 6,700 songs, the page is rendered. At the top are three list sections. These were generated into the DOM using the “list.js” library. The first (leftmost) column are the overall library statistics. The second (middle) column are the statistics related to play counts. The third (right) column are statistics related to skip counts. The lists are ordered such that related items are on the same row:

The remainder of the page is consumed by graphs. A few examples follow. At the bottom of this article is a PDF of an entire iStats page where you can see all the graphs, and the iStats source code.

Notice the call out here. Hovering over a bar on the graph shows the exact value:

This happens to be the last graph of the page. It shows a timestamp of when the page was generated:

To use iStats, simply extract the linked zip file. To make things easy, a copy of chart.js and list.js is included (distributed via MIT License), but you should download them yourself. For your own sanity, review the Javascript source in the “iStats.html” file so you can see there is no funny business going on. It reads the XML file, and updates the html page DOM, thats it.

The code could stand to be tightened up. There is plenty of room for code re-use. I got it to the point where it does what I want and works, but I haven’t cleaned it up. iStats is being released under the Simplified BSD License. Feel free to use, modify and improve.

Like this:

iTunes has all kinds of metrics in it’s library database. I’ve always wanted to see some detailed breakdown on various things, like how many songs from different decades I have, how many different genres I have, etc. In addition to those basic things, there are a lot more metrics that make analysis very interesting.

I’ve written Perl scripts that read from iTunes library in the past. This was mainly to allow syncing to SD cards. I didn’t really want to write something to do the analysis if there was something already available. A quick search led to “The Super Archiver” by Nosleep Software (http://www.nosleepsoftware.net). It’s a Java application, but works very fast and produces more output than I imagined possible.

After starting, click the “Analyze” button, it’s the only one and right in the middle of the window. Analysis took less than 10 second for my library which contains about 7100 items. It produces a summary screen right away with some interesting figures! Here is the summary window:

But WAIT, theres MORE!

Along the bottom of the window are different icons. Clicking each one gives a different view into the analysis. The folder icon (Genre’s) produces a breakdown of how many songs in each genre with a graph that looks like this:

Yeah, there is Childrens music since I manage a childs iPad from the same library. However I reset the play counts to 0 after every sync for that music. And it appears that it is correct as I would have told you my preferred genre is Hard Rock.

Clicking the calendar icon (Release Year) produces a graph that shows how many songs in each decade you own vs plays in each decade. For any window that has a “Show ALL” dropdown, you can refine the result by choosing a single decade. Here is a sample:

Clicking the clock icon (Listening Times) produces a graph showing the listening time at various points in the day. Sample:

The graph icon (Song Quality) isn’t that impressive and is easily discerned from looking at your music library directly if you have the bitrate column displayed, but none-the-less its cool to see:

The first award ribbon icon (left – Most Played) produces a dual graph display showing Most Played Artists and Most Played Albums. This was interested as I would have said Dokken was my favorite band, maybe so but it doesn’t reflect in the play count*. But it was dead on as showing “Standing Hampton” as my favorite album. Truly a great album! Graphs:

The second award ribbon icon (right – Most Played) produces another dual graph display showing Most Played Decade and Most Played Genre. Yep, I’m a product of the 80’s hair metal (arena rock, or whatever you want to call it) era. Graph:

Clicking the plus icon (Play count) produces a graph showing the number of songs by play count. Looks like a large portion has play count of less than 5. I’m not mixing it up enough apparently. Graph:

Clicking the graph icon with an upward arrow (Library Growth) produces a graph showing when you added songs from different decades by year:

Clicking the document icon (Song Words) produces a graph showing the most common words appearing in song names. Graph:

Very cool information, and a lot more than I was looking for. With all that said the output is only as good as the library meta data. I’ve spent a considerable amount of time over the past 5 years getting the meta data accurate in my library so I feel this is fairly accurate. Well, at least as long as I’ve been listening to music solely digitally. The analysis doesn’t reflect all the listen counts from before the library was digitized, so all those times I listened to “For Those About To Rock” in the Eighties, or on cassette in a car or Walkman, etc, are not counted.

Like this:

I’ve been building my digital song library since around 1998, when MP3 players just started taking off. Suffice it to say that CD tracks “ripped” or imported back then had lower bit quality.

It wasn’t until Apple iTunes came along that I started managing my digital music collection in library form. I’ve stuck with it, though it was frustrating at times. I’ve learned that most of the frustration had more to do with the meta data associated with each track, and less to do with the actual iTunes application. So the first advice I give anyone when talking about digital music libraries is: Management is all about proper meta data, get your meta data fixed and you’ll be happy.

Over time bit rates have increased and there is a notable difference in sound quality between 128 kbps and 320 kbps. A significant portion of my library was imported at less than 160 kbps. Up until last year I had been importing at 192 kbps. This year I decided to re-import the entire library with a higher bit rate. I going with 256 kbps. The smaller rate will save some disk space and more importantly space on devices with limited storage capacities.

A lot of people will say I should use 320 kbps, but I have imported the same songs of different musical genres at both rates and listened to them on multiple devices (iPhone, computer with Harmon/Kardon 2.1 sound, streamed to home stereo via AirPlay, streamed to Bluetooth headphones, digital MP3 off SD card in car, and streamed to Bluetooth speakers (as in the JamBox I built). Honestly, it was very, very, hard to pick up any differences between 256 and 320.

When I started the process I realized I was going to lose much of the valuable meta data by removing the tracks and re-importing. I didn’t want to lose my play counts, didn’t want to lose the art-work (some can’t be found or is poor quality so I replace it), didn’t want to lose the genre tags (some people tag pop as rock, etc), and most importantly didn’t want to lose any customizations to the album or song names (like removing unfriendly characters that don’t display properly on all devices). I didn’t really find any tricks on the web and no direct information from Apple, so I experimented.

Using the method outlined here you can re-import the same CD’s and the meta data will be preserved!

1. Open iTunes.

2. Find a CD you want to re-import. I highlighted these, but that is not required. You can see some are 160 kbps, and some are 192 kbps.

3. Insert the CD. Select all the tracks you want to re-import by checking the check box on each song.

4. Click the Import button for iTunes (upper right corner for iTunes 11).

5. With iTunes 11, and I think 10, you will be asked about the import settings prior to the actual import. iTunes only shows up to 192 kbps as high quality. Choose “Custom…” setting. Then set the bit rate to the one you want, up to 320 kbps. I chose 256 kbps. You can use VBR if you want, I don’t because some of my devices do not show remaining time for VBR files. Click OK when you are satisfied with the settings.

6. Now iTunes will detect that you already have the songs imported and ask what you want to do. Click “Replace Existing”. Don’t worry, it will copy the meta data from the old files to the new files.

7. After the import is complete, go back to the Music library and find the CD / songs. You will now see the bit rate reflects the new one you selected and your meta data is intact.

So you got a shiny new iPad, to replace your aging old iPad. Whats that? You spent a lot of hours playing games and don’t want to lose your progress? You have a lot of Apps on it that you don’t want to have to re-download? You have photos and other data on it that you don’t want to lose?

Don’t fear, this guide is for you. I’ll show you how easy it is to move from an old iPad to a new iPad. It works even when going from an iPad 1 to an iPad 4. You’ll need to use iTunes to do this.

First things first. Before you even turn on the new iPad, as tempting as it may be, let’s make sure we can get the data from the old one.

Start iTunes.

Plug in the old iPad and do a sync, or a backup.

Eject the old iPad from iTunes and disconnect it from the computer.

Now the moment you’ve been waiting for. Turn on that shiny new iPad! Then do the following:

Press Home button.

Slide the arrow to get started.

Choose your language, then tap Next (arrow in upper right corner).

Choose your geographic location, then tap Next.

Choose to enable or disable location services, then tap Next. This is entirely up to you and can be toggled later should you change your mind.

If you disabled location services, tap OK to acknowledge.

Choose your network, enter the network password, then tap Next.

When you’re asked if you want to set up as new iPad or restore from backup, choose Restore. Tap Next.

You will be prompted to plug the new iPad into the computer, do so (iTunes should already be running).

iTunes will see the new iPad and ask which device you want to restore from. Choose the one you backed up from (if more than one).

Let iTunes do its thing. It will restore the iPad, reboot it, then synchronize it. The sync could take a while depending on what you had installed (how many books, how much music or movies, and how many apps).

Once the sync completes, go through iTunes settings for the new iPad and make sure the synchronization settings are still how you want them. Make adjustments where needed, then re-sync. You may want to change the name while you’re in iTunes, otherwise you can change it on the iPad itself later if you so desire.

When all done in iTunes, eject the new iPad and disconnect it from the computer.

When the new iPad has completed the iTunes initiated reboot, it will ask you to tap Continue. Just leave it until you are completely done in iTunes (as described in previous step).