AppleScript para obtener todas las pistas de álbumes con menos de un cierto número de pistas

0

¿Cómo escribiría un AppleScript para obtener todas las pistas de álbumes con menos de n pistas en iTunes?

    
pregunta Bilal Syed Hussain 10.01.2014 - 16:22

2 respuestas

2

Aquí se modifica el código de una respuesta relacionada en

. álbumes completos en iTunes (es decir, álbumes con todas las canciones)

Es lento pero hace el trabajo. Imprimirá el álbum y los nombres de las pistas.

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
    
respondido por el Vic 05.05.2014 - 20:29
2

Versión más rápida (toma < 10 segundos en comparación con 1/2 hora en > 10000 pistas) de Vic answer

#!/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
    
respondido por el Bilal Syed Hussain 05.05.2014 - 23:24

Lea otras preguntas en las etiquetas