feat: discogs description and bugfixes
This commit is contained in:
@@ -36,7 +36,7 @@ __api_mb_get_artist() {
|
||||
$CURL \
|
||||
--get \
|
||||
--data fmt=json \
|
||||
--data inc="url-rels" \
|
||||
--data inc="url-rels+artist-rels+aliases" \
|
||||
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
||||
"https://musicbrainz.org/ws/2/artist/$1"
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ __put_artist_json() {
|
||||
f="$artistdir/$2"
|
||||
tmpf=$(mktemp)
|
||||
cat >"$tmpf"
|
||||
[ -s "$tmpf" ] && mv "$tmpf" "$f" || echo "{}" >"$f"
|
||||
[ -s "$tmpf" ] && mv "$tmpf" "$f" || printf "{}" >"$f"
|
||||
}
|
||||
|
||||
# Returns the cached MusicBrainz data for the artist given by the MusicBrainz
|
||||
|
30
src/sh/mb.sh
30
src/sh/mb.sh
@@ -6,7 +6,7 @@ __mb_artist_cache_or_fetch() {
|
||||
__api_mb_get_artist "$1" | cache_put_artist_mb "$1"
|
||||
mbartist="$(cache_get_artist_mb "$1")"
|
||||
fi
|
||||
echo "$mbartist"
|
||||
printf "%s" "$mbartist"
|
||||
}
|
||||
|
||||
# Get MusicBrainz json for artist
|
||||
@@ -29,7 +29,8 @@ mb_artist_wikidata() {
|
||||
__api_wikidata_get_sitelinks "$wikidataid" | cache_put_artist_wikidata "$1"
|
||||
wikidata=$(cache_get_artist_wikidata "$1")
|
||||
fi
|
||||
echo "$wikidata"
|
||||
[ ! "$wikidata" ] || [ "$wikidata" != "null" ] || return
|
||||
printf "%s" "$wikidata"
|
||||
}
|
||||
|
||||
# Get Wikipedia (English) summary json for artist
|
||||
@@ -45,12 +46,31 @@ mb_artist_enwikipedia() {
|
||||
# For obvious reasons it is recommended to link to wikidata only. So, we
|
||||
# take the second route.
|
||||
wikidata=$(mb_artist_wikidata "$1" || true)
|
||||
wikiid=$(echo "$wikidata" |
|
||||
wikiid=$(printf "%s" "$wikidata" |
|
||||
$JQ -r '.enwiki.url' |
|
||||
awk -F "/" '{print $NF}')
|
||||
[ ! "$wikiid" ] || [ "$wikiid" != "null" ] || return
|
||||
[ ! "$wikiid" ] && return || [ "$wikiid" = "null" ] && return
|
||||
__api_wikipedia_en_get_summary "$wikiid" | cache_put_artist_enwikipedia "$1"
|
||||
enwiki="$(cache_get_artist_enwikipedia "$1")"
|
||||
fi
|
||||
[ ! "$enwiki" ] || [ "$enwiki" != "null" ] || return
|
||||
[ ! "$enwiki" ] && return || [ "$enwiki" = "null" ] && return
|
||||
printf "%s" "$enwiki"
|
||||
}
|
||||
|
||||
# Get Discogs json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
mb_artist_discogs() {
|
||||
discogs="$(cache_get_artist_discogs "$1" || true)"
|
||||
if [ ! "$discogs" ] || [ "$discogs" = "null" ]; then
|
||||
discogsid=$(mb_artist "$1" |
|
||||
$JQ -r '.relations |
|
||||
map(select(.type=="discogs")) |
|
||||
.[0].url.resource' |
|
||||
awk -F "/" '{print $NF}')
|
||||
[ ! "$discogsid" ] && return || [ "$discogsid" = "null" ] && return
|
||||
__api_discogs_get_artist "$discogsid" | cache_put_artist_discogs "$1"
|
||||
discogs="$(cache_get_artist_discogs "$1" || true)"
|
||||
fi
|
||||
[ ! "$discogs" ] && return || [ "$discogs" = "null" ] && return
|
||||
printf "%s" "$discogs"
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
# Print preview of artist
|
||||
# @input $1: MusicBrainz Artist ID
|
||||
__preview_artist() {
|
||||
desc=$(mb_artist_enwikipedia "$1" | $JQ -r ".extract")
|
||||
desc=$(mb_artist_enwikipedia "$1" | $JQ -r '.extract')
|
||||
if [ ! "$desc" ]; then
|
||||
desc=$(mb_artist_discogs "$1" | $JQ -r '.profile' | sed 's/\[a=\([^]]*\)\]/\1/g')
|
||||
fi
|
||||
echo "$desc" | fold -s -w "$FZF_PREVIEW_COLUMNS" | $CAT
|
||||
}
|
||||
|
Reference in New Issue
Block a user