Files
illogical-impulse/dots/.config/quickshell/ii/modules/sidebarRight/quickToggles/androidStyle/AndroidMusicRecognition.qml
T
vaguesyntax cf159f6112 some typos
2025-10-26 03:45:43 +03:00

78 lines
2.4 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import qs
import qs.modules.common
import qs.modules.common.widgets
import QtQuick
import Quickshell
import Quickshell.Io
import qs.services
AndroidQuickToggleButton {
id: root
property int timeoutInterval: 5
property int timeoutDuration: Config.options.resources.musicRecognitionTimeout
property string resultsJSON
property string recognizedTrackTitle
property string recognizedTrackSubtitle
property string recognizedTrackURL
name: Translation.tr("Identify Music")
statusText: toggled ? Translation.tr("Listening...") : Translation.tr("Inactive")
toggled: false
buttonIcon: toggled ? "cadence" : "graphic_eq"
onClicked: {
if (!toggled){
recognizeMusicProc.running = true
} else {
recognizeMusicProc.running = false
}
root.toggled = !root.toggled
}
Process {
id: recognizeMusicProc
running: false
command: [`${Directories.scriptPath}/musicRecognition/musicRecognition.sh`, "-i", root.timeoutInterval, "-t", root.timeoutDuration]
stdout: StdioCollector {
onStreamFinished: {
root.resultsJSON = this.text
if (this.text.length < 100) {
Quickshell.execDetached(["notify-send", "Unable to recognize music", "Please make sure your music is playing and try again", "-a", "Shell"])
toggled = false
return
}
var obj = JSON.parse(root.resultsJSON)
root.recognizedTrackTitle = obj.track.title
root.recognizedTrackSubtitle = obj.track.subtitle
root.recognizedTrackURL = obj.track.url
musicReconizedProc.running = true
toggled = false
}
}
}
Process {
id: musicReconizedProc
running: false
command: [ "notify-send" , "Music Recognized" , root.recognizedTrackTitle + " by " + root.recognizedTrackSubtitle , "-A" , "Shazam Link" , "-a" , "Shell"]
stdout: StdioCollector {
onStreamFinished: {
if (this.text !== ""){
Qt.openUrlExternally(root.recognizedTrackURL);
}
}
}
}
StyledToolTip {
//text: Translation.tr("Identifies the song thats playing right now")
text: "Identifies the song thats playing right now"
}
}