improved preview
This commit is contained in:
31
src/main.sh
31
src/main.sh
@@ -8,19 +8,23 @@ set -eu
|
|||||||
# Load helper methods
|
# Load helper methods
|
||||||
. "sh/helper.sh"
|
. "sh/helper.sh"
|
||||||
|
|
||||||
|
# Load theme
|
||||||
|
. "sh/theme.sh"
|
||||||
|
|
||||||
|
# Load AWK scripts
|
||||||
|
. "sh/awk.sh"
|
||||||
|
|
||||||
|
# Load tools
|
||||||
|
. "sh/tools.sh"
|
||||||
|
|
||||||
# Load MusicBrainz and Discogs methods
|
# Load MusicBrainz and Discogs methods
|
||||||
. "sh/api.sh"
|
. "sh/api.sh"
|
||||||
|
|
||||||
|
# Load preview methods
|
||||||
|
. "sh/preview.sh"
|
||||||
|
|
||||||
if [ "${1:-}" = "--internal-preview" ]; then
|
if [ "${1:-}" = "--internal-preview" ]; then
|
||||||
# Get discogs url
|
__preview_artist "$2"
|
||||||
discogsurl=$(mb_get_artist "$2" |
|
|
||||||
$JQ -r '.relations | map(select(.type=="discogs")) | .[0].url.resource')
|
|
||||||
[ ! "$discogsurl" ] || [ "$discogsurl" = "(null)" ] && exit 0
|
|
||||||
discogsid=$(echo "$discogsurl" | awk -F "/" '{print $NF}')
|
|
||||||
profile=$(discogs_get_artist "$discogsid" |
|
|
||||||
$JQ -r '.profile')
|
|
||||||
[ ! "$profile" ] || [ "$profile" = "(null)" ] && exit 0
|
|
||||||
echo "$profile" | $CAT
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -59,15 +63,6 @@ if [ "${1:-}" = "--internal-search" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load theme
|
|
||||||
. "sh/theme.sh"
|
|
||||||
|
|
||||||
# Load AWK scripts
|
|
||||||
. "sh/awk.sh"
|
|
||||||
|
|
||||||
# Load tools
|
|
||||||
. "sh/tools.sh"
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ "${1:-}" = "--help" ]; then
|
||||||
$CAT <<EOF
|
$CAT <<EOF
|
||||||
Usage: \`$0\` [ \`--help\` ]
|
Usage: \`$0\` [ \`--help\` ]
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
# Argument: Search string
|
||||||
mb_browse_artists() {
|
mb_browse_artists() {
|
||||||
$CURL \
|
$CURL \
|
||||||
--get \
|
--get \
|
||||||
@@ -7,6 +8,7 @@ mb_browse_artists() {
|
|||||||
"https://musicbrainz.org/ws/2/artist"
|
"https://musicbrainz.org/ws/2/artist"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Argument: MB Artist ID
|
||||||
mb_get_artist() {
|
mb_get_artist() {
|
||||||
$CURL \
|
$CURL \
|
||||||
--get \
|
--get \
|
||||||
@@ -16,9 +18,26 @@ mb_get_artist() {
|
|||||||
"https://musicbrainz.org/ws/2/artist/$1"
|
"https://musicbrainz.org/ws/2/artist/$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Argument: Discogs id
|
||||||
discogs_get_artist() {
|
discogs_get_artist() {
|
||||||
$CURL \
|
$CURL \
|
||||||
--get \
|
--get \
|
||||||
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
|
||||||
"https://api.discogs.com/artists/$1"
|
"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