stevetunes/mpc_shim.rb

71 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2021-12-22 19:40:08 +00:00
class MpcShim
def update()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} update`
2021-12-22 19:40:08 +00:00
end
def clear()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} clear`
2021-12-22 19:40:08 +00:00
end
def play()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} play`
2021-12-22 19:40:08 +00:00
end
def stop()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} stop`
2021-12-22 19:40:08 +00:00
end
def next()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} next`
2021-12-22 19:40:08 +00:00
end
def reset()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} clear`
`mpc #{@host_arg} add /`
`mpc #{@host_arg} shuffle`
`mpc #{@host_arg} repeat`
2021-12-22 19:40:08 +00:00
end
def update()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} update`
2021-12-22 19:40:08 +00:00
end
def toggle()
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} toggle`
2021-12-22 19:40:08 +00:00
end
def add(filename = nil)
if filename == nil
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} add /`
2021-12-22 19:40:08 +00:00
else
2022-05-01 20:49:39 +00:00
`mpc #{@host_arg} add #{filename}`
2021-12-22 19:40:08 +00:00
end
return $?.success?
end
2022-05-01 20:42:31 +00:00
def start()
`systemctl start mpd` unless `ps aux | grep mpd` != ""
2022-05-01 21:10:02 +00:00
`mpc #{@host_arg} repeat`
2022-05-01 20:42:31 +00:00
end
def running?()
return `ps aux | grep mpd` == ""
end
2022-05-01 21:10:02 +00:00
def playing?()
return `mpc status | grep playing` == ""
end
2022-05-01 20:42:31 +00:00
def nowplaying()
2022-05-01 21:10:02 +00:00
return `mpc #{@host_arg} | head -n 1`
2022-05-01 20:42:31 +00:00
end
2021-12-22 19:48:31 +00:00
def initialize(hostname=:localhost)
if hostname != :localhost
@host_arg = "--host #{hostname} "
end
2021-12-22 19:40:08 +00:00
true
end
end