0
我需要的方式来获得使用Python当前播放Spotify的歌曲,但在MacOS塞拉利昂,我知道如何做到这一点在Windows上,但我不能找到一个模块,它适用于MacOS在Mac上播放Spotify曲目?
感谢
我需要的方式来获得使用Python当前播放Spotify的歌曲,但在MacOS塞拉利昂,我知道如何做到这一点在Windows上,但我不能找到一个模块,它适用于MacOS在Mac上播放Spotify曲目?
感谢
我只是写了一个python代码来获取当前播放的歌曲名称和艺术家,并将它显示为Mac上的通知。您还可以访问不同的变量并控制播放/暂停下一首歌曲的功能。
您可以在Applications/Spotify.app/Contents/Resources/Spotify.sdef文件中查找这些变量。因此,您可以在Python应用程序中使用它们。
编辑:我想你必须在你的Python应用中使用AppleScript来控制Spotify使用Python或其他语言。
Spotify Developer page for AppleScript API
这里是我的代码:
#! /usr/bin/python
from Foundation import *
apple_script_code = """
set currentlyPlayingTrack to getCurrentlyPlayingTrack()
displayTrackName(currentlyPlayingTrack)
on getCurrentlyPlayingTrack()
tell application "Spotify"
set currentArtist to artist of current track as string
set currentTrack to name of current track as string
return currentArtist & " - " & currentTrack
end tell
end getCurrentlyPlayingTrack
on displayTrackName(trackName)
display notification trackName
delay 1
end displayTrackName
"""
s = NSAppleScript.alloc().initWithSource_(apple_script_code)
s.executeAndReturnError_(None)