simplify and handle multiple albums
This commit is contained in:
parent
69307351a7
commit
9e5d3c9bcf
1 changed files with 24 additions and 43 deletions
67
latestalbum
67
latestalbum
|
@ -2,26 +2,11 @@
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
client="ass"
|
client="ass"
|
||||||
url=""
|
url="https://www.squidify.org"
|
||||||
user=""
|
user="Guest"
|
||||||
password=""
|
password="Guest"
|
||||||
|
cache_folder="$HOME/.cache/$client"
|
||||||
# Checks if the last retrieved album has changed.
|
cache_file="$cache_folder/list"
|
||||||
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 album catalog number if it's available (Requires proper tags).
|
||||||
get_cn(){
|
get_cn(){
|
||||||
|
@ -37,32 +22,28 @@ get_cn(){
|
||||||
sed 's/.*>//' | grep -v '^N/A$' | head -n1
|
sed 's/.*>//' | grep -v '^N/A$' | head -n1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the latest recently added album with curl in "Artist - Album" format.
|
# Get the latest recently added album with curl in "ID|Artist - Album" format.
|
||||||
get_album(){
|
get_albums(){
|
||||||
curl -s "$url/rest/getAlbumList2.view?u=$user&p=$password&v=1.16.1&c=$client&f=json&type=newest" | \
|
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)"'
|
jq -r '.["subsonic-response"].albumList2.album[] | "\(.id)|\(.artist) - \(.name)"'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Same thing but with album id.
|
mkdir -p "$cache_folder" && touch "$cache_file"
|
||||||
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_albums | while IFS="|" read -r album_id album_full; do
|
||||||
get_albumcv(){
|
album_name="$(echo "$album_full" | sed 's/^[^-]* - //')"
|
||||||
echo "$url/rest/getCoverArt.view?id=$latest_albumid&u=$user&p=$password&v=1.16.1&c=$client&f=json"
|
catalog_number=$(get_cn "$album_name" | sed 's/[[:space:]]*$//' | tr -d '\r' | sed 's/[^[:print:]\t]//g')
|
||||||
}
|
|
||||||
|
|
||||||
latest_album="$(get_album)"
|
if [ -n "$catalog_number" ]; then
|
||||||
latest_albumid="$(get_albumid)"
|
entry="$(printf "%s [%s]" "$album_full" "$catalog_number")"
|
||||||
latest_albumcv="$(get_albumcv)"
|
else
|
||||||
album_name="$(echo "$latest_album" | sed 's/^[^-]* - //')"
|
entry="$album_full"
|
||||||
catalog_number=$(get_cn "$album_name" | sed 's/[[:space:]]*$//' | tr -d '\r' | sed 's/[^[:print:]\t]//g')
|
fi
|
||||||
|
|
||||||
if [ -n "$catalog_number" ]; then
|
|
||||||
check_album "$(printf "%s [%s]\n" "$latest_album" "$catalog_number")"
|
|
||||||
else
|
|
||||||
check_album "$latest_album"
|
|
||||||
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
|
Loading…
Add table
Reference in a new issue