Skip to content

Instantly share code, notes, and snippets.

@Sledge
Created March 29, 2011 14:15
Show Gist options
  • Save Sledge/892428 to your computer and use it in GitHub Desktop.
Save Sledge/892428 to your computer and use it in GitHub Desktop.
Small Ruby script to skip unwanted tracks in spotify (radio-mode) on linux/ubuntu (native mode)
#!/usr/bin/env ruby
# This is my current blacklist when playing spotify in radio mode with "heavy metal".
blacklist = ['Nickelback', 'Scorpions', 'Watain', 'Mayhem', 'Guns N\' Roses']
# gem install ruby-dbus
require "dbus"
session_bus = DBus::SessionBus.instance
# Get in touch with the Spotify service
spotify = session_bus.service("org.mpris.MediaPlayer2.spotify")
# Get the object from this service
player = spotify.object("/org/mpris/MediaPlayer2")
# Introspect it
player.introspect
if player.has_iface? "org.mpris.MediaPlayer2.Player"
player_iface = player["org.mpris.MediaPlayer2.Player"]
end
# Main loop
loop do
artist = player_iface["Metadata"]["xesam:artist"]
if blacklist.include?(artist)
t = Time.now
puts t.strftime("(%H:%M) #{artist} is blacklisted, switching to next track")
player_iface.Next
end
sleep(3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment