extended awk scripts to return partentid

This commit is contained in:
2025-08-28 13:26:47 +02:00
parent 28f6dc67ba
commit f2383c3803
9 changed files with 133 additions and 119 deletions

View File

@@ -4,76 +4,6 @@ USER_AGENT="$APP_NAME/$APP_VERSION ($APP_WEBSITE)"
SLEEP_ON_ERROR=1
export MB_BROWSE_STEPS
__mpv_command() {
printf "{ \"command\": [\"%s\"] }\n" "$1" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_arg() {
printf "{ \"command\": [\"%s\", \"%s\"] }\n" "$1" "$2" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_args2() {
printf "{ \"command\": [\"%s\", \"%s\", \"%s\"] }\n" "$1" "$2" "$3" | $SOCAT - "$MPV_SOCKET"
}
__mpv_get() {
__mpv_command_with_arg "expand-text" "$1" | $JQ -r '.data'
}
mpv_playlist_count() {
__mpv_get '${playlist/count}'
}
mpv_playlist_position() {
__mpv_get '${playlist-pos}'
}
mpv_quit() {
__mpv_command "quit"
}
mpv_start() {
MPV_SOCKET="$(mktemp --suffix=.sock)"
trap 'mpv_quit >/dev/null; rm -f "$MPV_SOCKET"' EXIT INT
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
}
mpv_play_file() {
__mpv_command_with_arg "loadfile" "$1"
}
mpv_queue_file() {
__mpv_command_with_args2 "loadfile" "$1" "append-play"
}
mpv_play_list() {
__mpv_command_with_arg "loadlist" "$1"
}
mpv_queue_list() {
__mpv_command_with_arg "loadlist" "$1" "append-play"
}
mpv_next() {
__mpv_command "playlist-next"
}
mpv_prev() {
__mpv_command "playlist-prev"
}
mpv_seek_forward() {
__mpv_command_with_arg "seek" "10"
}
mpv_seek_backward() {
__mpv_command_with_arg "seek" "-10"
}
mpv_toggle_pause() {
__mpv_command_with_arg "cycle" "pause"
}
__api_mb() {
tmpout=$(mktemp)
for _ in $(seq "$MB_MAX_RETRIES"); do

View File

@@ -42,7 +42,7 @@ list_releasegroups() {
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|'
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
}
# List releases in given relese group
@@ -53,7 +53,8 @@ list_releases() {
artist="$(mb_releasegroup "$1" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
mb_releasegroup_releases "$1" |
$JQ -r '."releases"[] | [
$JQ -r --arg rid "$1" '."releases"[] | [
$rid,
.id,
.status,
.date,
@@ -86,7 +87,7 @@ list_releases() {
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2|'
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
}
# List recordings of given release
@@ -99,9 +100,10 @@ list_recordings() {
$JQ -r --arg base "$base/" '.tracks | to_entries | map(.key + "\t" + $base + .value) | join("\n")' "$deco" >"$rectmp"
fi
mb_release "$1" |
$JQ -r '.media[] |
$JQ -r --arg rid "$1" '.media[] |
.position as $pos |
.tracks[] | [
$rid,
.id,
$pos,
.number,
@@ -119,7 +121,7 @@ list_recordings() {
sort -k1,1n -k2,2g |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -R 2,3,6 |
sed 's| \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2|'
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
if [ "${rectmp:-}" ] && [ -f "$rectmp" ]; then
rm -f "$rectmp"
fi
@@ -143,27 +145,33 @@ list_local_releases() {
# Generate playlist from MB release ID and path to decoration
# @argument $1: MusicBrainz Release ID
# @argument $2: Path to decoration file
# @argument $3: MusicBrainz Track ID to select (optional)
generate_playlist() {
printf "#EXTM3U\n"
dir="$(dirname "$2")"
mb_release "$1" |
$JQ -r --slurpfile deco "$2" --arg base "$dir" '$deco[].tracks as $filenames |
$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: [
.title,
(."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
.id,
$rid
] | 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
) |
map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) |
sort_by([.pos, .number]) |
map($base + "/" + .file)[]'
map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]'
}
# Generate artist list from JSON
@@ -179,10 +187,10 @@ list_artists_from_json() {
-v format_local="$FORMAT_LOCAL" \
"$AWK_ARTISTS" |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|'
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
}
# Generate playlist
# Generate playlist view
list_playlist() {
count=$(mpv_playlist_count)
# mb_release "$1" |

View File

@@ -150,7 +150,7 @@ load_local() {
"$AWK_ARTISTS" |
sort |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|' >"$LOCALDATA_ARTISTS_VIEW"
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_ARTISTS_VIEW"
info "Precomputing releasegroup view"
while IFS= read -r rgid; do
mb_releasegroup "$rgid" | $JQ -r '[
@@ -192,11 +192,12 @@ load_local() {
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|' >"$LOCALDATA_RELEASEGROUPS_VIEW"
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_RELEASEGROUPS_VIEW"
info "Precomputing release view"
cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" |
while IFS= read -r rid; do
mb_release "$rid" | $JQ -r '[
"0",
.id,
.status,
.date,
@@ -228,5 +229,5 @@ load_local() {
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2|' >"$LOCALDATA_RELEASES_VIEW"
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|' >"$LOCALDATA_RELEASES_VIEW"
}

69
src/sh/mpv.sh Normal file
View File

@@ -0,0 +1,69 @@
__mpv_command() {
printf "{ \"command\": [\"%s\"] }\n" "$1" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_arg() {
printf "{ \"command\": [\"%s\", \"%s\"] }\n" "$1" "$2" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_args2() {
printf "{ \"command\": [\"%s\", \"%s\", \"%s\"] }\n" "$1" "$2" "$3" | $SOCAT - "$MPV_SOCKET"
}
__mpv_get() {
__mpv_command_with_arg "expand-text" "$1" | $JQ -r '.data'
}
mpv_playlist_count() {
__mpv_get '${playlist-count}'
}
mpv_playlist_position() {
__mpv_get '${playlist-pos}'
}
mpv_quit() {
__mpv_command "quit"
}
mpv_start() {
MPV_SOCKET="$(mktemp --suffix=.sock)"
trap 'mpv_quit >/dev/null; rm -f "$MPV_SOCKET"' EXIT INT
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
}
mpv_play_file() {
__mpv_command_with_arg "loadfile" "$1"
}
mpv_queue_file() {
__mpv_command_with_args2 "loadfile" "$1" "append-play"
}
mpv_play_list() {
__mpv_command_with_arg "loadlist" "$1"
}
mpv_queue_list() {
__mpv_command_with_arg "loadlist" "$1" "append-play"
}
mpv_next() {
__mpv_command "playlist-next"
}
mpv_prev() {
__mpv_command "playlist-prev"
}
mpv_seek_forward() {
__mpv_command_with_arg "seek" "10"
}
mpv_seek_backward() {
__mpv_command_with_arg "seek" "-10"
}
mpv_toggle_pause() {
__mpv_command_with_arg "cycle" "pause"
}