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) 2014, anticlockwise <http://github.com/anticlockwise>
9 local helpers = require("lain.helpers")
10 local async = require("lain.asyncshell")
12 local escape_f = require("awful.util").escape
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
26 local function worker(args)
27 local args = args or {}
28 local timeout = args.timeout or 2
29 local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
30 local cover_size = args.cover_size or 100
31 local default_art = args.default_art or ""
32 local settings = args.settings or function() end
34 local mpdcover = helpers.scripts_dir .. "mpdcover"
36 moc.widget = wibox.widget.textbox('')
38 moc_notification_preset = {
39 title = "Now playing",
43 helpers.set_map("current moc track", nil)
46 -- mocp -i will produce output like:
50 async.request("mocp -i", function(f)
61 for line in f:lines() do
62 for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
63 if k == "State" then moc_now.state = v
64 elseif k == "File" then moc_now.file = v
65 elseif k == "Artist" then moc_now.artist = escape_f(v)
66 elseif k == "SongTitle" then moc_now.title = escape_f(v)
67 elseif k == "Album" then moc_now.album = escape_f(v)
68 elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
69 elseif k == "TotalTime" then moc_now.total = escape_f(v)
74 moc_notification_preset.text = string.format("%s (%s) - %s\n%s", moc_now.artist,
75 moc_now.album, moc_now.total, moc_now.title)
79 if moc_now.state == "PLAY" then
80 if moc_now.title ~= helpers.get_map("current moc track") then
81 helpers.set_map("current moc track", moc_now.title)
82 os.execute(string.format("%s %q %q %d %q", mpdcover, "",
83 moc_now.file, cover_size, default_art))
85 moc.id = naughty.notify({
86 preset = moc_notification_preset,
87 icon = "/tmp/mpdcover.png",
91 elseif moc_now.state ~= "PAUSE" then
92 helpers.set_map("current moc track", nil)
97 helpers.newtimer("moc", timeout, moc.update)
99 return setmetatable(moc, { __index = moc.widget })
102 return setmetatable(moc, { __call = function(_, ...) return worker(...) end })