You are not logged in.

#1 2008-12-10 01:33:26

hack.augusto
Member
From: Brazil
Registered: 2008-08-28
Posts: 124

[solved]mpd - gathering time left

I use dzen bar to keep track of some stuff, like battery and what mpd is playing. I would like to know how much time is left to a song end, the thing is, how can I get this information easilly from mpd?

Last edited by hack.augusto (2008-12-10 16:28:24)

Offline

#2 2008-12-10 04:43:24

elmer_42
Member
From: /na/usa/ca
Registered: 2008-10-11
Posts: 427

Re: [solved]mpd - gathering time left

I believe there is a way to get the total time and the current position from MPD. If this is so, I imagine you could write a script to subtract the current position from the total time. I tried it out in Ruby, but failed. If you want to try to build off of my source, go ahead:

total = `mpc|grep playing|cut -c25-25`
curre = `mpc|grep playing|cut -c20-20`
f = total.to_i - curre.to_i
tot = `mpc|grep playing|cut -c27-27`
cur = `mpc|grep playing|cut -c22-22`
s = tot.to_i - cur.to_i
tota = `mpc|grep playing|cut -c28-28`
curr = `mpc|grep playing|cut -c23-23`
t = tota.to_i - curr.to_i
puts "#{f}:#{s}#{t}"

[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]

Offline

#3 2008-12-10 12:16:20

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [solved]mpd - gathering time left

echo -e 'status\nclose' | nc localhost 6600 | awk -F: '/time/{print $3-$2}'

Offline

#4 2008-12-10 16:27:57

hack.augusto
Member
From: Brazil
Registered: 2008-08-28
Posts: 124

Re: [solved]mpd - gathering time left

Procyon wrote:
echo -e 'status\nclose' | nc localhost 6600 | awk -F: '/time/{print $3-$2}'

great! it redeuced 9 lines of code, thanks

Offline

Board footer

Powered by FluxBB