feat: discogs description and bugfixes

This commit is contained in:
2025-07-23 12:11:24 +02:00
parent dcba30bf94
commit b7f45c613c
4 changed files with 31 additions and 8 deletions

View File

@@ -36,7 +36,7 @@ __api_mb_get_artist() {
$CURL \ $CURL \
--get \ --get \
--data fmt=json \ --data fmt=json \
--data inc="url-rels" \ --data inc="url-rels+artist-rels+aliases" \
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \ -A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
"https://musicbrainz.org/ws/2/artist/$1" "https://musicbrainz.org/ws/2/artist/$1"
} }

View File

@@ -24,7 +24,7 @@ __put_artist_json() {
f="$artistdir/$2" f="$artistdir/$2"
tmpf=$(mktemp) tmpf=$(mktemp)
cat >"$tmpf" 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 # Returns the cached MusicBrainz data for the artist given by the MusicBrainz

View File

@@ -6,7 +6,7 @@ __mb_artist_cache_or_fetch() {
__api_mb_get_artist "$1" | cache_put_artist_mb "$1" __api_mb_get_artist "$1" | cache_put_artist_mb "$1"
mbartist="$(cache_get_artist_mb "$1")" mbartist="$(cache_get_artist_mb "$1")"
fi fi
echo "$mbartist" printf "%s" "$mbartist"
} }
# Get MusicBrainz json for artist # Get MusicBrainz json for artist
@@ -29,7 +29,8 @@ mb_artist_wikidata() {
__api_wikidata_get_sitelinks "$wikidataid" | cache_put_artist_wikidata "$1" __api_wikidata_get_sitelinks "$wikidataid" | cache_put_artist_wikidata "$1"
wikidata=$(cache_get_artist_wikidata "$1") wikidata=$(cache_get_artist_wikidata "$1")
fi fi
echo "$wikidata" [ ! "$wikidata" ] || [ "$wikidata" != "null" ] || return
printf "%s" "$wikidata"
} }
# Get Wikipedia (English) summary json for artist # 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 # For obvious reasons it is recommended to link to wikidata only. So, we
# take the second route. # take the second route.
wikidata=$(mb_artist_wikidata "$1" || true) wikidata=$(mb_artist_wikidata "$1" || true)
wikiid=$(echo "$wikidata" | wikiid=$(printf "%s" "$wikidata" |
$JQ -r '.enwiki.url' | $JQ -r '.enwiki.url' |
awk -F "/" '{print $NF}') awk -F "/" '{print $NF}')
[ ! "$wikiid" ] || [ "$wikiid" != "null" ] || return [ ! "$wikiid" ] && return || [ "$wikiid" = "null" ] && return
__api_wikipedia_en_get_summary "$wikiid" | cache_put_artist_enwikipedia "$1" __api_wikipedia_en_get_summary "$wikiid" | cache_put_artist_enwikipedia "$1"
enwiki="$(cache_get_artist_enwikipedia "$1")" enwiki="$(cache_get_artist_enwikipedia "$1")"
fi 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"
} }

View File

@@ -1,6 +1,9 @@
# Print preview of artist # Print preview of artist
# @input $1: MusicBrainz Artist ID # @input $1: MusicBrainz Artist ID
__preview_artist() { __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 echo "$desc" | fold -s -w "$FZF_PREVIEW_COLUMNS" | $CAT
} }