aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-13 06:08:49 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-13 06:08:49 +0200
commit2e32296dfc9dc1fd190d17626b40b0fd098452b1 (patch)
treefecd8e4a9c0358453597c38715d6589d010e5169
parent144b8f9c58da2836728235ba2cea82c6ccbcffea (diff)
downloadponymap-2e32296dfc9dc1fd190d17626b40b0fd098452b1.tar.gz
ponymap-2e32296dfc9dc1fd190d17626b40b0fd098452b1.tar.xz
ponymap-2e32296dfc9dc1fd190d17626b40b0fd098452b1.zip
Add an MPD service detection plugin
-rw-r--r--plugins/mpd.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/mpd.lua b/plugins/mpd.lua
new file mode 100644
index 0000000..b513723
--- /dev/null
+++ b/plugins/mpd.lua
@@ -0,0 +1,45 @@
+--
+-- mpd.lua: Music Player Daemon service detection plugin
+--
+-- Copyright (c) 2015, Přemysl Janouch <p.janouch@gmail.com>
+--
+-- Permission to use, copy, modify, and/or distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- 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
+ local line = string.match (self.buf, "([^\n]*)\n")
+ if line then
+ local version = string.match (line, "OK MPD (.*)")
+ if version then
+ self.unit:add_info ("version " .. version)
+ self.unit:set_success (true)
+ end
+ self.unit:abort ()
+ end
+end
+
+ponymap.register_service ({
+ name = "MPD",
+ flags = 0,
+ new_scan = MPD.new
+})