Skip to content

Instantly share code, notes, and snippets.

@veny
Last active August 29, 2015 14:12
Show Gist options
  • Save veny/ed7d6c4619961069e33d to your computer and use it in GitHub Desktop.
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).
#!/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:vaclav.sykora@gmail.com)
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