Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keys to mpd_now for querying the length of a song and the current time #90

Merged
merged 1 commit into from
Jan 20, 2015
Merged

Conversation

jepugs
Copy link

@jepugs jepugs commented Jan 16, 2015

I added functionality to the mpd widget by extending the mpd_now table with keys mpd_now.elapsed and mpd_now.time, which give the current time in the song and the total length of the current song respectively, in seconds. This is some code from my rc.lua that uses the widget:

-- Represent a number of seconds as a string of minutes:seconds.
function format_time(s)
   return string.format("%d:%.2d", math.floor(s/60), s%60)
end

-- Add an mpd widget
mpdwidget = lain.widgets.mpd({
      settings = function()
         local artist = mpd_now.artist
         local title = mpd_now.title
         local state = ""
         local time = ""
         if mpd_now.time ~= "N/A" and mpd_now.elapsed ~= "N/A" then
            time = string.format("(%s/%s)", format_time(mpd_now.elapsed),
            format_time(mpd_now.time))
         end
         if mpd_now.state == "pause" then
            state = "[Paused]"
         elseif mpd_now.state == "play" then
            state = "[Playing]"
         end
         widget:set_markup(string.format(" %s %s - %s %s ", state, artist, title, time))
      end
})

Example output: [Playing] Danger Mouse - What More Can I Say (1:29/4:25)

lcpz pushed a commit that referenced this pull request Jan 20, 2015
Added keys to mpd_now for querying the length of a song and the current time
@lcpz lcpz merged commit e2a84ec into lcpz:master Jan 20, 2015
lcpz pushed a commit that referenced this pull request Jan 20, 2015
0xforee pushed a commit to 0xforee/lain that referenced this pull request Jan 28, 2015
lcpz pushed a commit that referenced this pull request Aug 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants