0
0

SpotifyAPIを使わずにSpotifyをいじる。(Mac, Linux)

Posted at

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]

使用例

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0