show local music and switch between MB and local music

This commit is contained in:
2025-08-25 14:35:27 +02:00
parent dd1b15e925
commit b56d691041

View File

@@ -307,10 +307,14 @@ if [ "${1:-}" = "--internal-list-local-artists" ]; then
done <"$LOCALDATA_ARTISTS" |
awk \
-F "\t" \
-v file_local_artists="${LOCALDATA_ARTISTS:-}" \
-v format_person="$AV_PERSON" \
-v format_group="$AV_GROUP" \
-v format_disambiguation="$AV_DISAMBIGUATION" \
"$AWK_ARTISTS"
-v format_local="$FORMAT_LOCAL" \
"$AWK_ARTISTS" |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\)$|\t\1|'
exit 0
fi
@@ -398,15 +402,19 @@ if [ "${1:-}" = "--help" ]; then
cat <<EOF
Usage: $0 [OPTION]
OPTIONS:
GENERAL OPTIONS:
--help Show this help and exit.
--artists Default options, list artists of local music
--albums List albums of local music
--search-artist [<query>] Search artist on MusicBrainz
--search-album [<query>] Search album on MusicBrainz
--artist <mbid> List release groups of given artist <mbid>
--releasegroup <mbid> List releases in given release group <mbid>
--release <mbid> Show release given by <mbid>
--search-artist [<query>] Search artist
--search-album [<query>] Search album
--ni-search-artist [<query>] Non-interactive search
--ni-search-album [<query>] Non-interactive search
--ni-search-artist [<query>] Non-interactive search on MusicBrainz
--ni-search-album [<query>] Non-interactive search on MusicBrainz
MANAGE LOCAL MUSIC:
--decorate <path> Decorate directory containing a tagged release
--load-local Populate database with local music
EOF
@@ -435,7 +443,7 @@ if [ "${1:-}" = "--ni-search-album" ]; then
fi
case "${1:-}" in
"" | "--artist" | "--releasegroup" | "--release" | "--search-artist" | "--search-album") ;;
"" | "--artist" | "--releasegroup" | "--release" | "--search-artist" | "--search-album" | "--albums" | "--artists") ;;
*)
err "Unknown option $1"
exit 1
@@ -577,10 +585,12 @@ while true; do
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--info="inline-right" \
--info-command="echo \"Search album\"" \
--info-command="echo \"Search album on MusicBrainz\"" \
--color='input-fg:#ba478f' \
--accept-nth="{2}" \
--with-nth="{1}" \
--expect="ctrl-c,ctrl-q,tab" \
--expect="ctrl-/" \
--bind="start:transform:[ \"${2:-}\" ] && echo \"change-query:${2:-}\"" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
@@ -594,6 +604,7 @@ while true; do
[ "$key" = "ctrl-c" ] && tput rmcup && exit 0
[ "$key" = "ctrl-q" ] && tput rmcup && exit 0
[ "$key" = "tab" ] && set -- "--search-artist"
[ "$key" = "ctrl-/" ] && set -- "--albums"
[ "$lns" -eq 2 ] && [ ! "$key" ] && [ "$mid" ] && set -- "--releasegroup" "$mid"
;;
"--search-artist")
@@ -609,12 +620,14 @@ while true; do
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--info="inline-right" \
--info-command="echo \"Search music artist\"" \
--info-command="echo \"Search music artist on MusicBrainz\"" \
--color='input-fg:#ba478f' \
--accept-nth="{2}" \
--with-nth="{1}" \
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
--preview="$0 --internal-preview-artist {2}" \
--expect="ctrl-c,ctrl-q,tab" \
--expect="ctrl-/" \
--bind="start:transform:[ \"${2:-}\" ] && echo \"change-query:${2:-}\"" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
@@ -629,10 +642,79 @@ while true; do
[ "$key" = "ctrl-c" ] && tput rmcup && exit 0
[ "$key" = "ctrl-q" ] && tput rmcup && exit 0
[ "$key" = "tab" ] && set -- "--search-album"
[ "$key" = "ctrl-/" ] && set -- "--artists"
[ "$lns" -eq 2 ] && [ ! "$key" ] && [ "$mid" ] && set -- "--artist" "$mid"
;;
"--albums")
sel=$(
$0 --internal-list-local-releases |
$FZF \
--no-clear \
--ansi \
--reverse \
--cycle \
--no-sort \
--query="$FORMAT_STATUS_OFFICIAL " \
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--info="inline-right" \
--info-command="echo \"Search albums\"" \
--accept-nth="{2}" \
--with-nth="{1}" \
--expect="ctrl-h,ctrl-a" \
--expect="ctrl-c,ctrl-q,tab" \
--expect="ctrl-/" \
--bind="load:transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="enter:execute-silent:$0 --play-release {3}" \
--bind="focus:transform:[ {3} ] && echo \"rebind:enter\" || echo \"unbind:enter\"" \
--bind="ctrl-l:accept" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/release/{r2}' &" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up"
)
lns=$(echo "$sel" | wc -l)
key=$(echo "$sel" | head -1 | tail -1)
mid=$(echo "$sel" | head -2 | tail -1)
[ "$lns" -eq 2 ] && [ ! "$key" ] && [ "$mid" ] && set -- "--release" "$mid"
[ "$lns" -eq 2 ] && [ "$key" = "ctrl-h" ] && set -- "--select-artist" "$(mb_releasegroup "$2" | $JQ -r -c '."artist-credit"')"
[ "$lns" -eq 2 ] && [ "$key" = "ctrl-a" ] && set -- "--select-artist" "$(mb_release "$mid" | $JQ -r -c '."artist-credit"')"
[ "$key" = "ctrl-c" ] && tput rmcup && exit 0
[ "$key" = "ctrl-q" ] && tput rmcup && exit 0
[ "$key" = "ctrl-/" ] && set -- "--search-album"
[ "$key" = "tab" ] && set -- "--artists"
;;
*)
set -- "--search-artist"
sel=$(
$0 --internal-list-local-artists |
$FZF \
--no-clear \
--ansi \
--reverse \
--no-sort \
--cycle \
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--info="inline-right" \
--info-command="echo \"Search music artist\"" \
--accept-nth="{2}" \
--with-nth="{1}" \
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
--preview="$0 --internal-preview-artist {2}" \
--expect="ctrl-c,ctrl-q,tab" \
--expect="ctrl-/" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \
--bind="down:preview-half-page-down,up:preview-half-page-up" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/artist/{r2}' &"
)
lns=$(echo "$sel" | wc -l)
key=$(echo "$sel" | head -1 | tail -1)
mid=$(echo "$sel" | head -2 | tail -1)
[ "$key" = "ctrl-c" ] && tput rmcup && exit 0
[ "$key" = "ctrl-q" ] && tput rmcup && exit 0
[ "$key" = "tab" ] && set -- "--albums"
[ "$key" = "ctrl-/" ] && set -- "--search-artist"
[ "$lns" -eq 2 ] && [ ! "$key" ] && [ "$mid" ] && set -- "--artist" "$mid"
;;
esac
done