Improved the post, -p, function.
This commit is contained in:
parent
13aeccd78f
commit
7b12f2797a
41
ratatoskr.sh
41
ratatoskr.sh
@ -62,11 +62,23 @@ get_oauth_token() {
|
|||||||
|
|
||||||
# Scrobble music with -S flag
|
# Scrobble music with -S flag
|
||||||
scrobble_music() {
|
scrobble_music() {
|
||||||
curl -sS --oauth2-bearer "${oauth_token}" \
|
local result
|
||||||
|
result="$(curl -sS --oauth2-bearer "${oauth_token}" \
|
||||||
-d "$(playerctl metadata -f 'album={{album}}')" \
|
-d "$(playerctl metadata -f 'album={{album}}')" \
|
||||||
-d "$(playerctl metadata -f 'artist={{artist}}')" \
|
-d "$(playerctl metadata -f 'artist={{artist}}')" \
|
||||||
-d "$(playerctl metadata -f 'title={{title}}')" \
|
-d "$(playerctl metadata -f 'title={{title}}')" \
|
||||||
"${instanceURL}/api/v1/pleroma/scrobble"
|
"${instanceURL}/api/v1/pleroma/scrobble")"
|
||||||
|
# Check for errors
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "there was a problem contacting the server"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local error="$(echo "$result" | jq -r '.error')"
|
||||||
|
if [[ "$error" != "null" ]]; then
|
||||||
|
echo "Error: $error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Track scrobbled!"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,9 +109,28 @@ post_music() {
|
|||||||
|
|
||||||
# Post status with -p flag, command line.
|
# Post status with -p flag, command line.
|
||||||
post_status() {
|
post_status() {
|
||||||
curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: ${content_type:-text/markdown}" \
|
local text="$@"
|
||||||
-d "status=${@}" \
|
visibility="${visibility:-public}"
|
||||||
"${instanceURL}/api/v1/statuses"
|
local content_type="${content_type:-text/markdown}"
|
||||||
|
local json="$(jq -n --arg status "$text" \
|
||||||
|
--arg spoiler_text "$spoiler_text" \
|
||||||
|
--arg visibility "$visibility" \
|
||||||
|
--arg content_type "$content_type" \
|
||||||
|
'{ status: $status, spoiler_text: $spoiler_text, visibility: $visibility, content_type: $content_type }')"
|
||||||
|
local result
|
||||||
|
result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \
|
||||||
|
-d "$(echo "$json" | jq 'if .spoiler_text == "" then del(.spoiler_text) else . end | if .visibility == "" then del(.visibility) else . end')" \
|
||||||
|
"${instanceURL}/api/v1/statuses")"
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "there was a problem contacting the server"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local error="$(echo "$result" | jq -r '.error')"
|
||||||
|
if [[ "$error" != "null" ]]; then
|
||||||
|
echo "Error: $error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Status posted!"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user