0

我查看了一些答案,这些答案告诉我如何从文件夹中获取随机文件,以及一些可以处理 iTunes 播放列表的答案。没办法把这些放在一起。

我正在寻找的是一种方法(我正在考虑使用 AppleScript),将 200 首歌曲放在我硬盘上的 Folk 播放列表文件夹中,随机选择其中的 20 首歌曲,然后将它们添加到 iTunes 播放列表中。

我知道智能播放列表可以做到这一点,但我想尽可能多地在 iTunes 之外进行,因为我的很多音乐都在文件夹中,而不是 iTunes 本身。

我真的很感激任何帮助:

  1. 从文件夹中获取 20 个随机文件和
  2. 然后将它们推入播放列表。

我确实想知道是否有某种方法可以获得百分比的文件数量(Folk 中文件的 20%),但这并不是真正的破坏交易!

提前感谢任何可以帮助我的人!

迟迟

4

2 回答 2

0

要播放曲目,您必须首先将它们导入 iTunes,如 Vadian 所说。最好将它们导入播放列表(之后更容易删除)。下面的脚本就是这样做的:

set MyRatio to 0.2 -- the % of files randomly selected over the total file of the selected folder
set MyFolder to choose folder "select folder with your musics"
tell application "Finder" to set MyList to every file of MyFolder

-- build the random list
set SongList to {}
set MaxCount to (MyRatio * (count of MyList)) as integer
set MyCount to 0
repeat until MyCount = MaxCount
set MyItem to random number from 1 to (count of MyList)
set NewFile to (item MyItem of MyList) as string
if NewFile is not in SongList then
    copy NewFile to the end of SongList
    set MyCount to MyCount + 1
end if
end repeat

-- add the files to iTunes new playlist
tell application "iTunes"
set MyPlayList to make new user playlist with properties {name:"my Import"}
repeat with I from 1 to count of SongList
    add ((item I of SongList) as alias) to MyPlayList
end repeat
play MyPlayList -- start to play the play list
end tell
于 2015-11-14T19:15:47.533 回答
0

这是您要查找的脚本。我留下第一个答案,因为它也可能对其他人有用。

property RList : "my random list" -- name of the random list
property ListGenres : {"Rock", "Pop", "Soundtrack", "Jazz"} -- your list of genres
property NumPerGenre : {3, 2, 5, 4} -- the number of songs per genre

tell application "iTunes"
if exists user playlist RList then -- check if the playlsit exists or not
    delete tracks of user playlist RList -- delete all current tracks of the play list
    repeat while (number of tracks of playlist RList) > 0
        delay 0.1 -- wait for the library to clear out, because iTunes is asynchronous !
    end repeat
else -- creation of the play list
    set MyPlayList to make new user playlist with properties {name:RList}
end if

repeat with I from 1 to (count of ListGenres) -- loop per genre
    set ListTracks to (tracks whose genre is (item I of ListGenres))
    repeat with J from 1 to (item I of NumPerGenre) -- loop to add x tracks per genre
        set TheTrack to item (random number from 1 to (count of ListTracks)) of ListTracks
        duplicate TheTrack to playlist RList
    end repeat -- loop for all tracks per genre
end repeat -- loop by Genre
play playlist RList -- start to play !  
end tell

我已经发表了很多评论来说明清楚(我希望)。在这个例子中,我有 4 个流派,我会得到第一个流派的 3 首歌曲,第二个流派的 2 首歌曲,……以此类推。您可以更改这些属性,只要流派列表的项目数与 numpergenre 列表相同。

不幸的是,由于iTunes 11,shuffle属性无法通过脚本设置,必须在iTunes中手动设置才能随机播放列表(可以设置一次)

于 2015-11-21T16:39:24.517 回答