有什么方法可以改善这个Applescript iTunes Code的性能?

时间:2014-02-18 12:31:21

标签: performance applescript itunes

我编写了一个脚本,用于识别iTunes中的重复项,在播放列表中查找实例,以及其他我认为不相关的内容。为了检查曲目是否重复,我有以下代码:

        set duplicateSongs to ¬
        get (every track of playlist 1 where ¬
            (name is equal to (name of currentTrackToCheck as text) and ¬
                database ID is not equal to (database ID of currentTrackToCheck as integer) and ¬
                time is equal to (time of currentTrackToCheck as text)))

我在1000个歌曲的测试库中编写并测试了这个并且速度很快。当我对我的iTunes资料库进行测试时,大约有30,000首歌曲,然后一切都崩溃了。

这段代码需要2分钟才能完成处理!有没有办法让代码更快?我一直在阅读AppleScript上的很多内容,我相信使用where /哪个是从查询中筛选结果的最快方法。

谢谢! : - )

2 个答案:

答案 0 :(得分:0)

它不会影响速度,但我会这样写......

tell application "iTunes"
    set {trackName, trackDatabaseID, trackTime} to {name, database ID, time} of current track
    set duplicateSongs to (get every track of playlist 1 whose name = trackName and time = trackTime and database ID ≠ trackDatabaseID)
end tell

答案 1 :(得分:0)

刚刚更改为使用搜索功能,然后在其中进行搜索,只需不到一秒钟 - yay! : - )

on SearchForDuplicates(currentTrackToCheck, iTunesLibrary)
tell application "iTunes"
    set duplicateSongs to {}
    set preSearch to search iTunesLibrary for (name of currentTrackToCheck as text) only songs
    repeat with aTrack in preSearch
        tell aTrack
            if (name is equal to (name of currentTrackToCheck as text) and ¬
                database ID is not equal to (database ID of currentTrackToCheck as integer) and ¬
                time is equal to (time of currentTrackToCheck as text)) then
                set end of duplicateSongs to aTrack
            end if
        end tell
    end repeat
    return duplicateSongs
end tell

结束SearchForDuplicates