You are not logged in.

#1 2008-09-27 11:05:12

patogen
Member
Registered: 2008-05-11
Posts: 86

Mpd pause after current song

I'm missing a feature of mpd (mpc/sonata/ncmcppp) is a feature  that I can have "stop after current song", so I wrote an extremely ugly script for zsh:

function pause
{
a="$(    mpc | grep "playing" | awk '{print $3}' | cut -d/ -f1)"
b="$(    mpc | grep "playing" | awk '{print $3}' | cut -d/ -f2)"
c=$(calc "60*$(echo $a | cut -d: -f1) + $(echo $a | cut -d: -f2)")
d=$(calc "60*$(echo $b | cut -d: -f1) + $(echo $b | cut -d: -f2)")
e=`calc "$d-$c"`
sleep $e; mpc toggle
}

As you can see it is very ugly an it depends on the software calc, but it can be easily modified to not depend on calc (however I made it in ~5min). I'm wondering what would the best way to do something that isn't as ugly as this. So, any ideas? The best would probably to make a change in the source code of mpc to handle this feature. I've downloaded the source code ... but it's kinda hard to change a kinda complex (at least to me that can just write really really simple C programs) the source to what I want ...


We met up with the aliens and guess what? They have no word for fluffy!

Offline

#2 2008-09-27 14:24:47

kett
Member
Registered: 2008-04-21
Posts: 104

Re: Mpd pause after current song

sleep $(mpc | awk -F"[ /:]" '/playing/ {print 60*($8-$6)+$9-$7}');mpc pause

That should do the same thing in one line.  awk is a pretty powerful tool.

Offline

#3 2008-09-27 15:02:03

patogen
Member
Registered: 2008-05-11
Posts: 86

Re: Mpd pause after current song

kett wrote:
sleep $(mpc | awk -F"[ /:]" '/playing/ {print 60*($8-$6)+$9-$7}');mpc pause

That should do the same thing in one line.  awk is a pretty powerful tool.

Wow. That's nice, I should look into awk more! That is much prettier, didn't know that it was that powerful! Thank you very much, will read more about awk to be able to solve other problems! smile


We met up with the aliens and guess what? They have no word for fluffy!

Offline

Board footer

Powered by FluxBB