ponymap/plugins/mpd.lua

41 lines
1.2 KiB
Lua
Raw Normal View History

2015-05-13 06:08:49 +02:00
--
-- mpd.lua: Music Player Daemon service detection plugin
--
-- Copyright (c) 2015, Přemysl Janouch <p@janouch.name>
2015-05-13 06:08:49 +02:00
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted.
2015-05-13 06:08:49 +02:00
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
-- OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
-- CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--
ponymap.check_api_version (1)
local MPD = {}
MPD.__index = MPD
function MPD.new (unit)
return setmetatable ({ unit = unit, buf = "" }, MPD)
end
function MPD:on_data (data)
self.buf = self.buf .. data
2017-01-29 20:56:27 +01:00
local line = self.buf:match ("([^\n]*)\n")
2015-05-13 06:08:49 +02:00
if line then
2017-01-29 20:56:27 +01:00
local version = line:match ("OK MPD (.*)")
2015-05-13 06:08:49 +02:00
if version then
self.unit:add_info ("version " .. version)
self.unit:set_success (true)
end
2015-05-13 06:57:06 +02:00
self.unit:stop ()
2015-05-13 06:08:49 +02:00
end
end
2017-01-29 22:52:22 +01:00
ponymap.register_service { name="MPD", flags=0, new_scan=MPD.new }