recordings

This commit is contained in:
2025-07-31 08:55:25 +02:00
parent 64afff2110
commit 7eb9d6633f
4 changed files with 81 additions and 1 deletions

32
src/awk/recordings.awk Normal file
View File

@@ -0,0 +1,32 @@
BEGIN { OFS="\t" }
{
gsub("&", "\\\\&")
id = $1
med = $2
nr = $3
dur = $4
title = $5
artist = $6
# Parse duration
if (dur) {
dur = int(dur / 1000)
dh = int(dur / 3600)
dur = dur % 3600
dm = int(dur / 60)
ds = dur % 60
if (ds <= 9)
ds = "0"ds
dur = dh ? dh":"dm":"ds : dm":"ds
} else {
dur = "??:??"
}
line = format
sub("<<med>>", med, line)
sub("<<nr>>", nr, line)
sub("<<title>>", title, line)
sub("<<artist>>", artist, line)
sub("<<duration>>", dur, line)
sortk = med" "nr
print sortk, line, id
}

View File

@@ -169,6 +169,30 @@ if [ "${1:-}" = "--internal-list-releases" ]; then
exit 0
fi
if [ "${1:-}" = "--internal-list-recordings" ]; then
mb_release "$2" |
$JQ -r '.media[] |
.position as $pos |
.tracks[] | [
.id,
$pos,
.number,
.length,
.recording.title,
(.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join(""))
] |
join("\t")' |
awk \
-F "\t" \
-v format="$REC_FORMAT" \
"$AWK_RECORDINGS" |
sort -k1,1n -k 2,2n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -R 1,2,4 |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|'
exit 0
fi
if [ "${1:-}" = "--help" ]; then
cat <<EOF
Usage: $0 [ --help | --show-artist <mbid> ]
@@ -207,6 +231,7 @@ while true; do
--ansi \
--reverse \
--cycle \
--no-sort \
--query="!$secsymb " \
--delimiter="\t" \
--prompt="$(printf "$ARTIST_PROMPT" "$name")" \
@@ -237,9 +262,22 @@ while true; do
--with-nth="{1}" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up"
)
exit 0
[ "$sel" ] && set -- "--show-release" "$sel"
;;
"--show-release")
$0 --internal-list-recordings "$2" |
$FZF \
--ansi \
--reverse \
--cycle \
--no-sort \
--no-input \
--delimiter="\t" \
--accept-nth="{2}" \
--with-nth="{1}" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up"
exit 0
;;
*)
sel=$(
printf "" |

View File

@@ -18,3 +18,10 @@ AWK_RELEASEGROUPS=$(
EOF
)
export AWK_RELEASEGROUPS
AWK_RECORDINGS=$(
cat <<'EOF'
@@include awk/recordings.awk
EOF
)
export AWK_RECORDINGS

View File

@@ -68,3 +68,6 @@ RV_FORMAT="<<status>>\t${CXXX}<<tracks>> tracks\t<<media>>${OFF}\t${CYEAR}<<year
RV_TITLE_ARTIST="${FAINT}${CTITLE}<<title>>$OFF${FAINT}${CARTIST}<<artist>>$OFF"
RV_TITLE="${FAINT}${CTITLE}<<title>>$OFF"
RV_ARTIST="${FAINT}by ${CARTIST}<<artist>>$OFF"
# Recording view
REC_FORMAT="${CNOTE}${FAINT}<<med>>$OFF\t${CNOTE}<<nr>>$OFF\t${CTITLE}<<title>>$OFF\t${CARTIST}<<artist>>$OFF\t${CXXX}<<duration>>$OFF"