我看了一些答案,告诉我如何从文件夹中获取随机文件,以及一些可以处理iTunes播放列表的答案。未能将这些放在一起。
我正在寻找的是一种方式(我在AppleScript中思考)在我的硬盘上的民谣播放列表文件夹中获取200首歌曲,随机选择其中的20首歌曲,然后将它们添加到iTunes播放列表中。
我知道智能播放列表可以做到这一点,但我想尽可能多地在iTunes之外进行,因为我的很多音乐都在文件夹中而不是iTunes本身。
我真的很感激任何帮助:
我确实想知道是否有某种方式可以获得百分比的文件数量(民间文件中20%的文件),但这不是真正的交易破坏者!
提前感谢任何可以帮助我的人!
塔迪
答案 0 :(得分: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
答案 1 :(得分: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中手动设置它以随机播放列表(可以为所有设置一次)