使用Apple脚本将音乐添加到Apple Music库

发布于 2025-02-13 18:33:53 字数 1435 浏览 0 评论 0原文

我有一个applescript,重复当前track到我的applusic library。虽然,看来该库的容量为(库 + 1的长度),并且每当我使用重复添加新轨道时,此容量不会增加。这意味着,每当我尝试添加另一个曲目时,它都行不通。虽然,如果我删除了任何其他物品,则释放了1个容量,我可以在库中添加其他曲目。

如果我使用Apple Music应用程序将另一个曲目添加到库中,则可以更新容量,并且可以使用AppleScript脚本添加另一个曲目。

tell application "Music"
    set currentTrack to current track
    duplicate currentTrack to source "Library"
end tell

更新:下面的片段似乎正在起作用(这是JXA THO)。 重复方法没有返回添加的曲目(只有true),可能是因为它是一个异步操作。这就是为什么延迟的原因。不确定是否有更好的方法可以实现同样的方法,我对此有些限制。
奖励:更改添加项目的评分。

var music = Application("Music")
var app = Application.currentApplication()
app.includeStandardAdditions = true

var track = music.currentTrack
track.loved = true

var myLib = music.sources['Library']
track.duplicate({ to: myLib })

delay(4)

myLib.tracks().find(t => t.name() === track.name() && t.artist() === track.artist()).rating = 100

更新2: 如果i 创建站...,上面的一个不起作用。如果我播放浏览部分中可用的任何播放列表,则可以按预期进行工作。我开始在这里看到一个模式...看来我只能添加到我的library属于播放列表的曲目。 使用创建站和从另一个播放列表中播放时,我已经比较了同一首歌的属性。唯一的相关区别是两者的ID,其databaseIDpersistentid是不同的。因此,我的假设是这是原因。

update3:this 博客文章解释很多上面的情况。

I have an AppleScript, which duplicates the currentTrack to my AppleMusic Library. Although, it seems that the Library has a capacity of (length of the library + 1), and whenever I add a new track using the duplicate this capacity is not increased. This means, that whenever I try to add another track, it doesn't work. Although, if I remove any other item, then 1 capacity is freed, and I can add another track to my Library.

If I manually add another track to the Library using the Apple Music app, then the capacity is updated, and I can add another track using the AppleScript script.

tell application "Music"
    set currentTrack to current track
    duplicate currentTrack to source "Library"
end tell

Update: the snippet below seems to be working (it's JXA tho). The duplicate method is not returning the added track (just true), probably because it's an async operation. That's why the delay. Not sure if there's a better way to achieve the same, my knowledge of this is a bit limited.
Bonus: Changing the rating of the added item.

var music = Application("Music")
var app = Application.currentApplication()
app.includeStandardAdditions = true

var track = music.currentTrack
track.loved = true

var myLib = music.sources['Library']
track.duplicate({ to: myLib })

delay(4)

myLib.tracks().find(t => t.name() === track.name() && t.artist() === track.artist()).rating = 100

Update 2:
The one above does not work if I Create Station.... It works as expected if I play any of the Playlists available in the Browse section. I'm starting to see a pattern here... it looks like I can only add to my Library the tracks that belong to a Playlist.
I've compared the properties of the same song when played using the Create Station and from another playlist. The only relevant difference is the IDs of both, their databaseID and persistentId are different. So my assumption is that this is the reason.

Update3: this blog post explains a lot the situation above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文