From fbd3d16d518e52483b87938e9a99fb54dc6df79a Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 8 May 2022 04:05:07 +0000 Subject: [PATCH] prevent panic --- api/kill_panic.sh | 7 +++++++ api/search | 39 +++++++++++---------------------------- api/style.css | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 28 deletions(-) create mode 100755 api/kill_panic.sh create mode 100644 api/style.css diff --git a/api/kill_panic.sh b/api/kill_panic.sh new file mode 100755 index 0000000..2d63b61 --- /dev/null +++ b/api/kill_panic.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +sleep 1 + +if [[ $(cat /tmp/spotify-dl.log) == '' ]]; then + kill -9 $(ps -aux | grep "lib/spotify-ripper" | grep -v grep | awk '{print $2}') +fi diff --git a/api/search b/api/search index e01c8cc..e498006 100755 --- a/api/search +++ b/api/search @@ -7,20 +7,28 @@ 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" -result=$(../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) +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

+

$track







" else - echo "
No result found
" + echo "
No result found, please try again.
" # echo "" fi ## redirection: echo "" -echo " - -" - echo "" diff --git a/api/style.css b/api/style.css new file mode 100644 index 0000000..878828c --- /dev/null +++ b/api/style.css @@ -0,0 +1,24 @@ +echo " + +"