KITHUB夏アドカレです。
下書きに眠ってたので投稿します。
Mac
mac.py
import osascript
track_osa = 'tell application "Spotify" to name of current track as string'
artist_osa = 'tell application "Spotify" to artist of current track as string'
play_stop_osa = 'tell application "Spotify" to playpause'
next_osa = 'tell application "Spotify" to next track'
back_osa = 'tell application "Spotify" to back track'
osascript.run(play_stop_osa)
osascript.run(next_osa)
track = osascript.run(track_osa)[1]
artist = osascript.run(artist_osa)[1]
Linux
linux.py
import dbus
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify","/org/mpris/MediaPlayer2")
spotify_pro = dbus.Interface(spotify_bus,"org.freedesktop.DBus.Properties")
metadata = spotify_pro.Get("org.mpris.MediaPlayer2.Player","Metadata")
title = metadata["xesam:title"]
artUrl = metadata["mpris:artUrl"]
artist = ",".join([x for x in metadata["xesam:artist"]])
track_id = metadata["mpris:trackid"].split(":")[-1]
使用例