improvement: no media number if only one

This commit is contained in:
2025-09-15 14:01:52 +02:00
parent ca2c7ae3c5
commit f7e22805f8
3 changed files with 85 additions and 19 deletions

View File

@@ -19,12 +19,13 @@
# The input to this awk program is a sequence of lines containing the following fields: # The input to this awk program is a sequence of lines containing the following fields:
# Field 1: The MusicBrainz ID of the release this track belongs to # Field 1: The MusicBrainz ID of the release this track belongs to
# Field 2: MusicBrainz ID of this track # Field 2: MusicBrainz ID of this track
# Field 3: Medium number of this track within the release # Field 3: Number of media of theis release
# Field 4: Track number of this track within the medium # Field 4: Medium number of this track within the release
# Field 5: Duration of this track in miliseconds # Field 5: Track number of this track within the medium
# Field 6: Title of this track # Field 6: Duration of this track in miliseconds
# Field 7: Artist of this track # Field 7: Title of this track
# Field 8: Path to decoratoin file of this release # Field 8: Artist of this track
# Field 9: Path to decoratoin file of this release
# #
# The output is a sequence of tab-delimited lines containing the following fields: # The output is a sequence of tab-delimited lines containing the following fields:
# Field 1: Sort value (to sort the track within the release) # Field 1: Sort value (to sort the track within the release)
@@ -47,12 +48,13 @@ BEGIN {
{ {
parentid = $1 parentid = $1
id = $2 id = $2
med = $3 medtot = $3
nr = $4 med = $4
dur = $5 nr = $5
title = $6 dur = $6
artist = $7 title = $7
deco = local_recordings[id] ? $8 : "" artist = $8
deco = local_recordings[id] ? $9 : ""
gsub("&", "\\\\&", title) gsub("&", "\\\\&", title)
gsub("&", "\\\\&", artist) gsub("&", "\\\\&", artist)
# Parse duration # Parse duration
@@ -69,6 +71,9 @@ BEGIN {
dur = "??:??" dur = "??:??"
} }
line = format line = format
if (medtot == 1)
sub("<<med>>", "", line)
else
sub("<<med>>", med, line) sub("<<med>>", med, line)
sub("<<nr>>", nr, line) sub("<<nr>>", nr, line)
sub("<<title>>", title, line) sub("<<title>>", title, line)

View File

@@ -99,20 +99,78 @@ list_releases() {
# #
# argument $1: MusicBrainz release ID # argument $1: MusicBrainz release ID
list_recordings() { list_recordings() {
info "list recordings.."
deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)" deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)"
info "deco=$deco"
if [ "$deco" ]; then if [ "$deco" ]; then
rectmp=$(mktemp) rectmp=$(mktemp)
$JQ '.tracks | keys | join("\n")' "$deco" >"$rectmp" $JQ '.tracks | keys | join("\n")' "$deco" >"$rectmp"
info "rectmp=$rectmp"
info "$(cat "$rectmp")"
fi fi
info "going to awk..."
info "$(
mb_release "$1" | mb_release "$1" |
$JQ \ $JQ \
--arg rid "$1" \ --arg rid "$1" \
--arg deco "$deco" \ --arg deco "$deco" \
'.media[] | '.media |
length as $l |
.[] |
.position as $pos | .position as $pos |
.tracks[] | [ .tracks[] | [
$rid, $rid,
.id, .id,
$l,
$pos,
.number,
.length,
.recording.title,
(.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
$deco
] |
join("\t")'
)"
info "$(
mb_release "$1" |
$JQ \
--arg rid "$1" \
--arg deco "$deco" \
'.media |
length as $l |
.[] |
.position as $pos |
.tracks[] | [
$rid,
.id,
$l,
$pos,
.number,
.length,
.recording.title,
(.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
$deco
] |
join("\t")' |
awk \
-F "\t" \
-v file_local_recordings="${rectmp:-}" \
-v format="$REC_FORMAT" \
-v format_local="$FORMAT_LOCAL" \
"$AWK_RECORDINGS"
)"
mb_release "$1" |
$JQ \
--arg rid "$1" \
--arg deco "$deco" \
'.media |
length as $l |
.[] |
.position as $pos |
.tracks[] | [
$rid,
.id,
$l,
$pos, $pos,
.number, .number,
.length, .length,

View File

@@ -60,7 +60,9 @@ __generate_playlist() {
'$decofile[].tracks as $filenames | '$decofile[].tracks as $filenames |
. | . |
.id as $rid | .id as $rid |
.media[] | .media |
length as $l |
.[] |
.position as $pos | .position as $pos |
.tracks | .tracks |
if ($tid == "") then . else map(select(.id == $tid)) end | if ($tid == "") then . else map(select(.id == $tid)) end |
@@ -68,6 +70,7 @@ __generate_playlist() {
t: [ t: [
$rid, $rid,
.id, .id,
$l,
$pos, $pos,
.number, .number,
.length, .length,