Files
fuzic/src/sh/preview.sh
2025-07-30 21:42:24 +02:00

40 lines
1.5 KiB
Bash

__shape() {
cat | tr -d '\r' | fold -s -w "$((FZF_PREVIEW_COLUMNS - 4))" | awk '{print " "$0" "}'
}
# Print preview of artist
# @input $1: MusicBrainz Artist ID
__preview_artist() {
desc=$(mb_artist_enwikipedia "$1" | $JQ -r '.extract' | __shape)
[ "$desc" ] || desc=$(mb_artist_discogs "$1" | $JQ -r '.profile' | sed 's/\[a=\([^]]*\)\]/\1/g' | __shape)
if [ "$(mb_artist "$1" | $JQ -r '.type')" = "Person" ]; then
# Show birth place and death place of person
lsb=$(mb_artist "$1" | $JQ -r '."life-span".begin // ""' | head -c 4)
lse=$(mb_artist "$1" | $JQ -r '."life-span".end // ""' | head -c 4)
ab=$(mb_artist "$1" | $JQ -r '."begin-area".name // ""')
ae=$(mb_artist "$1" | $JQ -r '."end-area".name // ""')
if [ "$lsb" ] && [ "$ab" ]; then
begin=$(printf "$APV_DATEPLACE" "$lsb" "$ab")
elif [ "$lsb" ]; then
begin=$(printf "$APV_DATE" "$lsb")
elif [ "$ab" ]; then
begin=$(printf "$APV_PLACE" "$ab")
else
begin=""
fi
if [ "$lse" ] && [ "$ae" ]; then
end=$(printf "$APV_DATEPLACE" "$lse" "$ae")
elif [ "$lse" ]; then
end=$(printf "$APV_DATE" "$lse")
elif [ "$ae" ]; then
end=$(printf "$APV_PLACE" "$ae")
else
end=""
fi
[ "$begin" ] && lifespan="$(printf "$APV_BORN" "$begin")"
[ "$end" ] && lifespan="$(printf "%s\n$APV_DIED" "$lifespan" "$end")"
fi
#link=$(printf "More info:\033]8;;%s\033\\ %s\033]8;;\033\\" "https://musicbrainz.org/" "[MusicBrainz]")
printf "$APV_FORMAT" "$desc" "${lifespan:-}"
}