#!/bin/bash

CONF="$HOME/.simplestream"
PLAYR="/usr/bin/mpv"
ICON="/usr/share/simplestream/menu/icons/simplestream.png"
H1=`cat $CONF/stations | awk 'NR==22{print $0}'`
H2=`cat $CONF/stations | awk 'NR==23{print $0}'`
PID=`ps -eaf | grep mpv | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID > /dev/null 2>&1 
fi &
PID=`ps -eaf | grep simplestream | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID > /dev/null 2>&1
rm -f $CONF/.tmp > /dev/null 2>&1 
exec /usr/share/simplestream/menu/notify/"SimpleStream" 2>&1 |less &
$PLAYR --no-cache $H2 2>&1 |tee > $CONF/.tmp &
sleep 3
echo $H2 > $CONF/url | awk 'NR==1{print $0}'
while true; do
echo $H1 > $CONF/playing | awk 'NR==1{print $0}'
grep -E "icy-title" $CONF/.tmp| sed 's/^............//'| sed 's/(.*//'| sed 's/[[].*//' | tail -n1 >> $CONF/playing
TITLE=`cat $CONF/playing | awk 'NR==1{print $0}'`
sleep 2
`echo \
"$H1
"$TITLE"
" \
| awk '{print $0}' > $CONF/playing`
done
fi &

