【问题标题】:How to access Apple Music album art in iTunes via Apple Script如何通过 Apple Script 在 iTunes 中访问 Apple Music 专辑封面
【发布时间】:2016-09-24 03:44:16
【问题描述】:

我正在尝试创建一个应用程序,将桌面背景设置为在 iTunes 中播放的当前歌曲的专辑封面,但遇到了一个问题,即我的脚本无法读取 Apple Music 歌曲的专辑封面,除非它已被添加到用户的音乐收藏或播放列表中。

目前我正在使用this code 提取专辑封面。

-- 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

有人知道为什么直接从 Apple Music 播放时这不起作用吗?
因此,我可以将一首 Apple Music 歌曲添加到我的资料库或播放列表中,并且我的脚本可以读取其专辑封面(不必下载歌曲),但例如,当只是浏览 New 或 For You 部分时,并播放一首歌,我的脚本将无法读取它并且我的应用程序将崩溃。

任何建议都将不胜感激,因为我希望任何希望它能够使用此应用程序的人。

【问题讨论】:

    标签: macos applescript itunes itunesartwork apple-music


    【解决方案1】:

    抱歉,当流式传输 Apple Music 时,当前曲目URL 曲目。虽然这继承自 track,但艺术品元素列表并未通过 iTunes 脚本公开,因此没有可用的封面。

    tell application "iTunes"
        tell current track
            if exists (every artwork) then
                tell artwork 1
                    get properties
                end tell
            else
                tell me to display alert "No Cover Art found."
            end if
        end tell
    end tell
    

    【讨论】:

    • 使用if exists artworks,效果非常好。使用if exists artwork 1 出现错误,“无法获取当前曲目的艺术品 1 的原始数据。”
    • @BenClose,很高兴这有效。我更新了答案以纳入您的反馈。如果您对答案感到满意,请单击复选标记接受。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2019-09-08
    相关资源
    最近更新 更多