Hello,
The iTunes script posted below uses track ratings and the total number of tracks (across all disks for a given album) to calculate and set an album rating. It may be that I don’t still have all tracks for a given album in my iTunes library, but because of the ‘track count’ tag in iTunes, I can still calculate this.
For the purposes of calculating the album rating I want to treat a track rating of 4 and 5 as the same - hence the maximum track rating of 80.
I am experiencing an issue with the script where I have more than one album with the same name - here I am not talking about multi-disc albums, but albums by different artists which have the same album name.
I can’t work out how to change the script to get it working with all albums, so would be glad of some help.
Thanks,
Nick
tell application "iTunes"
--Make a list of all the selected albums:
set theAlbums to {}
set theAlbumsRef to a reference to theAlbums
set tempList to album of selection
set thePreviousTitle to ""
repeat with thisTitle in tempList
set thisTitle to thisTitle as text
if thisTitle is not thePreviousTitle then
copy thisTitle to the end of theAlbumsRef
set thePreviousTitle to thisTitle
end if
end repeat
set numberOfAlbums to count theAlbums
---Make a list containing one track for each selected album:
set theTracks to {}
set theTracksRef to a reference to theTracks
repeat with thisAlbum in theAlbums
copy (track 1 whose album is thisAlbum) to the end of theTracksRef
end repeat
--Set the album rating of each album contained in the selection:
set theRatings to ""
set k to 0
repeat with thisTrack in theTracks
set k to k + 1
if k mod 25 = 0 then beep 1 -- for audio feedback
set thisAlbum to item k of theAlbums
set numberOfTracks to 0
repeat with k from 1 to (disc count of thisTrack)
try
get (track count of track 1 whose (album is thisAlbum) and (disc number is k))
set numberOfTracks to numberOfTracks + result
end try
end repeat
set songRating to 0
repeat with R in (rating of tracks whose album is thisAlbum)
if R > 80 then set R to 80
set songRating to songRating + R
end repeat
set thisRating to round (songRating / numberOfTracks)
set album rating of thisTrack to thisRating
set theRatings to theRatings & (album artist of thisTrack & tab & thisAlbum & tab & (thisRating as text) & return)
end repeat
end tell