ass/latestalbum
2025-05-03 23:55:09 -06:00

49 lines
No EOL
1.6 KiB
Bash

#!/bin/sh
# Settings
client="ass"
url=""
user=""
password=""
# Example: $HOME/.cache/$client
cache_folder=""
cache_file="$cache_folder/list"
# 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 "ID|Artist - Album" format.
get_albums(){
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[] | "\(.id)|\(.artist) - \(.name)"'
}
mkdir -p "$cache_folder" && touch "$cache_file"
get_albums | while IFS="|" read -r album_id album_full; do
album_name="$(echo "$album_full" | sed 's/^[^-]* - //')"
catalog_number=$(get_cn "$album_name" | sed 's/[[:space:]]*$//' | tr -d '\r' | sed 's/[^[:print:]\t]//g')
if [ -n "$catalog_number" ]; then
entry="$(printf "%s [%s]" "$album_full" "$catalog_number")"
else
entry="$album_full"
fi
if grep -Fxq "$entry" "$cache_file"; then
exit 0
else
echo "$entry" | tee -a "$cache_file"; echo "$url/library/albums/$album_id"
echo "$url/rest/getCoverArt.view?id=$album_id&u=$user&p=$password&v=1.16.1&c=$client&f=json"
fi
done