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 helpers = require("lain.helpers")
12 local util = require("awful.util")
13 local naughty = require("naughty")
14 local wibox = require("wibox")
16 local io = { popen = io.popen }
17 local os = { execute = os.execute,
19 local string = { format = string.format,
20 gmatch = string.gmatch }
22 local setmetatable = setmetatable
28 local function worker(args)
29 local args = args or {}
30 local timeout = args.timeout or 2
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 settings = args.settings or function() end
37 local mpdcover = helpers.scripts_dir .. "mpdcover"
38 local mpdh = "telnet://" .. host .. ":" .. port
39 local echo = "echo 'password " .. password .. "\nstatus\ncurrentsong\nclose'"
41 mpd.widget = wibox.widget.textbox('')
43 notification_preset = {
44 title = "Now playing",
48 helpers.set_map("current mpd track", nil)
60 local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 1 " .. mpdh)
62 for line in f:lines() do
63 for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
64 if k == "state" then mpd_now.state = v
65 elseif k == "file" then mpd_now.file = v
66 elseif k == "Artist" then mpd_now.artist = util.escape(v)
67 elseif k == "Title" then mpd_now.title = util.escape(v)
68 elseif k == "Album" then mpd_now.album = util.escape(v)
69 elseif k == "Date" then mpd_now.date = util.escape(v)
76 notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
77 mpd_now.album, mpd_now.date, mpd_now.title)
81 if mpd_now.state == "play"
83 if mpd_now.title ~= helpers.get_map("current mpd track")
85 helpers.set_map("current mpd track", mpd_now.title)
87 os.execute(string.format("%s %q %q", mpdcover, music_dir, mpd_now.file))
89 mpd.id = naughty.notify({
90 preset = notification_preset,
91 icon = "/tmp/mpdcover.png",
95 elseif mpd_now.state ~= "pause"
97 helpers.set_map("current mpd track", nil)
101 helpers.newtimer("mpd", timeout, mpd.update)
103 return setmetatable(mpd, { __index = mpd.widget })
106 return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })