Compare commits
25 Commits
9578307c7a
...
master
Author | SHA1 | Date | |
---|---|---|---|
c6ef55cb0c | |||
05f236df25 | |||
a6849cceea | |||
5eff83b3ca | |||
220d5c3d30 | |||
2e8bb5961a | |||
cc1dab3fdb | |||
da6a960bcd | |||
cabe5058ff | |||
d7aa704cf1 | |||
36513b8db6 | |||
870cf0e4fd | |||
fb97aab81f | |||
a6da379c5f | |||
f790267a44 | |||
051d6e51e8 | |||
0ce5af2bc4 | |||
ae0cc60a79 | |||
ebad002e73 | |||
6377a626b6 | |||
7857d66376 | |||
ff82089979 | |||
7b12f2797a | |||
13aeccd78f | |||
661f00217c |
10
README.md
10
README.md
@ -1,3 +1,11 @@
|
|||||||
# ratatoskr
|
# ratatoskr
|
||||||
|
|
||||||
A command line client for Pleroma, written in bash.
|
A command line client for Pleroma, written in bash. Originally it was to be a client with viewing as well as posting features, but there are plenty of clients that do decent formatting of statuses, and the web client also does a great job, especially with things like threading. So This project is mainly for posting to your instance.
|
||||||
|
|
||||||
|
It can be used to post things you may want to send like playing music, or it can be used to post from piped in information as in:
|
||||||
|
|
||||||
|
echo "Hello world" | ./ratatoskr -p
|
||||||
|
|
||||||
|
It's still very much a work in progress, but have fun with it anyway. :)
|
||||||
|
|
||||||
|
One thing not in help, if you want to display the client in your posts, add showClient="true" to your ~/.config/ratatoskr/default.conf file.
|
||||||
|
190
ratatoskr.sh
190
ratatoskr.sh
@ -1,14 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Hopefully one day this will be a full featured Pleroma client.
|
|
||||||
# Let's see how far we can get. :)
|
|
||||||
|
|
||||||
# Display usage information.
|
# Display usage information.
|
||||||
help() {
|
help() {
|
||||||
echo "${0##*/}"
|
echo "${0##*/}"
|
||||||
echo "Released under the terms of the WTFPL License"
|
echo "Released under the terms of the WTFPL License"
|
||||||
echo -e "Usage:\n"
|
echo -e "Usage:\n"
|
||||||
echo "With no arguments, open the interactive client."
|
|
||||||
for i in "${!command[@]}" ; do
|
for i in "${!command[@]}" ; do
|
||||||
echo "-${i/:/ <parameter>}: ${command[${i}]}"
|
echo "-${i/:/ <parameter>}: ${command[${i}]}"
|
||||||
done | sort
|
done | sort
|
||||||
@ -58,26 +55,108 @@ get_oauth_token() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
play_sound() {
|
||||||
|
if [[ "${enable_sound}" == "false" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
soundName="$*"
|
||||||
|
declare -A sounds=(
|
||||||
|
[error]="|sox -n -p synth saw E2 fade 0 0.25 0.05 repeat norm -7"
|
||||||
|
[music]="|sox -np synth pl E2 pl B2 overdrive 100 remix - overdrive 100 fade h .25 1 .25 norm -11"
|
||||||
|
[status]='|sox -np synth .05 tri C2:C7'
|
||||||
|
)
|
||||||
|
if [[ -n "${sounds[${soundName}]}" ]]; then
|
||||||
|
sox -qV0 "${sounds[${soundName}]}" -d gain -9 &> /dev/null &
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Functions that deal with posting.
|
# Functions that deal with posting.
|
||||||
|
|
||||||
# Post music with -M flag
|
# Scrobble music with -S flag
|
||||||
post_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")"
|
||||||
exit 0
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Post music with -M flag requires playerctl.
|
||||||
|
post_music() {
|
||||||
|
local text="$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}" via "{{playerName}}"')"
|
||||||
|
text="${text//Now playing \"\"/Now Playing}"
|
||||||
|
text="${text// by \"\"/}"
|
||||||
|
text="${text// from \"\"/}"
|
||||||
|
if [[ "${text}" =~ ^"Now playing via" ]]; then
|
||||||
|
echo "Error, no music was detected. Maybe it is not properly tagged?"
|
||||||
|
play_sound error
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local link="$(playerctl metadata -f '{{xesam:url}}')"
|
||||||
|
if [[ "${link}" =~ ^file:// ]]; then
|
||||||
|
link="https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b)"
|
||||||
|
fi
|
||||||
|
statusSpoiler_text="Music"
|
||||||
|
postType="music"
|
||||||
|
post_status "[${text}](${link})"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Post status with -p flag, command line.
|
# Post status with -p flag, command line.
|
||||||
post_status() {
|
post_status() {
|
||||||
curl -sS --oauth2-bearer "${oauth_token}" \
|
if [[ "${*}" == "" ]]; then
|
||||||
-d "content=${content_type:-text/markdown}" \
|
return
|
||||||
-d "status=${@}" \
|
fi
|
||||||
"${instanceURL}/api/v1/statuses"
|
postType="${postType:-status}"
|
||||||
exit 0
|
local statusText="$*"
|
||||||
|
statusVisibility="${statusVisibility:-public}"
|
||||||
|
statusContent_type="${statusContent_type:-text/markdown}"
|
||||||
|
if [[ "${showClient}" == "true" ]]; then
|
||||||
|
if [[ "${statusContent_type}" == "text/markdown" ]]; then
|
||||||
|
statusText+=$'\n'$'\n''----'$'\n'"[Posted from Ratatoskr](https://git.stormux.org/storm/ratatoskr)"
|
||||||
|
else
|
||||||
|
statusText+=$'\n'$'\n'"Posted from Ratatoskr: https://git.stormux.org/storm/ratatoskr"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
local statusJson="$(jq -n --arg status "$statusText" \
|
||||||
|
--arg spoiler_text "$statusSpoiler_text" \
|
||||||
|
--arg visibility "$statusVisibility" \
|
||||||
|
--arg content_type "$statusContent_type" \
|
||||||
|
'{ status: $status, spoiler_text: $spoiler_text, visibility: $visibility, content_type: $content_type }')"
|
||||||
|
local statusResult
|
||||||
|
statusResult="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \
|
||||||
|
-d "$(echo "$statusJson" | 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"
|
||||||
|
play_sound error
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local error="$(echo "$statusResult" | jq -r '.error')"
|
||||||
|
if [[ "$error" != "null" ]]; then
|
||||||
|
echo "Error: $error"
|
||||||
|
play_sound error
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "${postType^} posted!"
|
||||||
|
play_sound "${postType}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,17 +168,25 @@ softwareName="Ratatoskr" # The name of the client.
|
|||||||
|
|
||||||
# Main code starts here
|
# Main code starts here
|
||||||
|
|
||||||
# make sure the configuration path exists:
|
# Check for dependencies
|
||||||
mkdir -p "${configPath}"
|
dependencies=(
|
||||||
|
"jq"
|
||||||
# Associative array of command line parameters and short description of what they do.
|
"sox"
|
||||||
declare -A command=(
|
"urlencode"
|
||||||
[C]="Recreate default configuration file. Acquire new oauth token."
|
|
||||||
[h]="Help, show usage information for ${0##*/}."
|
|
||||||
[M]="Post the currently playing music track, requires playerctl."
|
|
||||||
[p:]="Post from the command line, e.g. ${0##*/} -p \"hello world\""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
# if the default file doesn't exist, create it
|
# if the default file doesn't exist, create it
|
||||||
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
||||||
get_oauth_token
|
get_oauth_token
|
||||||
@ -108,16 +195,57 @@ else
|
|||||||
source "${configPath}/${configFile}"
|
source "${configPath}/${configFile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Associative array of command line parameters and short description of what they do.
|
||||||
|
declare -A command=(
|
||||||
|
[C]="Recreate default configuration file. Acquire new oauth token."
|
||||||
|
[h]="Help, show usage information for ${0##*/}."
|
||||||
|
[M]="Post the currently playing music track, requires playerctl."
|
||||||
|
[p::]="Post from the command line, e.g. ${0##*/} -p \"hello world\" or echo \"Hello world\" | ${0}"
|
||||||
|
[t:]="Title of your post."
|
||||||
|
[v:]="Post visibility, [direct | followers | public | unlisted], default is public."
|
||||||
|
[S]="Scrobble the currently playing music track, requires playerctl."
|
||||||
|
)
|
||||||
|
|
||||||
# Handle command line parameters
|
# Handle command line parameters
|
||||||
# Convert the keys of the associative array to a format usable by getopts
|
# Convert the keys of the associative array to a format usable by getopt
|
||||||
args="${!command[*]}"
|
shortOptions="${!command[*]}"
|
||||||
args="${args//[[:space:]]/}"
|
shortOptions="${shortOptions//[[:space:]]/}"
|
||||||
while getopts "${args}" i ; do
|
|
||||||
case "$i" in
|
options="$(getopt -o "$shortOptions" -- "$@")"
|
||||||
C) get_oauth_token;;
|
eval set -- "$options"
|
||||||
h) help;;
|
|
||||||
M) post_music;;
|
while [[ $# -gt 0 ]]; do
|
||||||
p) post_status "${OPTARG}";;
|
case $1 in
|
||||||
|
-C)
|
||||||
|
get_oauth_token
|
||||||
|
shift;;
|
||||||
|
-t)
|
||||||
|
statusSpoiler_text="${2}"
|
||||||
|
shift 2;;
|
||||||
|
-v)
|
||||||
|
statusVisibility="${2}"
|
||||||
|
shift 2;;
|
||||||
|
-h)
|
||||||
|
help
|
||||||
|
exit 0;;
|
||||||
|
-M)
|
||||||
|
post_music
|
||||||
|
exit 0;;
|
||||||
|
-p)
|
||||||
|
if read -rt 0 ; then
|
||||||
|
post_status "$(cat)"
|
||||||
|
else
|
||||||
|
shift 3
|
||||||
|
post_status "$@"
|
||||||
|
fi
|
||||||
|
exit 0;;
|
||||||
|
-S)
|
||||||
|
scrobble_music
|
||||||
|
exit 0;;
|
||||||
|
*)
|
||||||
|
# unexpected option
|
||||||
|
help
|
||||||
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user