All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010, Adrian C. <anrxc@sysphere.org>
10 local markup = require("lain.util.markup")
11 local helpers = require("lain.helpers")
13 local awful = require("awful")
14 local beautiful = require("beautiful")
15 local naughty = require("naughty")
16 local wibox = require("wibox")
19 local os = { execute = os.execute,
21 local string = { gmatch = string.gmatch }
23 local setmetatable = setmetatable
27 local mpd = { id = nil }
30 local args = args or {}
31 local password = args.password or ""
32 local host = args.host or "127.0.0.1"
33 local port = args.port or "6600"
34 local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
35 local refresh_timeout = args.refresh_timeout or 1
36 local notify_timeout = args.notify_timeout or 5
37 local color_artist = args.color_artist or beautiful.fg_normal or "#FFFFFF"
38 local color_song = args.color_song or beautiful.fg_focus or "#FFFFFF"
39 local spr = args.spr or ""
40 local musicplr = args.musicplr or "ncmpcpp"
41 local shadow = args.shadow or false
43 local mpdcover = helpers.scripts_dir .. "mpdcover"
44 local mpdh = "telnet://"..host..":"..port
45 local echo = "echo 'password "..password.."\nstatus\ncurrentsong\nclose'"
47 local mympd = wibox.widget.textbox()
49 helpers.set_map("current mpd track", nil)
51 local mympdupdate = function()
52 local function set_nompd()
57 mympd:set_markup(markup(color_artist, " mpd "), markup(color_song , "off "))
70 -- Get data from MPD server
71 local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh)
73 for line in f:lines() do
74 for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
75 if k == "state" then mpd_state["{"..k.."}"] = v
76 elseif k == "file" then mpd_state["{"..k.."}"] = v
77 elseif k == "Artist" then mpd_state["{"..k.."}"] = awful.util.escape(v)
78 elseif k == "Title" then mpd_state["{"..k.."}"] = awful.util.escape(v)
79 elseif k == "Album" then mpd_state["{"..k.."}"] = awful.util.escape(v)
80 elseif k == "Date" then mpd_state["{"..k.."}"] = awful.util.escape(v)
87 if mpd_state["{state}"] == "play"
89 if mpd_state["{Title}"] ~= helpers.get_map("current mpd track")
91 helpers.set_map("current mpd track", mpd_state["{Title}"])
92 os.execute(mpdcover .. " '" .. music_dir .. "' '"
93 .. mpd_state["{file}"] .. "'")
94 mpd.id = naughty.notify({
95 title = "Now playing",
96 text = mpd_state["{Artist}"] .. " (" ..
97 mpd_state["{Album}"] .. ") - " ..
98 mpd_state["{Date}"] .. "\n" ..
100 icon = "/tmp/mpdcover.png",
101 fg = beautiful.fg_focus or "#FFFFFF",
102 bg = beautiful.bg_normal or "#000000" ,
103 timeout = notify_timeout,
107 mympd:set_markup(markup(color_artist, " " .. mpd_state["{Artist}"])
109 markup(color_song, " " .. mpd_state["{Title}"] .. " "))
110 elseif mpd_state["{state}"] == "pause"
112 mympd:set_markup(markup(color_artist, " mpd")
114 markup(color_song, " paused "))
116 helpers.set_map("current mpd track", nil)
121 local mympdtimer = timer({ timeout = refresh_timeout })
122 mympdtimer:connect_signal("timeout", mympdupdate)
124 mympdtimer:emit_signal("timeout")
126 mympd:buttons(awful.util.table.join(
129 helpers.run_in_terminal(musicplr)
133 local mpd_out = { widget = mympd, notify = mympdupdate }
135 return setmetatable(mpd_out, { __index = mpd_out.widget })
138 return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })