为iTunes中的完整专辑创建播放列表(即包含所有歌曲的专辑)


3

我怎样才能为iTunes中的所有专辑创建播放列表?假设曲目编号和曲目计数元数据在指定的位置是准确的,并且不用担心捕获缺少该元数据的曲目。我认为这将需要AppleScript。

Answers:


4

我意识到这是一个足够复杂的问题,我应该尝试自己给猫皮肤。这是一种方法:

-- Creates a playlist for each full album you have in iTunes
-- Set the playlistPrefix and playlistSuffix as desired before running

-- Based on code by Brad Campbell
-- http://www.bradcampbell.com/2009/05/26/make-a-whole-album-playlist-in-itunes/

tell application "iTunes"
    set playlistPrefix to "FA: "
    set playlistSuffix to ""
    -- The "FA: " prefix will help cluster full albums in iTunes' playlists,
    -- and is narrow enough to not get in your way when viewing on an iPhone

    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 "audio") as list

    -- Find all partial albums in iTunes
    repeat with currentTrack in allSongs
        set albumName to album of currentTrack as text
        set artistName to artist of currentTrack as text

        -- First check for missing values, then perform integer comparison
        -- Zero is on the left to force interger type coercion, just in case
        if album of currentTrack is not missing value and 0 is less than length of albumName then
            if artist of currentTrack is not missing value and 0 is less than length of artistName then
                if track number of currentTrack is not missing value and 0 is less than track number of currentTrack then
                    if track count of currentTrack is not missing value and 0 is less than track count of currentTrack 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 if
        end if

    end repeat

    repeat with currentAlbum in albumBuckets
        set albumSongs to (every track of library playlist 1 whose album is currentAlbum)
        set firstTrack to first item of albumSongs

        -- Filter album list to act only on full albums
        if (count of albumSongs) is equal to track count of first item of albumSongs and 1 is less than (count of albumSongs) then
            -- This is a full album, construct the playlist

            -- Sort tracks by track number
            set albumSongsSorted to {} as list
            repeat with i from 1 to (count of albumSongs)
                repeat with trk in albumSongs
                    if track number of trk is i then
                        set nextSong to trk
                        copy nextSong to the end of albumSongsSorted
                    end if
                end repeat
            end repeat

            -- Don't show artist name for compilations
            if firstTrack is not compilation then
                set playlistNameArtist to artist of firstTrack & " - "
            else
                set playlistNameArtist to ""
            end if

            set albumPlaylistName to playlistPrefix & playlistNameArtist & currentAlbum & playlistSuffix

            -- Create playlist
            if user playlist albumPlaylistName exists then
                try
                    delete tracks of user playlist albumPlaylistName
                end try
            else
                make new user playlist with properties {name:albumPlaylistName}
            end if

            try
                repeat with trk in albumSongsSorted
                    duplicate trk to user playlist albumPlaylistName
                end repeat
            end try
        end if
    end repeat

    display dialog "Playlists created! Check iTunes for playlists beginning with '" & playlistPrefix & "'"
end tell

要试一试,只需将代码块复制并粘贴到AppleScript Editor中,然后按“运行”即可。请注意,没有简单的“撤消”按钮 - 如果您想要丢弃所有创建的播放列表,则必须按住删除键。

可能有一个更快的算法(即只通过iTunes'库进行一次通过的算法)但我无法想象如何使用AppleScript中的二维变量,这似乎是一个先决条件。

这个脚本的一个额外的副作用是,它可能会显示您已移动的库中的古代专辑,并可以安全地删除:)


非常好的问题和出色的答案。使用该代码,可以非常接近目的地。但是,如果我没有错,它无法处理多磁盘上的完整专辑。我试图修改代码但没有太大的成功(目前)。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.