Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_amarok.lua
blob52b608e34d4eac729e4bba6360c6c2bc0d66119a
1 -- Authors: Mark Tran <mark@nirv.net>
2 -- License: Unknown
3 -- Last Changed: Unknown
4 --
5 -- statusd_amarok.lua : Mark Tran <mark@nirv.net>
7 -- Display current track from Amarok
9 if not statusd_amarok then
10 statusd_amarok = { interval = 3*1000 }
11 end
13 local function amarok_dcop()
14 local f = io.popen('dcop amarok player nowPlaying 2> /dev/null', 'r')
15 local amarok = f:read('*l')
16 f:close()
18 return amarok
19 end
21 local function amarok_status()
22 local f = io.popen('dcop amarok player status 2> /dev/null', 'r')
23 local status = f:read('*l')
24 f:close()
26 return status
27 end
29 local function change_display()
30 local status = amarok_status()
32 if status == "0" then
33 return ""
34 elseif status == "1" then
35 local amarok = amarok_dcop()
37 if (amarok ~= nil) then
38 return amarok.." (paused)"
39 end
40 elseif status == "2" then
41 return amarok_dcop()
42 else
43 return ""
44 end
45 end
47 local amarok_timer
49 local function update_amarok()
50 statusd.inform("amarok", change_display())
51 amarok_timer:set(statusd_amarok.interval, update_amarok)
52 end
54 amarok_timer = statusd.create_timer()
55 update_amarok()