1 ---------------------------------------------------
2 -- Licensed under the GNU General Public License v2
3 -- * (c) 2009, Adrian C. <anrxc.sysphere.org>
4 -- * (c) Wicked, Lucas de Vries
5 -- moc plugin written by Zsolt Udvari <udvzsolt.gmail.com>
6 ---------------------------------------------------
8 -- {{{ Grab environment
9 local io = { popen = io.popen }
10 local setmetatable = setmetatable
11 local helpers = require("vicious.helpers")
22 -- Moc: provides the currently playing song in Moc
26 -- {{{ MOC widget type
27 local function worker(format)
29 local f = io.popen("mocp -i")
30 local np = f:read("*all")
40 -- Check if it's stopped, off or not installed
45 state = string.match(np, "State: %a*")
46 state = string.gsub(state,"State: ","")
47 if state ~= "STOP" then
48 artist = string.gsub(string.match(np,"Artist: %C*") or artist,"Artist: ","")
49 title = string.gsub(string.match(np,"SongTitle: %C*") or title,"SongTitle: ","")
50 filename = string.gsub(string.match(np,"File: %C*") or filename,"File: ","")
51 curtime = string.gsub(string.match(np,"CurrentTime: %d*:%d*") or curtime,"CurrentTime: ","")
52 totaltime = string.gsub(string.match(np,"TotalTime: %d*:%d*") or totaltime,"TotalTime: ","")
54 state = helpers.escape(state)
55 artist = helpers.escape(artist)
56 title = helpers.escape(title)
57 filename = helpers.escape(filename)
58 curtime = helpers.escape(curtime)
59 totaltime = helpers.escape(totaltime)
62 return {state,artist,title,filename,curtime,totaltime}
66 setmetatable(_M, { __call = function(_, ...) return worker(...) end })