4

我正在尝试制作一个脚本来提取当前播放曲目的艺术品并将其写入文件。我已经查看了一些指南,但它们似乎都不起作用,有什么提示吗?

tell application "iTunes"
write artwork 1 to "path:to:desktop" of type("JPEG")
end tell

老实说,我不知道自己在做什么。有人觉得有帮助吗?

谢谢

4

1 回答 1

7

您可以写入raw data of artwork 1 of current track文件:

-- get the raw bytes of the artwork into a var
tell application "iTunes" to tell artwork 1 of current track
    set srcBytes to raw data
    -- figure out the proper file extension
    if format is «class PNG » then
        set ext to ".png"
    else
        set ext to ".jpg"
    end if
end tell

-- get the filename to ~/Desktop/cover.ext
set fileName to (((path to desktop) as text) & "cover" & ext)
-- write to file
set outFile to open for access file fileName with write permission
-- truncate the file
set eof outFile to 0
-- write the image bytes to the file
write srcBytes to outFile
close access outFile

您也可以使用http://dougscripts.com/itunes/scripts/ss.php?sp=savealbumart,但它不包含源代码。

于 2013-06-08T10:06:19.627 回答