#!/bin/bash
echo "content-type: text/html"
echo
echo '
'
source style.css
args=$(echo "$SP_TRACK" | awk -F? '{print $2}' | sed 's/%20/ /g')
#session_id=$(echo $RANDOM | md5sum | head -c 20; echo)
log_file="/tmp/spotify-dl.log"
if [[ $(ps -aux | grep "lib/spotify-ripper" | grep -v grep | awk '{print $2}') != '' ]]; then
echo "Service is already in use, please wait"
exit 1
fi
./kill_panic.sh&
result=$(timeout 600 ../spotify-dl.sh "$args" | tee $log_file 2>&1 | grep "/var/www/spotify-dl/" | grep -v "Format String:" | awk -F/ '{print $NF}' | rev | cut -c6- | rev | head -n1)
track=$(echo "$result" | awk -F '.mp3' '{print $1}')
if [[ $track ]];then
echo "
$track
"
else
echo "No result found, please try again."
# echo ""
fi
## redirection: echo ""
echo ""