From 4a8f42cdd5b18998387dff2b7325cff4155c9112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Thu, 28 Aug 2025 15:48:50 +0200 Subject: [PATCH] bugfix: single file play --- src/awk/recordings.awk | 5 ++- src/main.sh | 2 - src/sh/lists.sh | 96 ++++++++++++++++++++++-------------------- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/awk/recordings.awk b/src/awk/recordings.awk index bb165ca..b3c7bea 100644 --- a/src/awk/recordings.awk +++ b/src/awk/recordings.awk @@ -4,7 +4,7 @@ BEGIN { delete local_recordings[0] if (file_local_recordings) { while ((getline < file_local_recordings) == 1) - local_recordings[$1] = $2 + local_recordings[$1] = 1 close(file_local_recordings) } } @@ -17,6 +17,7 @@ BEGIN { dur = $5 title = $6 artist = $7 + deco = local_recordings[id] ? $8 : "" # Parse duration if (dur) { dur = int(dur / 1000) @@ -39,5 +40,5 @@ BEGIN { l = local_recordings[id] ? format_local : "" c = id == current_id ? format_current : "" sortk = med" "nr - print sortk, l, c, line, parentid, id ":" local_recordings[id] + print sortk, l, c, line, parentid, id ":" deco } diff --git a/src/main.sh b/src/main.sh index 51ad517..daae439 100755 --- a/src/main.sh +++ b/src/main.sh @@ -555,8 +555,6 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ printf "%s#%s" "$MODE_ARTIST" "$sel" >"$MODEFILE" ;; "$MODE_PLAYLIST") - count=$(mpv_playlist_count) - foo "Playlist: count=$count" list_playlist | $FZF \ --reverse \ diff --git a/src/sh/lists.sh b/src/sh/lists.sh index c0dbc21..c5218d0 100644 --- a/src/sh/lists.sh +++ b/src/sh/lists.sh @@ -95,23 +95,26 @@ list_releases() { list_recordings() { deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)" if [ "$deco" ]; then - base="$(dirname "$deco")" rectmp=$(mktemp) - $JQ -r --arg base "$base/" '.tracks | to_entries | map(.key + "\t" + $base + .value) | join("\n")' "$deco" >"$rectmp" + $JQ -r '.tracks | keys | join("\n")' "$deco" >"$rectmp" fi mb_release "$1" | - $JQ -r --arg rid "$1" '.media[] | - .position as $pos | - .tracks[] | [ - $rid, - .id, - $pos, - .number, - .length, - .recording.title, - (.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")) - ] | - join("\t")' | + $JQ -r \ + --arg rid "$1" \ + --arg deco "$deco" \ + '.media[] | + .position as $pos | + .tracks[] | [ + $rid, + .id, + $pos, + .number, + .length, + .recording.title, + (.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")), + $deco + ] | + join("\t")' | awk \ -F "\t" \ -v file_local_recordings="${rectmp:-}" \ @@ -144,38 +147,43 @@ list_local_releases() { # Generate playlist from MB release ID and path to decoration # @argument $1: MusicBrainz Release ID -# @argument $2: Path to decoration file / path to audio file +# @argument $2: Path to decoration file # @argument $3: MusicBrainz Track ID to select (optional) generate_playlist() { - foo "generate_playlist: releaseid(1)=$1; path(2)=$2; trackid(3)=$3" printf "#EXTM3U\n" dir="$(dirname "$2")" mb_release "$1" | - $JQ -r --slurpfile deco "$2" --arg base "$dir" --arg tid "${3:-}" '$deco[].tracks as $filenames | - . | - .id as $rid | - .media[] | - .position as $pos | - .tracks | - if ($tid == "") then . else map(select(.id == $tid)) end | - map({ - t: [ - $rid, - .id, - $pos, - .number, - .length, - .title, - (."artist-credit" | map([.name, .joinphrase] | join("")) | join("")) - ] | join("\t"), - length: (.length / 1000 | round | tostring), - $pos, - number: .number, - file: $filenames[.id] - }) | - map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) | - sort_by([.pos, .number]) | - map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]' + $JQ -r \ + --slurpfile decofile "$2" \ + --arg base "$dir" \ + --arg deco "$2" \ + --arg tid "${3:-}" \ + '$decofile[].tracks as $filenames | + . | + .id as $rid | + .media[] | + .position as $pos | + .tracks | + if ($tid == "") then . else map(select(.id == $tid)) end | + map({ + t: [ + $rid, + .id, + $pos, + .number, + .length, + .title, + (."artist-credit" | map([.name, .joinphrase] | join("")) | join("")), + $deco + ] | join("\t"), + length: (.length / 1000 | round | tostring), + $pos, + number: .number, + file: $filenames[.id] + }) | + map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) | + sort_by([.pos, .number]) | + map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]' } # Generate artist list from JSON @@ -200,7 +208,7 @@ list_playlist() { [ "$count" -eq 0 ] && return 0 mpvquery="" for i in $(seq 0 $((count - 1))); do - mpvquery="$mpvquery\${playlist/$i/current}\t\${playlist/$i/title}\t\${playlist/$i/filename}\n" + mpvquery="$mpvquery\${playlist/$i/current}\t\${playlist/$i/title}\n" done mpvtmp=$(mktemp) # Get playlist information from mpv @@ -209,10 +217,8 @@ list_playlist() { current_id=$(grep "^yes" "$mpvtmp" | cut -d "$(printf '\t')" -f 3) # Get file to be used in file_local_recordings rectmp=$(mktemp) - cut -d "$(printf '\t')" -f 3,9 "$mpvtmp" >"$rectmp" + cut -d "$(printf '\t')" -f 3 "$mpvtmp" >"$rectmp" # Get list - foo "current_id=$current_id" - foo "rectmp=$(cat "$rectmp")" cut -d "$(printf '\t')" -f 2- "$mpvtmp" | awk \ -F "\t" \