added network monitoring plugin
[wmiirc-lua.git] / plugins / mpd.lua
blobf7a896907009b57417b53b28feb943773f96a2d9
1 --[[
2 =pod
4 =head1 NAME
6 mpd.lua - wmiirc-lua plugin for monitoring and controlling mpd (music player daemon)
8 =head1 SYNOPSIS
10 -- in your wmiirc.lua:
11 wmii.load_plugin("cpu")
14 =head1 DESCRIPTION
16 =head1 SEE ALSO
18 L<wmii(1)>, L<lua(1)>
20 =head1 AUTHOR
22 Jan-David Quesel <jdq@gmx.net>
24 =head1 LICENCE AND COPYRIGHT
26 Copyright (c) 2008, Jan-David Quesel <jdq@gmx.net>
28 This is free software. You may redistribute copies of it under the terms of
29 the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
30 is NO WARRANTY, to the extent permitted by law.
32 =cut
33 --]]
34 local wmii = require("wmii")
35 local io = require("io")
36 local os = require("os")
37 local string = require("string")
38 local tonumber = tonumber
40 module("mpd")
41 api_version=0.1
43 -- ------------------------------------------------------------
44 -- Configuration Settings
45 wmii.set_conf ("mpd.server", "127.0.0.1")
46 wmii.set_conf ("mpd.port", "6600")
48 -- ------------------------------------------------------------
49 -- Init Plugin
50 local widget = wmii.widget:new ("301_mpd_status")
52 local function _command ( cmd )
54 if (cmd) then
55 wmii.log( "about to run " .. cmd)
56 local file = io.popen( cmd)
57 local status = file:read("*a")
58 file:close()
60 return status:match("[^\n]*")
61 else
62 return ""
63 end
64 end
66 local function update_mpd_status (time_since_update)
67 local printout = _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc")
69 widget:show(printout)
70 return 5
71 end
73 function next_song()
74 _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc next")
75 update_mpd_status(0)
76 end
78 function prev_song()
79 _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc prev")
80 update_mpd_status(0)
81 end
83 function toggle_pause()
84 _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc toggle")
85 update_mpd_status(0)
86 end
88 function stop()
89 _command("export MPD_HOST=" .. wmii.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii.get_conf("mpd.port") .. " && mpc stop")
90 update_mpd_status(0)
91 end
93 local timer = wmii.timer:new (update_mpd_status, 1)