从 Applescript 中的当前曲目获取艺术品 [英] Getting artwork from current track in Applescript

查看:26
本文介绍了从 Applescript 中的当前曲目获取艺术品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个脚本来提取当前播放曲目的插图并将其写入文件.我查看了一些指南,但似乎没有一个有用,有什么提示吗?

I'm trying to make a script to pull the artwork of the currently playing track and write it to a file. I've checked out a few guides but none of them seem to work, any tips?

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

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

To be honest I've no idea what I'm doing. Anyone feeling helpful?

谢谢

推荐答案

您可以将当前曲目的艺术品1的原始数据写入文件:

-- 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,但不包含源代码.

You might also use http://dougscripts.com/itunes/scripts/ss.php?sp=savealbumart, but it doesn't include source code.

这篇关于从 Applescript 中的当前曲目获取艺术品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