I made a script for searching my iTunes library for songs that are alone (meaning there is only 1 song from an album in the library) and puts them into a new playlist.
The script runs… but always at 100% load and it takes ages to scan a 15k song library. So is it possible to reduce/enhance the script that not that much load is on the MAC or is there even another way of scanning for lonley songs?
Here is the script:
tell application "iTunes"
repeat with aTrack in (file tracks of user playlist 1)
if genre of aTrack is not "Hörbuch" then
set tmpAlbum to album of aTrack
set num to count (tracks whose album is tmpAlbum)
if num is less than "2" then
duplicate (every file track of library playlist 1 whose album is tmpAlbum) to user playlist "single songs w/ no album"
end if
else
exit repeat
end if
end repeat
end tell
Any help is highly appreciated and thank you in advance
I ran the script via iTunes and then everything went like a charm
I took out a few lines since audiobooks/podcasts are not listed in “playlist 1”
tell application "iTunes"
repeat with aTrack in (file tracks of user playlist 1)
set tmpAlbum to album of aTrack
set num to count (tracks whose album is tmpAlbum)
if num is less than "2" then
duplicate (every file track of library playlist 1 whose album is tmpAlbum) to user playlist "single songs w/ no album"
end if
end repeat
end tell
You can probably speed the script a lot by changing this line.
duplicate (every file track of library playlist 1 whose album is tmpAlbum) to user playlist "single songs w/ no album"
You have already searched for tracks of that album and determined that only the current track has that album… so why perform the search a second time in the “duplicate” line? It’s just wasting time and energy. Change the line to this:
duplicate aTrack to user playlist "single songs w/ no album"
Here’s a different approach that avoids passing lots of script events to iTunes:
--FindiTunesSingletons
-- 398 singleton albums in 8 seconds from a library of 8300 songs
tell application "iTunes"
-- Be sure to have your iTunes Music Library set to sort by album.
-- The search RELIES on that presort.
set t1 to current date
-- get the data:
set nams to name of every file track of user playlist 1
set albs to album of every file track of user playlist 1
set dids to database ID of every file track of user playlist 1
-- store results here:
set singletrackalbIDs to {}
set singletrackalbnames to {}
set singletracksongtitles to {}
-- Loop through the data looking for album names that only occur once:
set numtracks to 1
repeat with n from 1 to ((count of albs) - 1)
set curalb to item n of albs
set nextalb to item (n + 1) of albs
if curalb is not equal to nextalb then
if numtracks is equal to 1 then
set end of singletrackalbnames to item n of albs
set end of singletracksongtitles to item n of nams
set end of singletrackalbIDs to item n of dids
else
set numtracks to 1
end if
else
set numtracks to numtracks + 1
end if
end repeat
set numsingletons to count of singletrackalbIDs -- Do something with the data
set t2 to current date
display dialog (numsingletons as string) & " Singletons\n" & ((t2 - t1) as string) & " Seconds" -- how long did that take?
end tell
return singletrackalbnames --singletracksongtitles