mpv reloads properly if it crashes

This commit is contained in:
DeaDvey 2024-11-05 01:20:33 +00:00
parent 3e947c2199
commit d52f821408

View File

@ -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 "<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
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
previous_songs_path=$path
sleep 0.5
done
fi
previous_songs_path=$path
sleep 0.5
done