Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

iTunes AppleScripts for play frequency and listening time Apps
Have you every wondered which songs are played most frequently? The play count is misleading because it is also a function of how long the song has been in your library.

I've written two scripts which compute the frequency with which played songs have been played, and then sorts them into three playlists and reports the results in corresponding text files which it puts on your desktop. One script sorts into these thirds using frequency bounds which you input yourself. The other script sorts all the songs from most frequently played to least frequently played, and then puts the top 25% in one text file (and playlist), the middle 50% in another text file (and playlist), and the bottom 25% in a third text file (and playlist).

The disadvantage of the latter method (although the lists are interesting) is that it might take awhile to run (6.25 hours on a 700 MHz eMac on a 2,200 song library). Songs which have only recently been added to your library have misleading frequencies and can tend to overpopulate your most frequent playlist, so they may be left out; a text file lists those which have been removed from the listing because of their youth. A fifth text file lists the basic age and frequency statistics of the library. You define how youthful the file is before it is left out of consideration.

I've also written a script which sums the product (play count) x (song length) to determine just how much music you've listened to...your total listening time. I've listened to 56 days worth over four years!

The scripts are interesting and fun, but perhaps a bit frivolous. They may all be found in this post of mine. Note that the first two scripts are covered in this hint; this hint covers the last three.

[robg adds: I've mirrored these three scripts [44KB] here on hints. I tested the total listening length script, but not the others. The total listening time script took a while to run -- five minutes or so on my Mac Pro for 3,800ish songs. When done, the result showed a total of 27 days. However, I reset my play counts quite often, as I use a "not often played" playlist for most of my listening. So the real figure is probably substantially higher :).]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,570 views]  

iTunes AppleScripts for play frequency and listening time | 10 comments | Create New Account
Click here to return to the 'iTunes AppleScripts for play frequency and listening time' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
iTunes AppleScripts for play frequency and listening time
Authored by: dmmorse on Oct 12, '07 08:39:09AM

I've listened to 126.7 days of music from a library of over 4300 songs. Of course, my ipod is typically on all day at work, every day, and it's almost always on in my car during my commute, unless I'm on the phone.



[ Reply to This | # ]
I'm at 695 days
Authored by: hamarkus on Oct 12, '07 09:33:57AM

And this probably does not include all the podcasts which get deleted after one listens to them.
I started using iTunes about eight years ago but at some point I started my library from scratch again, my oldest songs now are from Nov 2002. That means I should have listened to iTunes on average 9 hours per day. I am not sure this really correct.



[ Reply to This | # ]
I'm at 695 days
Authored by: Oops on Oct 12, '07 10:30:34AM
It does explicitly omit podcasts and video files from consideration.

If "Library Playlist 1" means the "Music" playlist, in which case audiobooks would not be included automatically, then audiobooks are omitted. If audiobooks are in library playlist 1, then the script does not remove audiobooks from consideration. I don't have any audiobooks and so I don't have a way to test this.

If anyone can tell me the answer to that question, or what sort of metadata is special to audiobooks (does the 'kind' contain audiobook?), then the script can easily be adapted to exclude audiobooks. The following should work if audiobooks do not reside in the 'Music' playlist automatically made by iTunes:

tell application "iTunes"
	set totalListeningTime to 0
	repeat with i from 1 to the count every track of playlist "Music"
		if (kind of track i of playlist "Music" contains "audio" and podcast of track i of playlist "Music" is false) then
			set timesPlayed to played count of track i of playlist "Music"
			set songLength to duration of track i of playlist "Music"
			set totalListeningTime to totalListeningTime + timesPlayed * songLength
		end if
	end repeat
	set totalHours to totalListeningTime / 3600
	set totalDays to totalHours / 24
	set totalYears to totalDays / 365.25
	display dialog "You have listened to " & totalDays & " days of music."
end tell
The only difference between this and the submitted script is that 'playlist "Music" ' is replaced by "library playlist 1". Looking at the script, I don't know how it can fail to give the correct answer. [The (kind of track i of playlist "Music" contains "audio" and podcast of track i of playlist "Music" is false) is to remove digital booklets and music videos from showing up. The podcast portion is unnecessary for the music playlist, but necessary if podcasts are in library playlist 1.]

Oops

[ Reply to This | # ]
I'm at 695 days
Authored by: Oops on Oct 12, '07 11:40:47AM

I have, on occasion, gone to class and left iTunes playing. If this happened enough, or overnight, or over the weekend, that could account for unusually high values. Other than this, or including audiobooks, or several iPods from different people syncing with iTunes, I don't know what would account for that high value. As you see from the code in my previous reply, it seems like it wouldn't be wrong.

Oops.



[ Reply to This | # ]
I'm at 695 days
Authored by: hamarkus on Oct 13, '07 05:48:12AM

My usual approach to a situation where the code does seem to be correct but the result not, is a brute force testing cycle.

Making several copies of my library, I would first cut it in half (in a random way, eg, alphabetically), then half it again and again until I am left with only a handful of songs. After verifying that the result is correct for these handful of songs, I would then run the script over all intermediate steps and plot the logarithm of the total playing time over the different slices of the library. I should then be able to fit a straight line to that. If there is significant sharp bend are jump in the data, then I would have found the part of the library that is giving suspicious results. Start again with this part to isolate the problem further.

I very much doubt however that I will go to that length.



[ Reply to This | # ]
I'm at 695 days
Authored by: Oops on Nov 12, '07 02:14:06PM
I have a new version at

http://oopsscripts.googlepages.com/

which will not count audio books if their genre is listed as "Books and Spoken". The old version did count audio books. Perhaps that was the issue it had with your library?

[ Reply to This | # ]
I'm at 695 days
Authored by: Oops on Sep 02, '08 09:37:37AM
I've had to put them on a new site:

http://sites.google.com/site/oopscripts/Home

as Google will be soon dropping 'Pages' in favor of 'Sites'. I think the scripts are fairly robust now.

[ Reply to This | # ]
Length of time for script to run.
Authored by: Oops on Oct 12, '07 01:40:13PM

The script that computes frequency from user input is not so prohibitive to run. On a 700 MHz eMac with 2200 songs in the library, it took about 15 minutes to run. In the other script which computes the actual quartiles and separates into ordered list by quartiles, the huge time bump was due to the time it took to sort the list by frequency.

Off that topic:
On thing I noted was that if you replaced any songs with their iTunes + counterpart, the 'date added to the library' has changed but the 'play count' has not, so the computed frequency is not reflective of the actual frequency beginning from the date the original AAC protected file was added to the library.



[ Reply to This | # ]
iTunes AppleScripts for play frequency and listening time
Authored by: Oops on Nov 12, '07 02:22:55PM
New versions are available at:

http://oopsscripts.googlepages.com/

The play frequency script which lists your songs in playlists in order by their play frequency (and puts a text file on your desktop with this information in it) has been improved so it now runs in about 1/3 the time it used to (now 2.25 hours on a 700 MHz eMac with a 2250 track library).

The listening time script will now exclude audio books if their genre is listed as "Books and Spoken".

The other scripts mentioned in this hint have also been improved and are available at the same site.

An additional script which computes the play frequency for individual songs is also at this site.

Thanks,
Oops

[ Reply to This | # ]
iTunes AppleScripts for play frequency and listening time
Authored by: Oops on Sep 02, '08 09:39:47AM
I've had to put them on a new site:

http://sites.google.com/site/oopscripts/Home

as Google will be soon dropping 'Pages' in favor of 'Sites'. I think the scripts are fairly robust now.

[ Reply to This | # ]