MPD jingles

I recently create a bash script in order to automatically insert jingles into the mpd playlist:

# directory of the database containing the jingles 
# frequence of the jingles (one jingle every x tracks)

# We add a random jingle at $FREQ position after the current playing song
# if there is no jingle in the next 2*$FREQ positions 

# current played song position
CURRENT=`mpc status | grep -oP '(?<=\[playing\] #)\d+'`

# if there is no playing song, exit
if [[ -z $CURRENT ]]
    exit 0

# identify the next jingle
NEXT_JINGLE=`mpc playlist | tail -n +$CURRENT | head -n $((2*$FREQ)) | grep -hn "$JINGLE_DIR"`
# new jingles position 
LENGTH=`mpc playlist | wc -l`

if [[ -z $NEXT_JINGLE && (( $NEW_POS < $LENGTH )) ]]
    # get random jingle
    JINGLE=`mpc ls "$JINGLE_DIR" |shuf -n 1`
    echo "Insert $JINGLE at position $NEW_POS"
    # insert the jingles at the end of the playlist
    # and move it at $NEW_POS
    mpc add "$JINGLE" && mpc mv $(($LENGTH + 1)) $NEW_POS

exit 0

The script is called each minute using following crontab entry:

# m  h  dom mon dow   command
  *  *   *   *   *    /home/user/ >>/tmp/mpc_jingle.log 2>&1

This post accepts webmentions. Do you have the URL to your post?

Otherwise, send your comment on my service.

Or interact from the fediverse with your username: