Uzsolt moc widget

From awesome
Jump to: navigation, search

Only a skeleton to create a hook to moc (music on console):


function hook_moc()
       moc_info = io.popen("mocp -i"):read("*all")
       moc_state = string.gsub(string.match(moc_info, "State: %a*"),"State: ","")
       if moc_state == "PLAY" or moc_state == "PAUSE" then
           moc_artist = string.gsub(string.match(moc_info, "Artist: %C*"), "Artist: ","")
           moc_title = string.gsub(string.match(moc_info, "SongTitle: %C*"), "SongTitle: ","")
           moc_curtime = string.gsub(string.match(moc_info, "CurrentTime: %d*:%d*"), "CurrentTime: ","")
           moc_totaltime = string.gsub(string.match(moc_info, "TotalTime: %d*:%d*"), "TotalTime: ","")
           if moc_artist == "" then 
               moc_artist = "unknown artist" 
           end
           if moc_title == "" then 
               moc_title = "unknown title" 
           end
           moc_string = "MOC: " .. moc_artist .. " - " .. moc_title .. "(" .. moc_curtime .. "/" .. moc_totaltime .. ")"
           if moc_state == "PAUSE" then 
               moc_string = " [[ " .. moc_string .. " ]]"
           end
       else
           moc_string = "-- not playing --"
       end
       tb_moc.text = moc_string
end
Personal tools