bugfix: single file play

This commit is contained in:
2025-08-28 15:48:50 +02:00
parent 8bfa2d7483
commit 4a8f42cdd5
3 changed files with 54 additions and 49 deletions

View File

@@ -4,7 +4,7 @@ BEGIN {
delete local_recordings[0] delete local_recordings[0]
if (file_local_recordings) { if (file_local_recordings) {
while ((getline < file_local_recordings) == 1) while ((getline < file_local_recordings) == 1)
local_recordings[$1] = $2 local_recordings[$1] = 1
close(file_local_recordings) close(file_local_recordings)
} }
} }
@@ -17,6 +17,7 @@ BEGIN {
dur = $5 dur = $5
title = $6 title = $6
artist = $7 artist = $7
deco = local_recordings[id] ? $8 : ""
# Parse duration # Parse duration
if (dur) { if (dur) {
dur = int(dur / 1000) dur = int(dur / 1000)
@@ -39,5 +40,5 @@ BEGIN {
l = local_recordings[id] ? format_local : "" l = local_recordings[id] ? format_local : ""
c = id == current_id ? format_current : "" c = id == current_id ? format_current : ""
sortk = med" "nr sortk = med" "nr
print sortk, l, c, line, parentid, id ":" local_recordings[id] print sortk, l, c, line, parentid, id ":" deco
} }

View File

@@ -555,8 +555,6 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
printf "%s#%s" "$MODE_ARTIST" "$sel" >"$MODEFILE" printf "%s#%s" "$MODE_ARTIST" "$sel" >"$MODEFILE"
;; ;;
"$MODE_PLAYLIST") "$MODE_PLAYLIST")
count=$(mpv_playlist_count)
foo "Playlist: count=$count"
list_playlist | list_playlist |
$FZF \ $FZF \
--reverse \ --reverse \

View File

@@ -95,23 +95,26 @@ list_releases() {
list_recordings() { list_recordings() {
deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)" deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)"
if [ "$deco" ]; then if [ "$deco" ]; then
base="$(dirname "$deco")"
rectmp=$(mktemp) 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 fi
mb_release "$1" | mb_release "$1" |
$JQ -r --arg rid "$1" '.media[] | $JQ -r \
.position as $pos | --arg rid "$1" \
.tracks[] | [ --arg deco "$deco" \
$rid, '.media[] |
.id, .position as $pos |
$pos, .tracks[] | [
.number, $rid,
.length, .id,
.recording.title, $pos,
(.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")) .number,
] | .length,
join("\t")' | .recording.title,
(.recording."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
$deco
] |
join("\t")' |
awk \ awk \
-F "\t" \ -F "\t" \
-v file_local_recordings="${rectmp:-}" \ -v file_local_recordings="${rectmp:-}" \
@@ -144,38 +147,43 @@ list_local_releases() {
# Generate playlist from MB release ID and path to decoration # Generate playlist from MB release ID and path to decoration
# @argument $1: MusicBrainz Release ID # @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) # @argument $3: MusicBrainz Track ID to select (optional)
generate_playlist() { generate_playlist() {
foo "generate_playlist: releaseid(1)=$1; path(2)=$2; trackid(3)=$3"
printf "#EXTM3U\n" printf "#EXTM3U\n"
dir="$(dirname "$2")" dir="$(dirname "$2")"
mb_release "$1" | mb_release "$1" |
$JQ -r --slurpfile deco "$2" --arg base "$dir" --arg tid "${3:-}" '$deco[].tracks as $filenames | $JQ -r \
. | --slurpfile decofile "$2" \
.id as $rid | --arg base "$dir" \
.media[] | --arg deco "$2" \
.position as $pos | --arg tid "${3:-}" \
.tracks | '$decofile[].tracks as $filenames |
if ($tid == "") then . else map(select(.id == $tid)) end | . |
map({ .id as $rid |
t: [ .media[] |
$rid, .position as $pos |
.id, .tracks |
$pos, if ($tid == "") then . else map(select(.id == $tid)) end |
.number, map({
.length, t: [
.title, $rid,
(."artist-credit" | map([.name, .joinphrase] | join("")) | join("")) .id,
] | join("\t"), $pos,
length: (.length / 1000 | round | tostring), .number,
$pos, .length,
number: .number, .title,
file: $filenames[.id] (."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
}) | $deco
map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) | ] | join("\t"),
sort_by([.pos, .number]) | length: (.length / 1000 | round | tostring),
map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]' $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 # Generate artist list from JSON
@@ -200,7 +208,7 @@ list_playlist() {
[ "$count" -eq 0 ] && return 0 [ "$count" -eq 0 ] && return 0
mpvquery="" mpvquery=""
for i in $(seq 0 $((count - 1))); do 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 done
mpvtmp=$(mktemp) mpvtmp=$(mktemp)
# Get playlist information from mpv # Get playlist information from mpv
@@ -209,10 +217,8 @@ list_playlist() {
current_id=$(grep "^yes" "$mpvtmp" | cut -d "$(printf '\t')" -f 3) current_id=$(grep "^yes" "$mpvtmp" | cut -d "$(printf '\t')" -f 3)
# Get file to be used in file_local_recordings # Get file to be used in file_local_recordings
rectmp=$(mktemp) rectmp=$(mktemp)
cut -d "$(printf '\t')" -f 3,9 "$mpvtmp" >"$rectmp" cut -d "$(printf '\t')" -f 3 "$mpvtmp" >"$rectmp"
# Get list # Get list
foo "current_id=$current_id"
foo "rectmp=$(cat "$rectmp")"
cut -d "$(printf '\t')" -f 2- "$mpvtmp" | cut -d "$(printf '\t')" -f 2- "$mpvtmp" |
awk \ awk \
-F "\t" \ -F "\t" \