0 votes

AppleScript pour obtenir toutes les pistes d'un album dont le nombre de pistes est inférieur à un certain seuil.

Comment puis-je écrire un AppleScript pour récupérer toutes les pistes d'un album contenant moins de n des pistes dans iTunes ?

2voto

Vic Points 1820

Voici le code modifié d'une réponse connexe dans

Créer des listes de lecture pour des albums complets dans iTunes (c'est-à-dire des albums contenant toutes les chansons)

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

2voto

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

LesApples.com

LesApples est une communauté de Apple où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres utilisateurs d'appareils Apple, poser vos propres questions ou résoudre celles des autres.

Powered by:

X