global numToRemove, badPlaylist

-- SET VALUE BELOW --
set badPlaylist to "PUT_YOUR_ANNOYING_DUPLICATE_PLAYLIST_NAME_HERE"
-- SET VALUE ABOVE --


tell application "iTunes"
set startDate to (current date)

log ("Started collecting playlists @ " & (current date))

with timeout of 86400 seconds
set playlistList to (get every user playlist whose name is badPlaylist)
end timeout

if (count playlistList) = 0 then
log ("No playlists named " & badPlaylist)
return -1
else if (count playlistList) < 3000 then
set numToRemove to (count playlistList)
else if (count playlistList) < 15000 then
set numToRemove to 2000
else
set numToRemove to round (count playlistList / 10) rounding down
end if

log ("* Removing " & numToRemove & " of " & (count playlistList))
log ("Starting deletes @ " & (current date))

repeat with i from 1 to numToRemove
try
with timeout of 600 seconds
delete (item i of playlistList)
end timeout
on error m
-- debugging
log ("err: " & m)
end try
end repeat

log ("* Deleted: " & numToRemove & ", Rate: " & (round (numToRemove / ((current date) - startDate + 1))) & " per second.")
log ("Finished @ " & (current date))
end tell