stevetunes/mpc_shim.rb
2022-05-01 17:10:02 -04:00

71 lines
1.1 KiB
Ruby

class MpcShim
def update()
`mpc #{@host_arg} update`
end
def clear()
`mpc #{@host_arg} clear`
end
def play()
`mpc #{@host_arg} play`
end
def stop()
`mpc #{@host_arg} stop`
end
def next()
`mpc #{@host_arg} next`
end
def reset()
`mpc #{@host_arg} clear`
`mpc #{@host_arg} add /`
`mpc #{@host_arg} shuffle`
`mpc #{@host_arg} repeat`
end
def update()
`mpc #{@host_arg} update`
end
def toggle()
`mpc #{@host_arg} toggle`
end
def add(filename = nil)
if filename == nil
`mpc #{@host_arg} add /`
else
`mpc #{@host_arg} add #{filename}`
end
return $?.success?
end
def start()
`systemctl start mpd` unless `ps aux | grep mpd` != ""
`mpc #{@host_arg} repeat`
end
def running?()
return `ps aux | grep mpd` == ""
end
def playing?()
return `mpc status | grep playing` == ""
end
def nowplaying()
return `mpc #{@host_arg} | head -n 1`
end
def initialize(hostname=:localhost)
if hostname != :localhost
@host_arg = "--host #{hostname} "
end
true
end
end