From d52f821408c6f7acc2e8cdc233c2287f76c341e9 Mon Sep 17 00:00:00 2001 From: DeaDvey Date: Tue, 5 Nov 2024 01:20:33 +0000 Subject: [PATCH] mpv reloads properly if it crashes --- mpvmusic.sh | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/mpvmusic.sh b/mpvmusic.sh index 71d17a6..95a01b6 100755 --- a/mpvmusic.sh +++ b/mpvmusic.sh @@ -27,34 +27,30 @@ handle_sigint() { trap handle_sigint SIGINT while [ $quit_mpv = false ]; do - #echo $quit_mpv - mpv_running=$(pidof mpv) - if [ -z "$mpv_running" ] && [ $quit_mpv = false ]; then + if [ -z "$(pidof mpv)" ] && [ $quit_mpv = false ]; then echo "mpv process not found, (re)starting..." mpv --shuffle --really-quiet $playlist_path --input-ipc-server=/tmp/mpvsocket & + sleep 0.5 fi - 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}') + 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 + echo Song name: $name + echo Artist: $artist - if [ -n $webpage_path ]; then - echo "

Currently listening to:

" > $webpage_path - echo Name: $name"
" >> $webpage_path - echo Artist: $artist"
" >> $webpage_path - echo "
" >> $webpage_path - echo "
" >> $webpage_path - echo "
" >> $webpage_path - fi + if [ -n $webpage_path ]; then + echo "

Currently listening to:

" > $webpage_path + echo Name: $name"
" >> $webpage_path + echo Artist: $artist"
" >> $webpage_path + echo "
" >> $webpage_path + echo "
" >> $webpage_path + echo "
" >> $webpage_path fi - previous_songs_path=$path - sleep 0.5 - done + fi + previous_songs_path=$path + sleep 0.5 done