Kārlis Millers
Kārlis Millers

Reputation: 674

Linux: MPC current song output

I try to make custom output on my internet Radio. (mpd/mpc)

getInfo.py:

#!/bin/bash
opt=$@
mpc $opt &> /dev/null

station="`mpc --format \"[%name%]\" | head -n 1`"
title="`mpc --format \"[%title%]\" | head -n 1`"
vol="`mpc | head -n 2 | tail -n 1 | awk {'print $4'}`"

echo $station
echo $title
echo "Volume: "${vol//[()_]/}

And save output witch wach -n getInfo.py > radio.log

Output format is here:

Amazing Smooth and Jazz
Koop - Koop Island Blues
Volume: 100%

So i need each time when output changes show output on shell. How to do that?

Upvotes: 2

Views: 6190

Answers (2)

user4401178
user4401178

Reputation:

If you're only looking for the song output to update when changed, mpc has the command current that has a --wait option that tells mpc to block until the next song before displaying the result, this allows you to loop on it. From there you can update whatever software you want with it.

For example:

while :; do notify-send --urgency=low -i "audio-headphones" "$(mpc current --wait)"; done &

Upvotes: 3

MB-F
MB-F

Reputation: 23647

To get you started:

#!/usr/bin/python3
from subprocess import Popen, PIPE

last_output = ""
while(1):
    proc = Popen(["mpc"], stdout=PIPE)
    output, retval = proc.communicate()
    if not output == last_output:
        print(output.decode('ascii'))
    last_output = output

I will leave fine-tuning the output to you.

Upvotes: 1

Related Questions