Last active
August 29, 2015 14:12
-
-
Save veny/ed7d6c4619961069e33d to your computer and use it in GitHub Desktop.
This script opens lyrics of a song currently played by Spotify in default browser (for Linux, using Ruby and D-Bus).
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
#!/usr/bin/ruby | |
# This script opens lyrics of a song currently played by Spotify in default browser | |
# (for Linux, using Ruby and D-Bus). | |
# | |
# @see https://bbs.archlinux.org/viewtopic.php?id=134635 | |
# @see https://github.com/mvidner/ruby-dbus | |
# | |
# Author:: Vaclav Sykora (mailto:[email protected]) | |
require 'dbus' | |
require 'uri' | |
dbus = DBus::SessionBus.instance | |
service = dbus.service('org.mpris.MediaPlayer2.spotify') | |
object = service.object('/org/mpris/MediaPlayer2') | |
object.introspect | |
player = object['org.mpris.MediaPlayer2.Player'] | |
song_title = player['Metadata']['xesam:title'] | |
song_artist = player['Metadata']['xesam:artist'][0] | |
puts "#{song_artist} : #{song_title}" | |
link = "http://lyrics.wikia.com/#{URI::encode(song_artist)}:#{URI::encode(song_title)}" | |
#link = "http://www.songlyrics.com/#{URI::encode(song_artist)}/#{URI::encode(song_title)}-lyrics/" | |
`xdg-open "#{link}"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment