exits gracefully
This commit is contained in:
parent
54b2e84dcf
commit
3e947c2199
72
mpvmusic.sh
72
mpvmusic.sh
@ -6,7 +6,6 @@
|
||||
# jq
|
||||
#
|
||||
#set -x
|
||||
|
||||
config_path="$HOME/.config/mpvmusic/config.sh"
|
||||
if [ -f $config_path ]; then
|
||||
echo "config exists"
|
||||
@ -15,40 +14,47 @@ else
|
||||
fi
|
||||
source $config_path
|
||||
previous_songs_path=""
|
||||
#find $playlist_path -type f > song_list.txt
|
||||
export quit_mpv=false
|
||||
kill -9 $(pidof mpv) > /dev/null 2>&1
|
||||
handle_sigint() {
|
||||
echo "Quitting..."
|
||||
export quit_mpv=true
|
||||
echo $quit_mpv
|
||||
pkill -9 $$
|
||||
kill -9 $(pgrep mpv)
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [ 1 == 1 ]; do
|
||||
trap handle_sigint SIGINT
|
||||
while [ $quit_mpv = false ]; do
|
||||
#echo $quit_mpv
|
||||
mpv_running=$(pidof mpv)
|
||||
if [ -z "$mpv_running" ]; then
|
||||
echo "mpv process not found, (re)starting..."
|
||||
mpv --shuffle --really-quiet $playlist_path --input-ipc-server=/tmp/mpvsocket &
|
||||
else
|
||||
echo "mpv is already running"
|
||||
if [ -z "$mpv_running" ] && [ $quit_mpv = false ]; then
|
||||
echo "mpv process not found, (re)starting..."
|
||||
mpv --shuffle --really-quiet $playlist_path --input-ipc-server=/tmp/mpvsocket &
|
||||
fi
|
||||
sleep 1
|
||||
done &
|
||||
|
||||
sleep 1
|
||||
|
||||
while [ 1 == 1 ]; do
|
||||
path=$(echo '{ "command": ["get_property", "path"] }' | socat - "/tmp/mpvsocket" | jq -r '.data')
|
||||
if [[ $path != $previous_songs_path ]]; then
|
||||
clear
|
||||
name=$(exiftool -Title "$path" | awk -F: '{print $2}')
|
||||
artist=$(exiftool -Artist "$path" | awk -F: '{print $2}')
|
||||
|
||||
echo Song name: $name
|
||||
echo Artist: $artist
|
||||
|
||||
if [ -n $webpage_path ]; then
|
||||
echo "<h1>Currently listening to:</h1>" > $webpage_path
|
||||
echo Name: $name"<br/>" >> $webpage_path
|
||||
echo Artist: $artist"<br/>" >> $webpage_path
|
||||
echo "<form action='/music/prev' id='media-control' method='post'><button>previous</button></form>" >> $webpage_path
|
||||
echo "<form action='/music/playpause' id='media-control' method='post'><button>play/pause</button></form>" >> $webpage_path
|
||||
echo "<form action='/music/next' id='media-control' method='post'><button>next</button></form>" >> $webpage_path
|
||||
fi
|
||||
fi
|
||||
previous_songs_path=$path
|
||||
sleep 0.5
|
||||
while [ $quit_mpv = false ]; do
|
||||
path=$(echo '{ "command": ["get_property", "path"] }' | socat - "/tmp/mpvsocket" | jq -r '.data')
|
||||
if [[ $path != $previous_songs_path ]]; then
|
||||
clear
|
||||
name=$(exiftool -Title "$path" | awk -F: '{print $2}')
|
||||
artist=$(exiftool -Artist "$path" | awk -F: '{print $2}')
|
||||
|
||||
echo Song name: $name
|
||||
echo Artist: $artist
|
||||
|
||||
if [ -n $webpage_path ]; then
|
||||
echo "<h1>Currently listening to:</h1>" > $webpage_path
|
||||
echo Name: $name"<br/>" >> $webpage_path
|
||||
echo Artist: $artist"<br/>" >> $webpage_path
|
||||
echo "<form action='/music/prev' id='media-control' method='post'><button>previous</button></form>" >> $webpage_path
|
||||
echo "<form action='/music/playpause' id='media-control' method='post'><button>play/pause</button></form>" >> $webpage_path
|
||||
echo "<form action='/music/next' id='media-control' method='post'><button>next</button></form>" >> $webpage_path
|
||||
fi
|
||||
fi
|
||||
previous_songs_path=$path
|
||||
sleep 0.5
|
||||
done
|
||||
done
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user