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.
3 Licensed under GNU General Public License v2
4 * (c) 2014, anticlockwise <http://github.com/anticlockwise>
8 local helpers = require("lain.helpers")
9 local shell = require("awful.util").shell
10 local focused = require("awful.screen").focused
11 local escape_f = require("awful.util").escape
12 local naughty = require("naughty")
13 local wibox = require("wibox")
14 local os = { getenv = os.getenv }
15 local string = { format = string.format,
16 gmatch = string.gmatch }
19 -- lain.widget.contrib.moc
21 local function factory(args)
22 local moc = { widget = wibox.widget.textbox() }
23 local args = args or {}
24 local timeout = args.timeout or 2
25 local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
26 local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$"
27 local cover_size = args.cover_size or 100
28 local default_art = args.default_art or ""
29 local followtag = args.followtag or false
30 local settings = args.settings or function() end
32 moc_notification_preset = { title = "Now playing", timeout = 6 }
34 helpers.set_map("current moc track", nil)
37 helpers.async("mocp -i", function(f)
48 for line in string.gmatch(f, "[^\n]+") do
49 for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
50 if k == "State" then moc_now.state = v
51 elseif k == "File" then moc_now.file = v
52 elseif k == "Artist" then moc_now.artist = escape_f(v)
53 elseif k == "SongTitle" then moc_now.title = escape_f(v)
54 elseif k == "Album" then moc_now.album = escape_f(v)
55 elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
56 elseif k == "TotalTime" then moc_now.total = escape_f(v)
61 moc_notification_preset.text = string.format("%s (%s) - %s\n%s", moc_now.artist,
62 moc_now.album, moc_now.total, moc_now.title)
66 if moc_now.state == "PLAY" then
67 if moc_now.title ~= helpers.get_map("current moc track") then
68 helpers.set_map("current moc track", moc_now.title)
70 if followtag then moc_notification_preset.screen = focused() end
73 preset = moc_notification_preset,
75 icon_size = cover_size,
79 local path = string.format("%s/%s", music_dir, string.match(moc_now.file, ".*/"))
80 local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern)
81 helpers.async({ shell, "-c", cover }, function(current_icon)
82 common.icon = current_icon:gsub("\n", "")
83 moc.id = naughty.notify(common).id
86 elseif moc_now.state ~= "PAUSE" then
87 helpers.set_map("current moc track", nil)
92 moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)