如何通过Apple Script在iTunes中访问Apple Music专辑封面 [英] How to access Apple Music album art in iTunes via Apple Script
问题描述
我正在尝试创建一个将桌面背景设置为iTunes中当前播放歌曲的专辑插图的应用程序,但是遇到一个问题,除非我的脚本无法读取Apple Music歌曲的专辑插图,它已添加到用户的音乐收藏或播放列表中.
I'm trying to create an application that sets the desktop background to the album artwork of the current song playing in iTunes, but have come across an issue where my script can't read the album art of an Apple Music song unless it has been added to the user's music collection or playlist.
当前,我正在使用此代码来提取专辑封面
Currently I am using this code to extract the album art.
-- 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歌曲添加到我的媒体库或播放列表中,并且我的脚本可以读取其专辑封面(不必下载该歌曲),但是例如,在浏览新建"或为您准备"部分时,并播放歌曲时,我的脚本将无法读取它,并且我的应用程序将崩溃.
Does anybody know why this won't work when playing direct from Apple Music?
So I could add an Apple Music song to my Library or to a playlist, and my script can read its album art (the song doesn't have to be downloaded), but when just browsing the New or For You section, for example, and playing a song, my script won't read it and my application will crash.
任何建议将不胜感激,因为我希望任何希望它能够使用此应用程序的人.
Any suggestions would be greatly appreciated as I'd love for anyone who wants it to be able to use this application.
推荐答案
抱歉,在流式传输Apple Music时,当前曲目是 URL曲目 >.尽管这是从 track 继承的,但是图稿元素列表不会通过iTunes脚本显示,因此没有可用的封面.
Sorry, when streaming Apple Music the current track is a URL track. Although this inherits from track, the artwork element list is not exposed through iTunes scriptability so no cover art is available.
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
这篇关于如何通过Apple Script在iTunes中访问Apple Music专辑封面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!