Comment puis-je écrire un AppleScript pour récupérer toutes les pistes d'un album contenant moins de n des pistes dans iTunes ?
Réponses
Trop de publicités?Voici le code modifié d'une réponse connexe dans
Il est lent mais fait le travail. Il imprime les noms de l'album et des pistes.
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
Bilal Syed Hussain
Points
874
Version plus rapide (prend <10 secondes par rapport à 1/2 heure sur > 10000 pistes) de la réponse de 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