#!/bin/bash

EICON='/usr/share/click-radio/icons/error.svg'
PLAYR='mpv'
CONF="$HOME/.config/clickradio"

pkill -f "Click Radio"
pkill -f "createplay"
PID=`ps -eaf | grep "mpv" | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID
fi
D="$CONF/plist"
if [ "$(ls -A $D )" ]; then
exec $@
else
$(yad --width=400 --height=100 --fixed --center \
--text="\n\nNo music files was added to the playlist?\nAdd a playlist folder from <b>Create</b> in menu list.\n" \
--window-icon=$EICON \
--image=$EICON \
--title="Empty Playlist" \
--button="Cancel"!/usr/share/click-radio/icons/cancel.svg:1)
/usr/bin/click-radio
exit 0
fi
python3 /usr/share/click-radio/menu/notify/"My Playlist" &
while [[ 1 ]]; do
b=( $CONF/plist );
n=("$CONF/plist"/*);
s=${n[$(($RANDOM%${#n[@]}))]};
$PLAYR --audio-display=no "$s" 2>&1;
done

