stevetunes/mpc_shim.rb

71 lines
1.1 KiB
Ruby
Raw Normal View History

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