first commit
This commit is contained in:
commit
ea76213a9c
2 changed files with 100 additions and 0 deletions
68
latestalbum
Normal file
68
latestalbum
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
client="ass"
|
||||||
|
url=""
|
||||||
|
user=""
|
||||||
|
password=""
|
||||||
|
|
||||||
|
# Checks if the last retrieved album has changed.
|
||||||
|
check_album(){
|
||||||
|
cache_folder="$HOME/.cache/$client"
|
||||||
|
cache_file="$cache_folder/list"
|
||||||
|
mkdir -p "$cache_folder" && touch "$cache_file"
|
||||||
|
|
||||||
|
album="$(tail -n 1 "$cache_file")"
|
||||||
|
if [ "$album" = "$1" ]; then
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
printf "%s\n" "$1" | tee -a "$cache_file"
|
||||||
|
printf "%s\n" "$url/library/albums/$latest_albumid"
|
||||||
|
printf "%s\n" "$latest_albumcv"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get album catalog number if it's available (Requires proper tags).
|
||||||
|
get_cn(){
|
||||||
|
album="$(echo "$@" | tr -d '()[]')"
|
||||||
|
# Try looking up directly. (Should be accurate)
|
||||||
|
curl -sL "https://vgmdb.net/search?" --data-urlencode "q=$album" | \
|
||||||
|
grep -A1 "Catalog Number" | tail -n1 | \
|
||||||
|
sed 's/<[^>]*>//g' | sed 's/^[ \t]*//;s/[ \t]*$//'
|
||||||
|
|
||||||
|
# If multiple albums were found choose the first one. (Not accurate)
|
||||||
|
curl -s "https://vgmdb.net/search?" --data-urlencode "q=$album" | \
|
||||||
|
grep -o '<span class="catalog album-bonus">[^<]*' | \
|
||||||
|
sed 's/.*>//' | grep -v '^N/A$' | head -n1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the latest recently added album with curl in "Artist - Album" format.
|
||||||
|
get_album(){
|
||||||
|
curl -s "$url/rest/getAlbumList2.view?u=$user&p=$password&v=1.16.1&c=$client&f=json&type=newest" | \
|
||||||
|
jq -r '.["subsonic-response"].albumList2.album[0] | "\(.artist) - \(.name)"'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Same thing but with album id.
|
||||||
|
get_albumid(){
|
||||||
|
curl -s "$url/rest/getAlbumList2.view?u=$user&p=$password&v=1.16.1&c=$client&f=json&type=newest" | \
|
||||||
|
jq -r '.["subsonic-response"].albumList2.album[0].id'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get album cover (kinda unsafe for my standards, should work with public instances lmao)
|
||||||
|
get_albumcv(){
|
||||||
|
echo "$url/rest/getCoverArt.view?id=$latest_albumid&u=$user&p=$password&v=1.16.1&c=$client&f=json"
|
||||||
|
}
|
||||||
|
|
||||||
|
latest_album="$(get_album)"
|
||||||
|
latest_albumid="$(get_albumid)"
|
||||||
|
latest_albumcv="$(get_albumcv)"
|
||||||
|
album_name="$(echo "$latest_album" | sed 's/^[^-]* - //')"
|
||||||
|
catalog_number=$(get_cn "$album_name" | sed 's/[[:space:]]*$//' | tr -d '\r' | sed 's/[^[:print:]\t]//g')
|
||||||
|
|
||||||
|
if [ -n "$catalog_number" ]; then
|
||||||
|
check_album "$(printf "%s [%s]\n" "$latest_album" "$catalog_number")"
|
||||||
|
else
|
||||||
|
check_album "$latest_album"
|
||||||
|
fi
|
||||||
|
|
32
webhook
Normal file
32
webhook
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
# Discord Webhook URL (e.g. https://discord.com/api/webhooks/WEBHOOK_ID/TOKEN)
|
||||||
|
discord_url=""
|
||||||
|
# Message content (e.g. :newspaper: @everyone A new album has been added!"
|
||||||
|
message=""
|
||||||
|
# Embed color (e.g. 45973)
|
||||||
|
embed_color=""
|
||||||
|
|
||||||
|
generate_post_data() {
|
||||||
|
cat <<EOF
|
||||||
|
{
|
||||||
|
"content": "$message",
|
||||||
|
"embeds": [{
|
||||||
|
"title": "$albumtitle",
|
||||||
|
"description": "$albumurl",
|
||||||
|
"color": "$embed_color",
|
||||||
|
"thumbnail": {
|
||||||
|
"url": "$albumcover"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
data="$(latestalbum)"
|
||||||
|
albumtitle="$(echo "$data" | sed -n '1p')"
|
||||||
|
albumurl="$(echo "$data" | sed -n '2p')"
|
||||||
|
albumcover="$(echo "$data" | sed -n '3p')"
|
||||||
|
|
||||||
|
curl -H "Content-Type: application/json" -X POST -d "$(generate_post_data)" $discord_url
|
Loading…
Add table
Reference in a new issue