list release groups

This commit is contained in:
2025-07-21 21:10:10 +02:00
parent 8a3e5144cf
commit c40768c973
7 changed files with 181 additions and 19 deletions

22
src/awk/releasegroups.awk Normal file
View File

@@ -0,0 +1,22 @@
BEGIN { OFS="\t" }
{
gsub("&", "\\\\&")
id = $1
type = $2
year = substr($3, 1, 4) + 0
title = $4
if (type == "Single")
line = format_single
else if (type == "Album")
line = format_album
else if (type == "EP")
line = format_ep
else
line = format_album
if (year)
line = line " " format_year
sub("<<title>>", title, line)
sub("<<year>>", year, line)
print id, line
}

57
src/awk/releases.awk Normal file
View File

@@ -0,0 +1,57 @@
BEGIN {
OFS="\t"
year[0] = 0; del year[0]
title[0] = 0; del title[0]
type[0] = 0; del type[0]
id[0] = 0; del id[0]
score[0] = 0; del score[0]
}
function get_score(rgdt, rgti, dt, ti, qy, res) {
res = 0
if (rgdt == dt)
res = res + 5
if (rgti == ti)
res = res + 5
if (qy == "normal" || qy == "unknown")
res = res + 1
if (qy == "high")
res = res + 2
return res
}
{
gsub("&", "\\\\&")
rgmi = $1 # Release Group ID
rgty = $2 # Release Group Type
rgdt = substr($3, 1, 4) + 0 # Release Group Year
rgti = $4 # Release Group Title
mi = $5 # MusicBrainz Release ID
qy = $6 # Release Quality
dt = substr($7, 1, 4) + 0 # Release Year
ti = $8 # Release Title
s = get_score(rgdt, rgti, dt, ti, qy)
if (score[rgmi] < s) {
score[rgmi] = s
year[rgmi] = dt
title[rgmi] = ti
type[rgmi] = rgty
id[rgmi] = mi
}
}
END {
for (rgmi in id) {
if (type[rgmi] == "Single")
line = format_single
else if (type[rgmi] == "Album")
line = format_album
else if (type[rgmi] == "EP")
line = format_ep
else
line = format_album
sub("<<year>>", dt, line)
sub("<<title>>", ti, line)
print mi, line
}
}

View File

