Created
April 5, 2021 19:52
-
-
Save piotr-rudnik/1c4451d582b9ce133db7e7e83352fb73 to your computer and use it in GitHub Desktop.
Spotify almost automatic liric finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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