improved preview
This commit is contained in:
35
src/sh/preview.sh
Normal file
35
src/sh/preview.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
__description_from_wikidata() {
|
||||
wiki=$(wikidata_get_links "$1" | $JQ -r '.enwiki' | awk -F "/" '{print $NF}')
|
||||
[ ! "$wiki" ] || [ "$wiki" = "null" ] && return
|
||||
desc=$(wikipedia_en_get_summary "$wiki" | $JQ -r '.extract')
|
||||
[ ! "$wiki" ] || [ "$wiki" = "null" ] && return
|
||||
echo "$desc"
|
||||
}
|
||||
|
||||
# For now, this prints the description of the artist.
|
||||
#
|
||||
# Source of information:
|
||||
# 1. Wikipedia
|
||||
# 2. Discogs
|
||||
__preview_artist() {
|
||||
# Get artist information from MusicBrainz
|
||||
artist_relations=$(mb_get_artist "$1" | $JQ -r ".relations")
|
||||
wikidata=$(echo "$artist_relations" |
|
||||
$JQ -r 'map(select(.type="wikidata")) | .[0].url.resource' |
|
||||
awk -F "/" '{print $NF}')
|
||||
if [ "$wikidata" ] && [ "$wikidata" != "null" ]; then
|
||||
desc=$(__description_from_wikidata "$wikidata")
|
||||
fi
|
||||
# Alternative: Get information from Discogs
|
||||
if [ ! "${desc:-}" ]; then
|
||||
discogs=$(echo "$artist_relations" |
|
||||
$JQ -r 'map(select(.type=="discogs")) | .[0].url.resource' |
|
||||
awk -F "/" '{print $NF}')
|
||||
[ ! "$discogs" ] || [ "$discogs" = "null" ] && return
|
||||
desc=$(discogs_get_artist "$discogs" |
|
||||
$JQ -r '.profile')
|
||||
[ ! "$desc" ] || [ "$desc" = "null" ] && return
|
||||
fi
|
||||
|
||||
echo "$desc" | fold -s -w "$FZF_PREVIEW_COLUMNS" | $CAT
|
||||
}
|
Reference in New Issue
Block a user