You are not logged in.

#1 2009-04-25 08:55:30

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Need help with mpd script

Mpd has this new mode where it removes played songs from playlist. I thought this is perfect for dynamic playlist support since all you need to do is add 10 random songs to playlist and after each played song add another one.
In an ideal world this would be done in C because libmpdclient does support the idle protocol of mpd (detects track changes and stuff)

Well this is no ideal world and C is above my knowledge smile


So i try to do it in bash and have to realise i am even to stupid to do it this way.
i have the comand that actually adds songs to the playlist:

mpc clear && mpc listall | sort -R | head -n 10 | mpc add && mpc play

I also have the command that adds another song if song changes:

mpc listall | sort -R | head -n 1 | mpc add

what i need now is a function that compares the output of "mpc | head -n 1" every couple of seconds and if it changes it issues this last command...

Or maybe someone wants the same thing and does it using C smile


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#2 2009-04-25 10:08:34

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Need help with mpd script

#!/bin/bash
TIMEOUT=1
ORIG=""
while(true); do
NOW=$(mpc | head -n 1)
if [[ $ORIG =~ $NOW ]]
then
        echo "Song still playing";
else
        echo "Song changed to: \"$NOW\"";
        ORIG=$NOW;
fi
sleep $TIMEOUT
done

Last edited by Wra!th (2009-04-25 10:36:19)


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#3 2009-04-25 11:49:38

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Need help with mpd script

thank you very much.. its working perfecly!


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

Board footer

Powered by FluxBB