From 8c66dc7aa7545b4f43bf42168fcd2e0ef06ebefd Mon Sep 17 00:00:00 2001 From: Aman Date: Wed, 4 Mar 2026 09:21:29 +0530 Subject: [PATCH] fix(musicRecognition): restore 2s interval and fix songrec process leak --- .../musicRecognition/recognize-music.sh | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dots/.config/quickshell/ii/scripts/musicRecognition/recognize-music.sh b/dots/.config/quickshell/ii/scripts/musicRecognition/recognize-music.sh index c0d88e7f8..456ed963d 100755 --- a/dots/.config/quickshell/ii/scripts/musicRecognition/recognize-music.sh +++ b/dots/.config/quickshell/ii/scripts/musicRecognition/recognize-music.sh @@ -1,8 +1,9 @@ #!/bin/bash -INTERVAL=10 +INTERVAL=2 TOTAL_DURATION=30 SOURCE_TYPE="monitor" # monitor | input +FIFO=$(mktemp -u /tmp/songrec_out_XXXXXX) while getopts "i:t:s:" opt; do case $opt in @@ -30,19 +31,25 @@ if [ -z "$AUDIO_DEVICE" ] || ! pactl list short sources | grep -q "$AUDIO_DEVICE exit 1 fi +mkfifo "$FIFO" + cleanup() { kill "$SONGREC_PID" 2>/dev/null || true + wait "$SONGREC_PID" 2>/dev/null + rm -f "$FIFO" } trap cleanup EXIT -songrec listen --audio-device "$AUDIO_DEVICE" --request-interval "$INTERVAL" --json --disable-mpris | while IFS= read -r line; do - if echo "$line" | grep -q '"matches": \['; then - echo "$line" - kill "$SONGREC_PID" 2>/dev/null || true - exit 0 - fi -done & +songrec listen --audio-device "$AUDIO_DEVICE" --request-interval "$INTERVAL" --json --disable-mpris > "$FIFO" & SONGREC_PID=$! -sleep "$TOTAL_DURATION" +( sleep "$TOTAL_DURATION" && kill "$SONGREC_PID" 2>/dev/null ) & + +while IFS= read -r line; do + if echo "$line" | grep -q '"matches": \['; then + echo "$line" + exit 0 + fi +done < "$FIFO" + exit 0