Come scriverei un AppleScript per ottenere tutte le tracce da album con meno di n tracce in iTunes?
Come scriverei un AppleScript per ottenere tutte le tracce da album con meno di n tracce in iTunes?
Ecco il codice modificato da una risposta correlata in
Crea playlist per album completi in iTunes (ovvero album con tutte le canzoni)
È lento ma fa il lavoro. Stamperà l'album e i nomi delle tracce.
HTH
tell application "iTunes"
-- The number of tracks
set songsPerAlbum to 4
set albumBuckets to {} as list
set allSongs to (every track of library playlist 1 ¬
whose enabled is true and podcast is false ¬
and kind contains "Music") as list
log "Debug: # of songs in library: " & (get count of allSongs)
-- Get list of albums, the slow way...
repeat with currentTrack in allSongs
set albumName to album of currentTrack as text
if album of currentTrack is not missing value then
if 0 is less than length of albumName then
if albumBuckets does not contain album of currentTrack then
copy album of currentTrack to the end of albumBuckets
end if
end if
end if
end repeat
-- Check each album
repeat with currentAlbum in albumBuckets
set albumSongs to (every track of library playlist 1 whose album is currentAlbum)
-- Check track count
if (count of albumSongs) is less than songsPerAlbum then
log "Debug: Album: " & currentAlbum
repeat with trk in albumSongs
log "Debug: " & (get name of trk)
end repeat
end if
end repeat
end tell
Versione più veloce (richiede < 10 secondi confronta con 1/2 ora su > 10000 tracce) della risposta Vic
#!/usr/bin/env osascript
tell application "iTunes"
-- The number of tracks
set songsPerAlbum to 4
-- Get list of albums, the fast way...
set albumsWithDups to (album of every track)
set albumsNames to my removeDuplicates(albumsWithDups)
-- Check each album
repeat with currentAlbum in albumsNames
set albumSongs to (every track of library playlist 1 whose album is currentAlbum)
-- Check track count
if (count of albumSongs) is less than songsPerAlbum then
log "Debug: Album: " & currentAlbum
repeat with trk in albumSongs
log "Debug: " & (get name of trk)
end repeat
end if
end repeat
end tell
on removeDuplicates(lst)
-- from http://applescript.bratis-lover.net/library/list/#removeDuplicates
local lst, itemRef, res, itm
try
if lst's class is not list then error "not a list." number -1704
script k
property l : lst
property res : {}
end script
repeat with itemRef in k's l
set itm to itemRef's contents
-- note: minor speed optimisation when removing duplicates
-- from ordered lists: assemble new list in reverse so
-- 'contains' operator checks most recent item first
if k's res does not contain {itm} then ¬
set k's res's beginning to itm
end repeat
return k's res's reverse
on error eMsg number eNum
error "Can't removeDuplicates: " & eMsg number eNum
end try
end removeDuplicates
Leggi altre domande sui tag macos itunes applescript music