Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save piotr-rudnik/1c4451d582b9ce133db7e7e83352fb73 to your computer and use it in GitHub Desktop.
Save piotr-rudnik/1c4451d582b9ce133db7e7e83352fb73 to your computer and use it in GitHub Desktop.
Spotify almost automatic liric finder
import dbus
import os
from datetime import timedelta
def get_spotify_artist_title():
"""
Get the current song metadatas (artist - title)
"""
bus = dbus.SessionBus()
__bus = bus.get_object(
"org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2"
)
player = dbus.Interface(__bus, "org.freedesktop.DBus.Properties")
metadata = player.Get("org.mpris.MediaPlayer2.Player", "Metadata")
album = metadata.get("xesam:album")
artist = metadata.get("xesam:artist")[0]
microtime = metadata.get("mpris:length")
rtime = str(timedelta(microseconds=microtime))[:-7]
title = metadata.get("xesam:title")
return artist, title
print("https://genius.com/search?q=" + " ".join(get_spotify_artist_title()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment