rudimentary sound support in place.
This commit is contained in:
parent
7b12f2797a
commit
ff82089979
36
ratatoskr.sh
36
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=(
|
||||
|
Loading…
Reference in New Issue
Block a user