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?
Advertisement
Answer
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.