Compare commits

..

No commits in common. "13aeccd78f3e891d5e3b99747e115f3b4d43b810" and "9578307c7a4464843c809fa336091b4b2a348682" have entirely different histories.

View File

@ -60,8 +60,8 @@ get_oauth_token() {
# Functions that deal with posting. # Functions that deal with posting.
# Scrobble music with -S flag # Post music with -M flag
scrobble_music() { post_music() {
curl -sS --oauth2-bearer "${oauth_token}" \ 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}}')" \
@ -71,33 +71,10 @@ scrobble_music() {
} }
# Post music with -M flag requires playerctl.
post_music() {
local text="[$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}"')]"
local link="(https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b))"
local json=$(jq -n --arg status "$text$link" --arg spoiler_text "Music" --arg content_type "text/markdown" '{status: $status, spoiler_text: $spoiler_text, content_type: $content_type}')
local result
result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \
-d "$json" \
"${instanceURL}/api/v1/statuses")"
# 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 "Music posted!"
exit 0
}
# 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}" \ curl -sS --oauth2-bearer "${oauth_token}" \
-d "content=${content_type:-text/markdown}" \
-d "status=${@}" \ -d "status=${@}" \
"${instanceURL}/api/v1/statuses" "${instanceURL}/api/v1/statuses"
exit 0 exit 0
@ -121,7 +98,6 @@ declare -A command=(
[h]="Help, show usage information for ${0##*/}." [h]="Help, show usage information for ${0##*/}."
[M]="Post the currently playing music track, requires playerctl." [M]="Post the currently playing music track, requires playerctl."
[p:]="Post from the command line, e.g. ${0##*/} -p \"hello world\"" [p:]="Post from the command line, e.g. ${0##*/} -p \"hello world\""
[S]="Scrobble the currently playing music track, requires playerctl."
) )
# if the default file doesn't exist, create it # if the default file doesn't exist, create it
@ -142,7 +118,6 @@ while getopts "${args}" i ; do
h) help;; h) help;;
M) post_music;; M) post_music;;
p) post_status "${OPTARG}";; p) post_status "${OPTARG}";;
S) scrobble_music;;
esac esac
done done