Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created April 2, 2012 18:40
Show Gist options
  • Save qoobaa/2286192 to your computer and use it in GitHub Desktop.
Save qoobaa/2286192 to your computer and use it in GitHub Desktop.
require "socket"
loop do
begin
socket = TCPSocket.new("localhost", 6600)
time = nil
loop do
socket.puts "status"
message, addrinfo = socket.recvmsg
status = Hash[message.split("\n").map { |line| line.split(": ", 2) }]
`/etc/init.d/mpd restart` if status["state"] == "play" && time == status["time"]
time = status["time"]
sleep 30
end
rescue
sleep 60
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment