From ff820899799183128a5210175fa363d28ae99c77 Mon Sep 17 00:00:00 2001 From: stormdragon2976 Date: Mon, 30 Jan 2023 02:05:54 -0500 Subject: [PATCH] rudimentary sound support in place. --- ratatoskr.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ratatoskr.sh b/ratatoskr.sh index 5e1f22e..9f79223 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -58,6 +58,14 @@ get_oauth_token() { } +play_sound() { + local soundFile="${configPath}/soundpacks/${sound_pack:-default}/${1}.opus" + if [[ -e "${soundFile}" ]]; then + sox -qV0 "${soundFile}" -d &> /dev/null & + fi +} + + # Functions that deal with posting. # Scrobble music with -S flag @@ -71,14 +79,17 @@ scrobble_music() { # Check for errors if [[ $? -ne 0 ]]; then echo "there was a problem contacting the server" + play_sound error exit 1 fi local error="$(echo "$result" | jq -r '.error')" if [[ "$error" != "null" ]]; then echo "Error: $error" + play_sound error exit 1 fi echo "Track scrobbled!" + play_sound scrobble exit 0 } @@ -95,14 +106,17 @@ post_music() { # Check for errors if [[ $? -ne 0 ]]; then echo "there was a problem contacting the server" + play_sound error exit 1 fi local error="$(echo "$result" | jq -r '.error')" if [[ "$error" != "null" ]]; then echo "Error: $error" + play_sound error exit 1 fi echo "Music posted!" + play_sound post exit 0 } @@ -123,14 +137,17 @@ local json="$(jq -n --arg status "$text" \ "${instanceURL}/api/v1/statuses")" if [[ $? -ne 0 ]]; then echo "there was a problem contacting the server" + play_sound error exit 1 fi local error="$(echo "$result" | jq -r '.error')" if [[ "$error" != "null" ]]; then echo "Error: $error" + play_sound error exit 1 fi echo "Status posted!" + play_sound post exit 0 } @@ -143,8 +160,23 @@ softwareName="Ratatoskr" # The name of the client. # Main code starts here -# make sure the configuration path exists: -mkdir -p "${configPath}" +# Check for dependencies +dependencies=( + "jq" + "sox" + "urlencode" +) + +for i in "${dependencies[@]}" ; do + if ! command -v "$i" &> /dev/null ; then + echo "Missing dependency: $i" + exit 2 + fi +done + + +# make sure the configuration and soundpack paths exist: +mkdir -p "${configPath}/soundpacks" # Associative array of command line parameters and short description of what they do. declare -A command=(