applescript – 从csv文件填充iTunes播放列表

任何人都可以提供一种方法来填充我的播放列表与csv文件/文本文件中的歌曲格式如下:
歌名,艺术家?
我可以单独为标题做,但不能指定它必须有一定的艺术家.

编辑:以下是我如何通过标题获取它们的示例:

set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongList.txt"
tell application "iTunes"
    set thePlaylist to playlist "SongList"
    try
        delete every track of thePlaylist
    end try
    set MySongs to paragraphs of (TheFile) -- read artist names (separated by newlines) from the file
    repeat with AnItem in MySongs -- get all tracks from each artist
        set AnItem to (contents of AnItem)
        if AnItem is not "" then try -- don't bother with empty names
            set MyTracks to (location of file tracks of playlist "Music" whose name is AnItem)
            --can also modify the above from "is" to "contains" or "_begins with_"
            add MyTracks to thePlaylist
        on error errmess -- oopsie (not found,etc)
            log errmess -- just log it
        end try
    end repeat
end tell

解决方法

好吧,想通了!无法弄清楚如何处理带有逗号的标题(我有几个),所以我最终使用制表符分隔它们.所以,一旦我有我的制表符分隔文件,这段代码就可以了:
set thisTSVFile to (choose file with prompt "Select the CSV file")
readTabSeparatedValuesFile(thisTSVFile)

set theList to readTabSeparatedValuesFile(thisTSVFile)

tell application "iTunes"
    set myPlaylist to playlist "Test1"
    set sourcePlaylist to playlist "Music"
end tell

repeat with i from 2 to number of items in readTabSeparatedValuesFile(thisTSVFile)
     --gets first column
    set theName to item 1 of item i of theList
     --gets second
    set theArtist to item 2 of item i of theList
    tell application "iTunes"
        duplicate (some track of sourcePlaylist whose name is theName and artist is theArtist) to myPlaylist
    end tell
    delay 0.1
end repeat

on readTabSeparatedValuesFile(thisTSVFile)
    try
        set dataBlob to (every paragraph of (read thisTSVFile))
        set the tableData to {}
        set AppleScript's text item delimiters to tab
        repeat with i from 1 to the count of dataBlob
            set the end of the tableData to (every text item of (item i of dataBlob))
        end repeat
        set AppleScript's text item delimiters to ""
        return tableData
    on error errorMessage number errorNumber
        set AppleScript's text item delimiters to ""
        error errorMessage number errorNumber
    end try
end readTabSeparatedValuesFile

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...