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

applescript – 从csv文件填充iTunes播放列表,第1张

概述任何人都可以提供一种方法来填充我的播放列表与csv文件/文本文件中的歌曲格式如下: 歌名,艺术家? 我可以单独为标题做,但不能指定它必须有一定的艺术家. 编辑:以下是我如何通过标题获取它们的示例: set TheFile to read file "Macintosh HD:Applications:Automator stuff:01b iTunes Scripts:SongList.txt" 任何人都可以提供一种方法来填充我的播放列表与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 repeatend 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 tellrepeat 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.1end repeaton 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 tryend readTabSeparatedValuesfile
总结

以上是内存溢出为你收集整理的applescript – 从csv文件填充iTunes播放列表全部内容,希望文章能够帮你解决applescript – 从csv文件填充iTunes播放列表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1104825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存