improved preview
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# Argument: Search string
|
||||
mb_browse_artists() {
|
||||
$CURL \
|
||||
--get \
|
||||
@@ -7,6 +8,7 @@ mb_browse_artists() {
|
||||
"https://musicbrainz.org/ws/2/artist"
|
||||
}
|
||||
|
||||
# Argument: MB Artist ID
|
||||
mb_get_artist() {
|
||||
$CURL \
|
||||
--get \
|
||||
@@ -16,9 +18,26 @@ mb_get_artist() {
|
||||
"https://musicbrainz.org/ws/2/artist/$1"
|
||||
}
|
||||
|
||||
# Argument: Discogs id
|
||||
discogs_get_artist() {
|
||||
$CURL \
|
||||
--get \
|
||||
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
||||
"https://api.discogs.com/artists/$1"
|
||||
}
|
||||
|
||||
# Argument: wikidata id
|
||||
wikidata_get_links() {
|
||||
$CURL \
|
||||
--get \
|
||||
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
||||
"https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/$1/sitelinks"
|
||||
}
|
||||
|
||||
# Argument: Wikipedia name (last part of URL)
|
||||
wikipedia_en_get_summary() {
|
||||
$CURL \
|
||||
--get \
|
||||
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
||||
"https://en.wikipedia.org/api/rest_v1/page/summary/$1"
|
||||
}
|
||||
|
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