From 06d12fb8ecdcebb964fb684d98c7ddb420f0beaa Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Tue, 28 Oct 2025 08:48:57 +0100 Subject: [PATCH] music recognition: add check for songrec command existence --- .../androidStyle/AndroidMusicRecognition.qml | 11 +++++++++-- .../ii/scripts/musicRecognition/musicRecognition.sh | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dots/.config/quickshell/ii/modules/sidebarRight/quickToggles/androidStyle/AndroidMusicRecognition.qml b/dots/.config/quickshell/ii/modules/sidebarRight/quickToggles/androidStyle/AndroidMusicRecognition.qml index f7e475547..621bf7cf0 100644 --- a/dots/.config/quickshell/ii/modules/sidebarRight/quickToggles/androidStyle/AndroidMusicRecognition.qml +++ b/dots/.config/quickshell/ii/modules/sidebarRight/quickToggles/androidStyle/AndroidMusicRecognition.qml @@ -41,14 +41,15 @@ AndroidQuickToggleButton { StyledToolTip { - text: Translation.tr("Identifies currently playing song | Right-click to change monitor source") + text: Translation.tr("Recognize music | Right-click to toggle source") } - onClicked: { + onClicked: { root.toggled = !root.toggled recognizeMusicProc.running = root.toggled musicReconizedProc.running = false } + altAction: () => { if (root.monitorSource === "monitor"){ root.monitorSource = "input" @@ -68,6 +69,12 @@ AndroidQuickToggleButton { handleRecognition(this.text) } } + onExited: (exitCode, exitStatus) => { + if (exitCode === 1) { + Quickshell.execDetached(["notify-send", Translation.tr("Couldn't recognize music"), Translation.tr("Make sure you have songrec installed"), "-a", "Shell"]) + root.toggled = false + } + } } Process { diff --git a/dots/.config/quickshell/ii/scripts/musicRecognition/musicRecognition.sh b/dots/.config/quickshell/ii/scripts/musicRecognition/musicRecognition.sh index 4f129f29d..2f988f145 100755 --- a/dots/.config/quickshell/ii/scripts/musicRecognition/musicRecognition.sh +++ b/dots/.config/quickshell/ii/scripts/musicRecognition/musicRecognition.sh @@ -23,7 +23,7 @@ else exit 1 fi -if [ -z "$MONITOR_SOURCE" ]; then +if [ -z "$MONITOR_SOURCE" ] || ! command -v songrec >/dev/null 2>&1; then exit 1 fi @@ -46,7 +46,6 @@ while true; do fi ffmpeg -f s16le -ar 44100 -ac 2 -i "$TMP_RAW" -acodec libmp3lame -y -hide_banner -loglevel error "$TMP_MP3" 2>/dev/null - RESULT=$(songrec audio-file-to-recognized-song "$TMP_MP3" 2>/dev/null || true) if echo "$RESULT" | grep -q '"matches": \[' && [ ${#RESULT} -gt $MIN_VALID_RESULT_LENGTH ]; then