forked from Shinonome/dots-hyprland
refactor code
This commit is contained in:
+35
-40
@@ -12,24 +12,37 @@ AndroidQuickToggleButton {
|
|||||||
|
|
||||||
property int timeoutInterval: 5
|
property int timeoutInterval: 5
|
||||||
property int timeoutDuration: Config.options.resources.musicRecognitionTimeout
|
property int timeoutDuration: Config.options.resources.musicRecognitionTimeout
|
||||||
property string resultsJSON
|
|
||||||
|
|
||||||
property string recognizedTrackTitle
|
|
||||||
property string recognizedTrackSubtitle
|
|
||||||
property string recognizedTrackURL
|
|
||||||
|
|
||||||
name: Translation.tr("Identify Music")
|
name: Translation.tr("Identify Music")
|
||||||
statusText: toggled ? Translation.tr("Listening...") : Translation.tr("Inactive")
|
statusText: toggled ? Translation.tr("Listening...") : Translation.tr("Inactive")
|
||||||
toggled: false
|
toggled: false
|
||||||
buttonIcon: toggled ? "cadence" : "graphic_eq"
|
buttonIcon: toggled ? "cadence" : "graphic_eq"
|
||||||
onClicked: {
|
|
||||||
if (!toggled){
|
property var recognizedTrack: ({ title:"", subtitle:"", url:""})
|
||||||
recognizeMusicProc.running = true
|
|
||||||
} else {
|
function handleRecognition(jsonText) {
|
||||||
recognizeMusicProc.running = false
|
try {
|
||||||
|
var obj = JSON.parse(jsonText)
|
||||||
|
root.recognizedTrack = {
|
||||||
|
title: obj.track.title,
|
||||||
|
subtitle: obj.track.subtitle,
|
||||||
|
url: obj.track.url
|
||||||
|
}
|
||||||
|
musicReconizedProc.running = true
|
||||||
|
} catch(e) {
|
||||||
|
Quickshell.execDetached(["notify-send", "Unable to recognize music", "Please make sure your music is playing and try again", "-a", "Shell"])
|
||||||
|
} finally {
|
||||||
|
root.toggled = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledToolTip {
|
||||||
|
text: Translation.tr("Identifies the song that’s currently playing")
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
root.toggled = !root.toggled
|
root.toggled = !root.toggled
|
||||||
|
recognizeMusicProc.running = root.toggled
|
||||||
|
musicReconizedProc.running = false
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
@@ -38,45 +51,27 @@ AndroidQuickToggleButton {
|
|||||||
command: [`${Directories.scriptPath}/musicRecognition/musicRecognition.sh`, "-i", root.timeoutInterval, "-t", root.timeoutDuration]
|
command: [`${Directories.scriptPath}/musicRecognition/musicRecognition.sh`, "-i", root.timeoutInterval, "-t", root.timeoutDuration]
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
root.resultsJSON = this.text
|
handleRecognition(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
|
|
||||||
recognizedMusicKiller.running = true
|
|
||||||
toggled = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: musicReconizedProc
|
id: musicReconizedProc
|
||||||
running: false
|
running: false
|
||||||
command: [ "notify-send" , "Music Recognized" , root.recognizedTrackTitle + " by " + root.recognizedTrackSubtitle , "-A" , "Shazam Link" , "-a" , "Shell"]
|
command: [
|
||||||
|
"notify-send",
|
||||||
|
Translation.tr("Music Recognized"),
|
||||||
|
root.recognizedTrack.title + " - " + root.recognizedTrack.subtitle,
|
||||||
|
"-A", "Shazam",
|
||||||
|
"-a", "Shell"
|
||||||
|
]
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
if (this.text !== ""){
|
if (this.text !== ""){
|
||||||
Qt.openUrlExternally(root.recognizedTrackURL);
|
Qt.openUrlExternally(root.recognizedTrack.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: recognizedMusicKiller
|
|
||||||
running: false; repeat: false
|
|
||||||
interval: 5000
|
|
||||||
onTriggered: musicReconizedProc.running = false
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledToolTip {
|
|
||||||
text: Translation.tr("Identifies the song that’s playing right now")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
MONITOR_SOURCE="alsa_output.pci-0000_00_1f.3.analog-stereo.monitor"
|
## can be added manually if not chosen automatically with running this on terminal 'pw-cli list-objects | grep node.name'
|
||||||
|
MONITOR_SOURCE=$(pactl list short sources 2>/dev/null | grep -m1 monitor | awk '{print $2}' || true)
|
||||||
|
|
||||||
# Default değerler
|
|
||||||
INTERVAL=5
|
INTERVAL=5
|
||||||
TOTAL_DURATION=30
|
TOTAL_DURATION=30
|
||||||
|
MIN_VALID_RESULT_LENGTH=300
|
||||||
|
|
||||||
while getopts "i:t:" opt; do
|
while getopts "i:t:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
@@ -22,7 +23,7 @@ while true; do
|
|||||||
ELAPSED=$((CURRENT_TIME - START_TIME))
|
ELAPSED=$((CURRENT_TIME - START_TIME))
|
||||||
|
|
||||||
if (( ELAPSED >= TOTAL_DURATION )); then
|
if (( ELAPSED >= TOTAL_DURATION )); then
|
||||||
echo "Total duration reached. Exiting."
|
echo "Total duration reached, no music recognized."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ while true; do
|
|||||||
RESULT=$(songrec audio-file-to-recognized-song "$TMP_FILE" 2>/dev/null || true)
|
RESULT=$(songrec audio-file-to-recognized-song "$TMP_FILE" 2>/dev/null || true)
|
||||||
rm -f "$TMP_FILE"
|
rm -f "$TMP_FILE"
|
||||||
|
|
||||||
if [ -n "$RESULT" ] && [ ${#RESULT} -gt 300 ]; then
|
if [ -n "$RESULT" ] && [ ${#RESULT} -gt $MIN_VALID_RESULT_LENGTH ]; then
|
||||||
echo "$RESULT"
|
echo "$RESULT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user