@@ -23,7 +23,7 @@ set -eu
# Load preview methods # Load preview methods
. "sh/preview.sh" . "sh/preview.sh"
if [ "${1:-}" = "--internal-preview" ]; then if [ "${1:-}" = "--internal-preview-artist" ]; then
__preview_artist "$2" __preview_artist "$2"
exit 0 exit 0
fi fi
@@ -49,7 +49,7 @@ if [ "${1:-}" = "--internal-search" ]; then
echo "$$" >"$PIDFILE" echo "$$" >"$PIDFILE"
sleep 1 sleep 1
touch "$LOCKFILE" touch "$LOCKFILE"
mb_browse_artists "$2" | mb_search_artists "$2" |
$JQ -r '.artists[] | [.id, .type, .name, .disambiguation, .["life-span"].begin, .["life-span"].end] | join("\t")' | $JQ -r '.artists[] | [.id, .type, .name, .disambiguation, .["life-span"].begin, .["life-span"].end] | join("\t")' |
awk \ awk \
-F "\t" \ -F "\t" \
@@ -63,6 +63,24 @@ if [ "${1:-}" = "--internal-search" ]; then
exit 0 exit 0
fi fi
if [ "${1:-}" = "--internal-browse-artist" ]; then
mb_browse_release_groups "$2" |
$JQ -r '."release-groups"[] | [
.id,
."primary-type",
."first-release-date",
.title
] | join("\t")' |
awk \
-F "\t" \
-v format_album="$FORMAT_ALBUM" \
-v format_single="$FORMAT_SINGLE" \
-v format_ep="$FORMAT_EP" \
-v format_year="$FORMAT_YEAR" \
"$AWK_RELEASEGROUPS"
exit 0
fi
if [ "${1:-}" = "--help" ]; then if [ "${1:-}" = "--help" ]; then
$CAT <<EOF $CAT <<EOF
Usage: \`$0\` [ \`--help\` ] Usage: \`$0\` [ \`--help\` ]
@@ -73,6 +91,9 @@ EOF
exit 0 exit 0
fi fi
# Set window title
printf '\033]0;%s\007' "$WINDOW_TITLE"
# Generate filenames for temporary files # Generate filenames for temporary files
tmpdir=$(mktemp -d) tmpdir=$(mktemp -d)
LOCKFILE="$tmpdir/lock" LOCKFILE="$tmpdir/lock"
@@ -86,18 +107,35 @@ if [ "${1:-}" = "--search" ]; then
fi fi
while true; do while true; do
sel=$( case "${1:-}" in
printf "" | "--show-artist")
$FZF \ sel=$(
--ansi \ $0 --internal-browse-artist "$2" |
--no-sort \ $FZF \
--disabled \ --ansi \
--delimiter="\t" \ --no-sort \
--accept-nth="{1}" \ --disabled \
--with-nth="{2}" \ --delimiter="\t" \
--preview-window="wrap" \ --accept-nth="{1}" \
--preview="$0 --internal-preview {1}" \ --with-nth="{2}"
--bind="change:execute-silent($0 --internal-search \$FZF_QUERY &)+reload($0 --internal-reload)" )
) [ "$sel" ] && set -- "--show-release" "$sel"
echo "$sel" ;;
*)
sel=$(
printf "" |
$FZF \
--ansi \
--no-sort \
--disabled \
--delimiter="\t" \
--accept-nth="{1}" \
--with-nth="{2}" \
--preview-window="wrap" \
--preview="$0 --internal-preview-artist {1}" \
--bind="change:execute-silent($0 --internal-search \$FZF_QUERY &)+reload($0 --internal-reload)"
)
[ "$sel" ] && set -- "--show-artist" "$sel"
;;
esac
done done

View File

@@ -1,5 +1,26 @@
# Argument: MB Artist ID
mb_browse_releases() {
$CURL \
--get \
--data-urlencode fmt=json \
--data-urlencode artist="$1" \
--data-urlencode inc=release-groups \
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
"https://musicbrainz.org/ws/2/release"
}
# Argument: MB Artist ID
mb_browse_release_groups() {
$CURL \
--get \
--data-urlencode fmt=json \
--data-urlencode artist="$1" \
-A "$APP_NAME/$APP_VERSION ($APP_WEBSITE)" \
"https://musicbrainz.org/ws/2/release-group"
}
# Argument: Search string # Argument: Search string
mb_browse_artists() { mb_search_artists() {
$CURL \ $CURL \
--get \ --get \
--data-urlencode fmt=json \ --data-urlencode fmt=json \

View File

@@ -4,3 +4,17 @@ AWK_ARTISTS=$(
EOF EOF
) )
export AWK_ARTISTS export AWK_ARTISTS
AWK_RELEASES=$(
cat <<'EOF'
@@include awk/releases.awk
EOF
)
export AWK_RELEASES
AWK_RELEASEGROUPS=$(
cat <<'EOF'
@@include awk/releasegroups.awk
EOF
)
export AWK_RELEASEGROUPS

View File

@@ -1,5 +1,5 @@
APP_NAME="muf" APP_NAME="muf"
APP_VERSION="zero.zero" APP_VERSION="zero.zero"
APP_WEBSITE="https://git.indyfac.ch/amin/muf" APP_WEBSITE="https://git.indyfac.ch/amin/muf"
WINDOW_TITLE="🔎🎶 $APP_NAME" WINDOW_TITLE="🔎🎶 $APP_NAME | a simple music finder"
export APP_NAME APP_VERSION APP_WEBSITE WINDOW_TITLE export APP_NAME APP_VERSION APP_WEBSITE WINDOW_TITLE

View File

@@ -4,4 +4,14 @@ COLOR_RESET="\033[m"
FORMAT_PERSON="${FORMAT_PERSON:-👤 $COLOR_ARTIST<<name>>$COLOR_RESET}" FORMAT_PERSON="${FORMAT_PERSON:-👤 $COLOR_ARTIST<<name>>$COLOR_RESET}"
FORMAT_GROUP="${FORMAT_GROUP:-👥 $COLOR_ARTIST<<name>>$COLOR_RESET}" FORMAT_GROUP="${FORMAT_GROUP:-👥 $COLOR_ARTIST<<name>>$COLOR_RESET}"
FORMAT_DISAMBIGUATION="${FORMAT_DISAMBIGUATION:-$COLOR_DISAMBIGUATION(<<disambiguation>>)$COLOR_RESET}" FORMAT_DISAMBIGUATION="${FORMAT_DISAMBIGUATION:-$COLOR_DISAMBIGUATION(<<disambiguation>>)$COLOR_RESET}"
export FORMAT_PERSON FORMAT_GROUP FORMAT_DISAMBIGUATION COLOR_ALBUM="\033[38;5;208m"
COLOR_SINGLE="\033[38;5;210m"
COLOR_EP="\033[38;5;209m"
COLOR_RELEASE_TITLE="\033[38;5;229m"
COLOR_RELEASE_YEAR="\033[38;5;179m"
FORMAT_ALBUM="${FORMAT_ALBUM:-"💽 ${COLOR_ALBUM} LP $COLOR_RESET $COLOR_RELEASE_TITLE<<title>>$COLOR_RESET"}"
FORMAT_SINGLE="${FORMAT_SINGLE:-"💽 ${COLOR_SINGLE}single$COLOR_RESET $COLOR_RELEASE_TITLE<<title>>$COLOR_RESET"}"
FORMAT_EP="${FORMAT_EP:-"💽 ${COLOR_EP} EP $COLOR_RESET $COLOR_RELEASE_TITLE<<title>>$COLOR_RESET"}"
FORMAT_YEAR="${FORMAT_YEAR:-"${COLOR_RELEASE_YEAR}(<<year>>)${COLOR_RESET}"}"
export FORMAT_PERSON FORMAT_GROUP FORMAT_DISAMBIGUATION \
FORMAT_ALBUM FORMAT_SINGLE FORMAT_EP FORMAT_YEAR