]>
Commit | Line | Data |
---|---|---|
38ba9cb5 ZU |
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 | --------------------------------------------------- | |
7 | ||
8 | -- {{{ Grab environment | |
9 | local io = { popen = io.popen } | |
10 | local setmetatable = setmetatable | |
11 | local helpers = require("vicious.helpers") | |
12 | local string = { | |
13 | find = string.find, | |
14 | gsub = string.gsub, | |
15 | match = string.match | |
16 | } | |
17 | ||
18 | local print = print | |
19 | -- }}} | |
20 | ||
21 | ||
22 | -- Moc: provides the currently playing song in Moc | |
23 | module("vicious.moc") | |
24 | ||
25 | ||
26 | -- {{{ MOC widget type | |
27 | local function worker(format) | |
28 | -- Get data from mocp | |
29 | local f = io.popen("mocp -i") | |
30 | local np = f:read("*all") | |
31 | local state = "" | |
32 | local artist = "" | |
33 | local title = "" | |
34 | local filename = "" | |
35 | local curtime = "" | |
36 | local totaltime = "" | |
37 | ||
38 | f:close() | |
39 | ||
40 | -- Check if it's stopped, off or not installed | |
41 | if np == nil then | |
42 | return {"STOP"} | |
43 | end | |
44 | ||
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: ","") | |
53 | ||
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) | |
60 | end | |
61 | ||
62 | return {state,artist,title,filename,curtime,totaltime} | |
63 | end | |
64 | -- }}} | |
65 | ||
66 | setmetatable(_M, { __call = function(_, ...) return worker(...) end }) |