Compare commits

...

9 Commits

12 changed files with 624 additions and 177 deletions

View File

@@ -7,22 +7,22 @@ FORMAT_LOCAL="|>"
# Pointer to the track currently playing (playlist)
FORMAT_CURRENT="->"
# Input prompts
# Input prompt
# =============
# General search prompt
# Search prompt
SEARCH_PROMPT="search> "
# Prompt that takes an artist name as argument
ARTIST_PROMPT="%s > "
# Prompt that takes an artist name and a release name as arguments (in that
# order)
FULL_PROMPT="%s > %s > "
# Visual representation of current mode
# =====================================
# Sign to indicate `normal` mode
PROMPT_NORMAL="n "
# Sign to indicate `insert` mode
PROMPT_INSERT="i "
# Headers
# =======
# Header that displays artist's name
HEADER_ARTIST="%s > "
# Header that displays the release-group name after artist's
HEADER_ARTIST_RELEASEGROUP="%s > %s > "
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
# release information
HEADER_RELEASE="%s > %s > %s"
# The release information is formatted as follows (placeholders implicit):
HEADER_RELEASE_FORMAT="<<tracks>> tx <<media>> | <<label>> <<country>> <<year>>"
# Artist view
# ===========

View File

@@ -18,22 +18,22 @@ FORMAT_LOCAL="${BLUE}|>$OFF"
# Pointer to the track currently playing (playlist)
FORMAT_CURRENT="${WHITE}-->$OFF"
# Input prompts
# Input prompt
# =============
# General search prompt
# Search prompt
SEARCH_PROMPT="search: "
# Prompt that takes an artist name as argument
ARTIST_PROMPT="artist: %s: "
# Prompt that takes an artist name and a release name as arguments (in that
# order)
FULL_PROMPT="artist: %s / %s: "
# Visual representation of current mode
# =====================================
# Sign to indicate `normal` mode
PROMPT_NORMAL="n)"
# Sign to indicate `insert` mode
PROMPT_INSERT="i)"
# Headers
# =======
# Header that displays artist's name
HEADER_ARTIST="artist: %s"
# Header that displays the release-group name after artist's
HEADER_ARTIST_RELEASEGROUP="artist: %s / album: %s"
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
# release information
HEADER_RELEASE="artist: %s / album: %s (%s)"
# The release information is formatted as follows (placeholders implicit):
HEADER_RELEASE_FORMAT="<<label>> <<year>>"
# Artist view
# ===========

View File

@@ -94,17 +94,17 @@ BEGIN {
else
line = line "\t"
sub("<<status>>", line_status, line)
sub("<<year>>", year, line)
sub("<<tracks>>", trackcnt, line)
sub("<<media>>", media, line)
gsub("<<status>>", line_status, line)
gsub("<<year>>", year, line)
gsub("<<tracks>>", trackcnt, line)
gsub("<<media>>", media, line)
gsub("&", "\\\\&", label)
sub("<<label>>", label, line)
gsub("&", "\\\\&", titel)
sub("<<title>>", title, line)
gsub("<<label>>", label, line)
gsub("&", "\\\\&", title)
gsub("<<title>>", title, line)
gsub("&", "\\\\&", artist)
sub("<<artist>>", artist, line)
sub("<<country>>", country, line)
gsub("<<artist>>", artist, line)
gsub("<<country>>", country, line)
sortk = year ? year : 0
l = local_releases[id] ? format_local : ""
print sortk, l, line, rgid ? rgid : "0", id ":" local_releases[id]

View File

@@ -80,6 +80,9 @@ MODE_INSERT="show"
# FZF handlers
. "sh/fzf.sh"
# Load keys
. "sh/keys.sh"
# Command-line options that may only be used internally.
# --lines
# --playback
@@ -89,7 +92,9 @@ MODE_INSERT="show"
# --action-gotoartist
# --action-draw
# --mbsearch
# --preview-artist
# --preview
# --show-keybindings
# --remove-from-cache
case "${1:-}" in
"--lines")
# Print lines that are fed into fzf.
@@ -270,7 +275,7 @@ case "${1:-}" in
[ "$q" ] && q="$q "
printf "show-input+change-query(%s)" "$q"
# Store current state
printf "+change-border-label(%s)+change-list-label(%s)" "$view" "$mbid"
printf "+change-list-label(%s)" "$view"
# Set header
fzf_command_set_header "$view" "$mbid"
# Set preview window
@@ -301,14 +306,46 @@ case "${1:-}" in
mb_search_async "$2"
exit 0
;;
"--preview-artist")
# Generate content for artist preview
"--preview")
# Generate content for preview window
#
# @argument $2: MusicBrainz Artist ID
# @argument $2: view
# @argument $3: MusicBrainz ID of selected item
#
# This prints the text to be displayed in the preview window for the
# specified artist.
preview_artist "$2"
# This prints the text to be displayed in the preview window.
view=$2
mbid="${3:-}"
case "$view" in
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SELECT_ARTIST") preview_artist "$mbid" ;;
*) preview_nothing ;;
esac
exit 0
;;
"--show-keybindings")
# Print keybindings for current view
#
# @argument $2: view
print_keybindings "$2"
exit 0
;;
"--remove-from-cache")
# Remove entry from cache to reload
#
# @argument $2: view
# @argument $3: MusicBrainz ID of current object
# @argument $4: MusicBrainz ID of selected object
case "$2" in
"$VIEW_ARTIST")
cache_rm_artist "$3"
cache_rm_releasegroup "$4"
;;
"$VIEW_RELEASEGROUP")
cache_rm_releasegroup "$3"
cache_rm_release "$4"
;;
"$VIEW_RELEASE") cache_rm_release "$3" ;;
"$VIEW_LIST_ALBUMS" | "$VIEW_SEARCH_ALBUM") cache_rm_releasegroup "$4" ;;
esac
exit 0
;;
esac
@@ -344,6 +381,21 @@ case "${1:-}" in
fi
exit 0
;;
"--decorate-as")
# Decorate the specified directory as given MusicBrainz release
#
# @argument $2: path
# @argument $3: MusicBrainz release ID
[ ! "${2:-}" ] && err "You did not specify a directory." && exit 1
[ ! -d "$2" ] && err "Path $2 does not point to a directory." && exit 1
[ ! "${3:-}" ] && err "You did not specify a MusicBrainz release ID." && exit 1
[ ! "$(mb_release "$3" | $JQ '.title // ""')" ] && err "Did you specify a correct MusicBrainz release ID?" && exit 1
if ! decorate_as "$2" "$3"; then
err "Something went wrong."
exit 1
fi
exit 0
;;
"--reload-database")
# Reload database of local music
#
@@ -376,6 +428,7 @@ GENERAL OPTIONS:
MANAGE LOCAL MUSIC:
--decorate <path> Decorate directory containing a tagged release
--decorate-as <path> <mbid> Decorate directory as the relase <mbid>
--reload-database <path> Populate database with decorated local music from <path>
EOF
exit 0
@@ -432,7 +485,6 @@ esac
# Start application:
# - load and export preset filters
# - load and export keys
# - set title
# - check for missing data from MusicBrainz
# - precompute main views
@@ -443,9 +495,6 @@ esac
# Load filters
. "sh/filter.sh"
# Load keys
. "sh/keys.sh"
# Set window title
printf '\033]0;%s\007' "$WINDOW_TITLE"
@@ -474,17 +523,17 @@ mpv_start
# mode, we call `hide-input`. To switch to insert mode, we call `show-input`.
#
# view: [$VIEW_*]
# The view is stored in $FZF_BORDER_LABEL. To set the view, call
# `change-border-label($VIEW)`.
# The view is stored in $FZF_LIST_LABEL. To set the view, call
# `change-list-label($VIEW)`.
#
# argument: string
# The argument is stored in $FZF_LIST_LABEL. To set the argument, call
# `change-list-label($arg)`.
IN_NORMAL_MODE="[ \$FZF_INPUT_STATE = hidden ]"
IN_VIEW_PATTERN="[ \$FZF_BORDER_LABEL = %s ]"
IN_VIEW_PATTERN="[ \$FZF_LIST_LABEL = %s ]"
IN_LIST_ARTISTS_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_LIST_ARTISTS")"
FZF_CURRENT_MODE="\$FZF_INPUT_STATE"
FZF_CURRENT_VIEW="\$FZF_BORDER_LABEL"
FZF_CURRENT_VIEW="\$FZF_LIST_LABEL"
FZF_RELOAD_PLAYLIST="reload-sync($0 --lines $VIEW_PLAYLIST)"
FZF_POS_PLAYLIST="transform:$0 --action-playlistcursor"
PUT_FZF_KEY_LOGIC="case \$FZF_KEY in space) echo \"put( )\";; left) echo backward-char;; right) echo forward-char;; backspace|bspace|bs) echo backward-delete-char;; delete|del) echo delete-char;; *) echo \"put(\$FZF_KEY)\";; esac"
@@ -505,13 +554,20 @@ while true; do
--bind="$KEYS_SEARCH_ALBUM:print($VIEW_SEARCH_ALBUM)+accept" \
--bind="$KEYS_BROWSE:execute-silent:open \"https://musicbrainz.org/artist/{r3}\"" \
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+print()+accept" \
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $VIEW_SELECT_ARTIST" \
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
--bind="$KEYS_PREVIEW_OPEN:show-preview" \
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
--bind="$KEYS_FILTER_LOCAL:change-query($QUERY_LOCAL )" \
-0 -1 \
--border="bold" \
--border-label="Select artist" \
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
--preview="$0 --preview $VIEW_SELECT_ARTIST {3}" \
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--margin="5%,20%" \
--bind="$KEYS_FILTER_LOCAL:change-query('$QUERY_LOCAL' )" \
--accept-nth="{3}" \
--with-nth="{1}" || true
)
@@ -549,6 +605,12 @@ while true; do
--bind="$KEYS_SEARCH_ALBUM:print($VIEW_SEARCH_ALBUM)+accept" \
--bind="$KEYS_BROWSE:execute-silent:open \"https://musicbrainz.org/\track/{r3}\"" \
--bind="$KEYS_OPEN:execute-silent:open \"\$(dirname {4})\"" \
--bind="$KEYS_N_YANK:execute-silent:printf {3} | $CLIP)" \
--bind="$KEYS_YANK_CURRENT:execute-silent:printf {2} | $CLIP" \
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $VIEW_PLAYLIST" \
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
--bind="$KEYS_PLAYBACK,$KEYS_N_PLAYBACK:transform($0 --playback $VIEW_PLAYLIST {2} {3} {4})+$FZF_RELOAD_PLAYLIST+$FZF_POS_PLAYLIST" \
--bind="$KEYS_PLAYLIST_RELOAD:$FZF_RELOAD_PLAYLIST+$FZF_POS_PLAYLIST" \
--bind="$KEYS_PLAYLIST_REMOVE:execute-silent($0 --playlist $PLAYLIST_CMD_REMOVE)+$FZF_RELOAD_PLAYLIST" \
@@ -586,7 +648,7 @@ while true; do
# `$PUT_FZF_KEY_LOGIC` for details.
#
# Here is a list of all keys grouped by type (see `src/sh/keys.sh`).
#--bind="start:change-border-label($VIEW)+change-list-label($MBID)+$MODE-input+transform:$0 --display" \
#--bind="start:change-list-label($VIEW)+change-list-label($MBID)+$MODE-input+transform:$0 --display" \
sel=$(
printf "" | $FZF \
--reverse \
@@ -628,7 +690,7 @@ esac" \
--bind="$KEYS_FILTER:transform:$0 --action-filter $FZF_CURRENT_MODE $FZF_CURRENT_VIEW" \
--bind="$KEYS_BROWSE:execute-silent:
[ {3} ] || exit 0
case \$FZF_BORDER_LABEL in
case $FZF_CURRENT_VIEW in
$VIEW_LIST_ARTISTS | $VIEW_SEARCH_ARTIST) t=artist ;;
$VIEW_ARTIST | $VIEW_SEARCH_ALBUM | $VIEW_LIST_ALBUMS) t=release-group ;;
$VIEW_RELEASEGROUP) t=release ;;
@@ -641,13 +703,20 @@ open \"\$(dirname {4})\"" \
--bind="$KEYS_N_YANK:transform:$IN_NORMAL_MODE && echo \"execute-silent(printf {3} | $CLIP)\" || $PUT_FZF_KEY_LOGIC" \
--bind="$KEYS_YANK_CURRENT:execute-silent:printf {2} | $CLIP" \
--bind="$KEYS_SHOW_PLAYLIST:transform:echo \"print($VIEW_PLAYLIST)+print()+print($FZF_CURRENT_VIEW)+print({2})+accept\"" \
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $FZF_CURRENT_VIEW" \
--bind="$KEYS_REFRESH:execute-silent($0 --remove-from-cache $FZF_CURRENT_VIEW {2} {3})+transform:$0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2}" \
--bind="$KEYS_QUIT:print($VIEW_QUIT)+accept" \
--bind="$KEYS_N_QUIT:transform:$IN_NORMAL_MODE && ($IN_LIST_ARTISTS_VIEW && echo \"print($VIEW_QUIT)+accept\" || $0 --action-draw $MODE_NORMAL $VIEW_LIST_ARTISTS) || $PUT_FZF_KEY_LOGIC" \
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
--bind="$KEYS_PREVIEW_OPEN:show-preview" \
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
--bind="$KEYS_PLAYBACK:transform:$0 --playback $FZF_CURRENT_VIEW {2} {3} {4}" \
--bind="$KEYS_N_PLAYBACK:transform:$IN_NORMAL_MODE && $0 --playback $FZF_CURRENT_VIEW {2} {3} {4} || $PUT_FZF_KEY_LOGIC" \
--bind="W:execute-silent:echo 1 >> /tmp/foo; echo $FZF_CURRENT_VIEW >> /tmp/foo; echo 2 >> /tmp/foo" \
--bind="change:execute-silent($0 --mbsearch $FZF_CURRENT_VIEW &)+reload:$0 --lines $FZF_CURRENT_VIEW" \
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
--preview="$0 --preview-artist {3}" \
--preview="$0 --preview $FZF_CURRENT_VIEW {3}" \
--delimiter="\t" \
--with-nth="{1}" || true
)

View File

@@ -103,6 +103,8 @@ __api_mb() {
errormsg=$($JQ -e '.error // ""' "$tmpout")
if [ "$errormsg" ]; then
err "Failed to fetch MusicBrainz data for $1 $2: $errormsg"
echo "$errormsg" | grep -q -i "not found" && break
echo "$errormsg" | grep -q -i "invalid" && break
sleep "$SLEEP_ON_ERROR"
else
cat "$tmpout"

View File

@@ -244,3 +244,54 @@ cache_get_file_batch() {
cache_mbid_from_path_batch() {
cat | awk -F "/" '{ print $(NF-1) }'
}
# Remove artist items from cache
#
# @argument $1: MusicBrainz arist ID
#
# This function is "safer" than other because it removes data. These safty
# checks are paranoid.
cache_rm_artist() {
[ "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR/$TYPE_ARTIST" ] || return 1
d="$CACHEDIR/$TYPE_ARTIST/$(__radix "$1")/"
[ "$d" ] || return 1
[ -d "$d" ] || return 1
info "removing $d"
rm -rf "$d"
}
# Remove release-group items from cache
#
# @argument $1: MusicBrainz release-group ID
#
# This function is "safer" than other because it removes data. These safty
# checks are paranoid.
cache_rm_releasegroup() {
[ "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR/$TYPE_RELEASEGROUP" ] || return 1
d="$CACHEDIR/$TYPE_RELEASEGROUP/$(__radix "$1")/"
[ "$d" ] || return 1
[ -d "$d" ] || return 1
info "removing $d"
rm -rf "$d"
}
# Remove release items from cache
#
# @argument $1: MusicBrainz release ID
#
# This function is "safer" than other because it removes data. These safty
# checks are paranoid.
cache_rm_release() {
[ "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR" ] || return 1
[ -d "$CACHEDIR/$TYPE_RELEASE" ] || return 1
d="$CACHEDIR/$TYPE_RELEASE/$(__radix "$1")/"
[ "$d" ] || return 1
[ -d "$d" ] || return 1
info "removing $d"
rm -rf "$d"
}

View File

@@ -12,21 +12,38 @@ fzf_command_set_header() {
"$VIEW_LIST_ALBUMS") header="Search locally available album" ;;
"$VIEW_ARTIST")
name="$(mb_artist "$mbid" | $JQ '.name')"
header=$(printf "$ARTIST_PROMPT" "$name")
header=$(printf "$HEADER_ARTIST" "$name")
;;
"$VIEW_RELEASEGROUP")
title="$(mb_releasegroup "$mbid" |
$JQ '.title')"
artist="$(mb_releasegroup "$mbid" |
$JQ '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
header=$(printf "$FULL_PROMPT" "$artist" "$title")
header=$(printf "$HEADER_ARTIST_RELEASEGROUP" "$artist" "$title")
;;
"$VIEW_RELEASE")
title="$(mb_release "$mbid" |
$JQ '.title')"
artist="$(mb_release "$mbid" |
$JQ '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
header=$(printf "$FULL_PROMPT" "$artist" "$title")
releaseinfo="$(mb_release "$mbid" |
$JQ '[
.date[:4],
(."label-info" | map(.label.name) | unique | join(", ")),
(.media | map(."track-count") | add),
(.media | map(.format) | unique | join(", ")),
.country
] | join("\t")' |
awk -F "\t" -v format="$HEADER_RELEASE_FORMAT" '{
gsub("&", "\\\\&")
sub("<<year>>", $1, format)
sub("<<label>>", $2, format)
sub("<<tracks>>", $3, format)
sub("<<media>>", $4, format)
sub("<<country>>", $5, format)
print format
}')"
header=$(printf "$HEADER_RELEASE" "$artist" "$title" "$releaseinfo")
;;
esac
printf "+change-header(%s)" "${header:-"???"}"

View File

@@ -51,9 +51,15 @@
# - KEYS_N_YANK: Copy MusicBrainz ID of selected item to clipboard
# - KEYS_YANK_CURRENT: Copy MusicBrainz ID of current item to clipboard
# - KEYS_SHOW_PLAYLIST: Switch to playlist view
# - KEYS_KEYBINDINGS: Show keybindings
# - KEYS_QUIT: Quit application
# - KEYS_N_QUIT: Quit application if we are in VIEW_LIST_ARTISTS, else go to
# view VIEW_LIST_ARTISTS (normal mode)
# - KEYS_SCROLL_PREVIEW_DOWN: Scroll preview down
# - KEYS_SCROLL_PREVIEW_UP: Scroll preview up
# - KEYS_PREVIEW_OPEN: Open preview window
# - KEYS_PREVIEW_CLOSE: Close preview window
# - KEYS_REFRESH: Refresh current entry
#
# Playback:
# - KEYS_PLAY: Play selected release or selected track
@@ -80,8 +86,8 @@
# - KEYS_PLAYLIST_STORE: Store current playlist as file
# - KEYS_PLAYLIST_LOAD: Load playlist from file
# - KEYS_PLAYLIST_QUIT: Quit playlist view
#
if [ ! "${KEYS_LOADED:-}" ]; then
# Mode selection:
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/,?"}"
@@ -112,7 +118,7 @@ KEYS_SEARCH_ALBUM="${KEYS_SEARCH_ALBUM:-"alt-x"}"
KEYS_SWITCH_ARTIST_ALBUM="${KEYS_SWITCH_ARTIST_ALBUM:-"tab"}"
KEYS_SWITCH_LOCAL_REMOTE="${KEYS_SWITCH_LOCAL_REMOTE:-"ctrl-/"}"
export KEYS_IN KEYS_OUT KEYS_N_IN KEYS_N_OUT KEYS_SELECT_ARTIST \
KEYS_LIST_ARTISTS KEYS_SELECT_ARTIST KEYS_SEARCH_ALBUM \
KEYS_LIST_ARTISTS KEYS_LIST_ALBUMS KEYS_SEARCH_ARTIST KEYS_SEARCH_ALBUM \
KEYS_SWITCH_ARTIST_ALBUM KEYS_SWITCH_LOCAL_REMOTE
# Filtering:
@@ -138,10 +144,17 @@ KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
KEYS_N_YANK="${KEYS_N_YANK:-"y"}"
KEYS_YANK_CURRENT="${KEYS_YANK_CURRENT:-"ctrl-y"}"
KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}"
KEYS_KEYBINDINGS="${KEYS_KEYBINDINGS:-"alt-?"}"
KEYS_QUIT="${KEYS_QUIT:-"ctrl-c"}"
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
KEYS_SCROLL_PREVIEW_DOWN="${KEYS_SCROLL_PREVIEW_DOWN:-"page-down"}"
KEYS_SCROLL_PREVIEW_UP="${KEYS_SCROLL_PREVIEW_UP:-"page-up"}"
KEYS_PREVIEW_OPEN="${KEYS_PREVIEW_OPEN:-"alt-up"}"
KEYS_PREVIEW_CLOSE="${KEYS_PREVIEW_CLOSE:-"alt-down"}"
KEYS_REFRESH="${KEYS_REFRESH:-"ctrl-r"}"
export KEYS_BROWSE KEYS_OPEN KEYS_N_YANK KEYS_YANK_CURRENT KEYS_SHOW_PLAYLIST \
KEYS_QUIT KEYS_N_QUIT
KEYS_KEYBINDINGS KEYS_QUIT KEYS_N_QUIT KEYS_SCROLL_PREVIEW_DOWN \
KEYS_SCROLL_PREVIEW_UP KEYS_PREVIEW_CLOSE KEYS_PREVIEW_OPEN KEYS_REFRESH
# Playback:
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
@@ -185,3 +198,183 @@ export KEYS_PLAYLIST_RELOAD KEYS_PLAYLIST_REMOVE KEYS_PLAYLIST_UP \
KEYS_PLAYLIST_DOWN KEYS_PLAYLIST_CLEAR KEYS_PLAYLIST_CLEAR_ABOVE \
KEYS_PLAYLIST_CLEAR_BELOW KEYS_PLAYLIST_SHUFFLE KEYS_PLAYLIST_UNSHUFFLE \
KEYS_PLAYLIST_GOTO_RELEASE KEYS_PLAYLIST_STORE KEYS_PLAYLIST_LOAD
export KEYS_LOADED=1
fi
# Local method to print keybindin groups
#
# @argument $1: Group name
# @argument $2: Keys for first item
# @argument $3: Description of first item
# @argument $4: Keys for second item (optional)
# @argument $5: Description of second item (optional)
# @argument ...
#
# This is a helper method for printing key-binding groups.
__keybindinggroup_from_args() {
printf "$KBF_GROUP\n" "$1"
shift
{
while [ "$*" ]; do
printf "$KBF_KEY:\t$KBF_DESC\n" "$1" "${2:-"no description"}"
shift
shift
done
} | column -t -s "$(printf '\t')"
#} | column -t -s "$(printf '\t')" -c "$FZF_PREVIEW_COLUMNS" -W 2
printf "\n\n"
}
# Print view-dependent keybindings
#
# @argument $1: view
#
# This method pretty-prints the keybindings active at the given view.
print_keybindings() {
view=$1
case "$view" in
"$VIEW_SELECT_ARTIST")
__keybindinggroup_from_args "Previews" \
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
"$KEYS_KEYBINDINGS" "Show these keybindings" \
"$KEYS_PREVIEW_OPEN" "Open preview window" \
"$KEYS_PREVIEW_CLOSE" "Close preview window"
__keybindinggroup_from_args "Navigation" \
"$KEYS_DOWN" "Down" \
"$KEYS_UP" "Up" \
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
"$KEYS_HALFPAGE_UP" "Up half a page" \
"enter,$KEYS_IN" "Go to selected artist" \
"$KEYS_OUT,$KEYS_QUIT" "Return to previews view"
__keybindinggroup_from_args "Views" \
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz"
__keybindinggroup_from_args "Special operations" \
"$KEYS_SHOW_PLAYLIST" "Show playlist" \
"$KEYS_BROWSE" "Open artist in browser"
__keybindinggroup_from_args "Filtering" \
"$KEYS_FILTER_LOCAL" "Show only entries in local database"
;;
"$VIEW_PLAYLIST")
__keybindinggroup_from_args "Previews" \
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
"$KEYS_KEYBINDINGS" "Show these keybindings" \
"$KEYS_PREVIEW_CLOSE" "Close preview window"
__keybindinggroup_from_args "Navigation" \
"$KEYS_DOWN,$KEYS_N_DOWN" "Down" \
"$KEYS_UP,$KEYS_N_UP" "Up" \
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
"$KEYS_HALFPAGE_UP" "Up half a page" \
"$KEYS_N_TOP" "Go to first entry" \
"$KEYS_N_BOT" "Go to last entry" \
"$KEYS_OUT,$KEYS_N_OUT,$KEYS_QUIT,$KEYS_N_QUIT" "Leave playlist view" \
"$KEYS_SELECT_ARTIST" "Go to artist of selected item"
__keybindinggroup_from_args "Views" \
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz"
__keybindinggroup_from_args "Playlist" \
"$KEYS_PLAYLIST_RELOAD" "Reload playlist" \
"$KEYS_PLAYLIST_REMOVE" "Remove selected track" \
"$KEYS_PLAYLIST_UP" "Move track up" \
"$KEYS_PLAYLIST_DOWN" "Move track down" \
"$KEYS_PLAYLIST_CLEAR" "Clear playlist" \
"$KEYS_PLAYLIST_CLEAR_ABOVE" "Remove all tracks above" \
"$KEYS_PLAYLIST_CLEAR_BELOW" "Remove all tracks below" \
"$KEYS_PLAYLIST_SHUFFLE" "Shuffle" \
"$KEYS_PLAYLIST_UNSHUFFLE" "Undo shuffle" \
"$KEYS_PLAYLIST_GOTO_RELEASE" "Show release of selected track"
__keybindinggroup_from_args "Playback" \
"$KEYS_PLAY,$KEYS_N_PLAY" "Play selected item" \
"$KEYS_QUEUE,$KEYS_N_QUEUE" "Queue selected item" \
"$KEYS_QUEUE_NEXT,$KEYS_N_QUEUE_NEXT" "Play selected item next" \
"$KEYS_TOGGLE_PLAYBACK,$KEYS_N_TOGGLE_PLAYBACK" "Toggle playback" \
"$KEYS_PLAY_NEXT,$KEYS_N_PLAY_NEXT" "Play next track" \
"$KEYS_PLAY_PREV,$KEYS_N_PLAY_PREV" "Play previous track" \
"$KEYS_SEEK_FORWARD,$KEYS_N_SEEK_FORWARD" "Seek forward" \
"$KEYS_SEEK_BACKWARD,$KEYS_N_SEEK_BACKWARD" "Seek backward"
__keybindinggroup_from_args "Special operations" \
"$KEYS_BROWSE" "Open selected item in browser" \
"$KEYS_OPEN" "Open selected item in file manager" \
"$KEYS_N_YANK" "Copy MusicBrainz track ID" \
"$KEYS_YANK_CURRENT" "Copy MusicBrainz release ID"
;;
*)
__keybindinggroup_from_args "Switch between modes" \
"$KEYS_I_NORMAL" "Swtich to normal mode (insert)" \
"$KEYS_N_INSERT" "Swtich to insert mode (normal)"
__keybindinggroup_from_args "Previews" \
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
"$KEYS_KEYBINDINGS" "Show these keybindings" \
"$KEYS_PREVIEW_OPEN" "Open preview window" \
"$KEYS_PREVIEW_CLOSE" "Close preview window"
__keybindinggroup_from_args "Navigation" \
"$KEYS_DOWN" "Down" \
"$KEYS_UP" "Up" \
"$KEYS_N_DOWN" "Down (normal)" \
"$KEYS_N_UP" "Up (normal)" \
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
"$KEYS_HALFPAGE_UP" "Up half a page" \
"$KEYS_N_TOP" "Go to first entry (normal)" \
"$KEYS_N_BOT" "Go to last entry (normal)" \
"$KEYS_IN" "Open selected item" \
"$KEYS_N_IN" "Open selected item (normal)" \
"$KEYS_OUT" "Leave current item" \
"$KEYS_N_OUT" "Leave current item (normal)" \
"$KEYS_SELECT_ARTIST" "Go to artist of selected item"
__keybindinggroup_from_args "Views" \
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz" \
"$KEYS_SWITCH_ARTIST_ALBUM" "Swtich artist / album" \
"$KEYS_SWITCH_LOCAL_REMOTE" "Swtich local database / MusicBrainz"
__keybindinggroup_from_args "Filtering" \
"$KEYS_FILTER_LOCAL" "Show only entries in local database" \
"$KEYS_FILTER_0" "Clear filter" \
"$KEYS_FILTER_1" "Reset filter to default for current view" \
"$KEYS_FILTER_2" "Custom filter" \
"$KEYS_FILTER_3" "Custom filter" \
"$KEYS_FILTER_4" "Custom filter" \
"$KEYS_FILTER_5" "Custom filter" \
"$KEYS_FILTER_6" "Custom filter" \
"$KEYS_FILTER_7" "Custom filter" \
"$KEYS_FILTER_8" "Custom filter" \
"$KEYS_FILTER_9" "Custom filter"
__keybindinggroup_from_args "Playback" \
"$KEYS_PLAY" "Play selected item" \
"$KEYS_QUEUE" "Queue selected item" \
"$KEYS_QUEUE_NEXT" "Play selected item next" \
"$KEYS_TOGGLE_PLAYBACK" "Toggle playback" \
"$KEYS_PLAY_NEXT" "Play next track" \
"$KEYS_PLAY_PREV" "Play previous track" \
"$KEYS_SEEK_FORWARD" "Seek forward" \
"$KEYS_SEEK_BACKWARD" "Seek backward"
__keybindinggroup_from_args "Playback (normal)" \
"$KEYS_N_PLAY" "Play selected item" \
"$KEYS_N_QUEUE" "Queue selected item" \
"$KEYS_N_QUEUE_NEXT" "Play selected item next" \
"$KEYS_N_TOGGLE_PLAYBACK" "Toggle playback" \
"$KEYS_N_PLAY_NEXT" "Play next track" \
"$KEYS_N_PLAY_PREV" "Play previous track" \
"$KEYS_N_SEEK_FORWARD" "Seek forward" \
"$KEYS_N_SEEK_BACKWARD" "Seek backward"
__keybindinggroup_from_args "Special operations" \
"$KEYS_SHOW_PLAYLIST" "Show playlist" \
"$KEYS_BROWSE" "Open selected item in browser" \
"$KEYS_OPEN" "Open selected item in file manager" \
"$KEYS_N_YANK" "Copy selected MusicBrainz ID (normal)" \
"$KEYS_YANK_CURRENT" "Copy current MusicBrainz ID" \
"$KEYS_REFRESH" "Refresh current entry" \
"$KEYS_QUIT" "Quit applicaion" \
"$KEYS_N_QUIT" "First view or quit (normal)"
;;
esac
}

View File

@@ -53,7 +53,7 @@ decorate() {
fi
decoration=$($JQ -n '.tracks = {}')
tmpf=$(mktemp)
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a') >"$tmpf"
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a' -o -iname '*.ogg') >"$tmpf"
while IFS= read -r f; do
mbid=$(__gettags "$1/$f")
rid=$(echo "$mbid" | $JQ '.releaseid')
@@ -83,6 +83,97 @@ decorate() {
fi
}
# Decorate locally available music with specified MusicBrainz release
#
# @input $1: Path to directory with album
# @input $2: MusicBrainz release ID
#
# Similar as `decorate`, but the MusicBrainz IDs are not inferred from the
# tags, but passed as argument.
decorate_as() {
if [ -f "$1/$DECORATION_FILENAME" ]; then
rid="$($JQ '.releaseid' "$1/$DECORATION_FILENAME")"
title="$(mb_release "$rid" | $JQ '.title // ""')"
artist="$(mb_release "$rid" | $JQ '."artist-credit" | map([.name, .joinphrase] | join("")) | join("")')"
[ "$rid" = "$2" ] &&
info "Directory $1 has already been decorated as the release '$title' - '$artist' with the identical MusicBrainz release ID." ||
info "Directory $1 has already been decorated as the release '$title' - '$artist' with the MusicBrainz release ID $rid."
while true; do
infonn "Do you want to redecorate $1? (yes/no)"
read -r yn
case $yn in
"yes") break ;;
"no") return 0 ;;
*) info "Please answer \"yes\" or \"no\"." ;;
esac
done
fi
# Print info
title="$(mb_release "$2" | $JQ '.title // ""')"
artist="$(mb_release "$2" | $JQ '."artist-credit" | map([.name, .joinphrase] | join("")) | join("")')"
info "Decorating $1 as the release $title by $artist"
# Start decoration
decoration=$($JQ -n '.tracks = {}')
tmpf=$(mktemp)
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a' -o -iname '*.ogg' | sort) >"$tmpf"
# Compare number of tracks with release
rcnt="$(mb_release "$2" | $JQ '.media | map(."track-count") | add')"
dcnt="$(wc -l "$tmpf" | cut -d ' ' -f 1)"
if [ ! "$rcnt" -eq "$dcnt" ]; then
err "Number of tracks in directory ($dcnt) does not match number of tracks in release ($rcnt)."
return 1
fi
#
tmpj=$(mktemp)
mb_release "$2" |
$JQ '.media[] |
.position as $pos |
.tracks |
map({
$pos,
"id": .id,
"n": .number,
"t": .title
}) |
map(if(.n | type == "string" and test("^[0-9]+$")) then .n |= tonumber else . end) |
sort_by([.pos, .n])[] |
[.t, .id] |
join("\t")' >"$tmpj"
assocfile=$(mktemp)
awk -F '\t' '
BEGIN { OFS = "\t" }
FNR == NR { title[FNR] = $1; id[FNR] = $2 }
FNR != NR { fname[FNR] = $1 }
END { for (i in id) print title[i], id[i], fname[i] }
' "$tmpj" "$tmpf" >"$assocfile"
rm -f "$tmpj" "$tmpf"
# Ask user if this is ok
info "We discovered the following associatoin:"
while IFS= read -r line; do
t="$(echo "$line" | cut -d "$(printf '\t')" -f 1)"
f="$(echo "$line" | cut -d "$(printf '\t')" -f 3)"
printf "Track '%s'\tFile '%s'\n" "$t" "$f"
done <"$assocfile" | column -t -s "$(printf '\t')"
while true; do
infonn "Are the track correctly associated to the audio files? (yes/no)"
read -r yn
case $yn in
"yes") break ;;
"no") return 0 ;;
*) info "Please answer \"yes\" or \"no\"." ;;
esac
done
# Construct decoration
decoration=$($JQ -n '.tracks = {}')
while IFS= read -r line; do
i="$(echo "$line" | cut -d "$(printf '\t')" -f 2)"
f="$(echo "$line" | cut -d "$(printf '\t')" -f 3)"
decoration=$(echo "$decoration" | $JQ ".tracks += {\"$i\": \"$f\"}")
done <"$assocfile"
echo "$decoration" | $JQ ".releaseid = \"$2\"" >"$1/$DECORATION_FILENAME"
return 0
}
# Load missing cache entries (batch mode)
#
# argument $1: type

View File

@@ -25,3 +25,8 @@ err() {
info() {
echo "$(date) [$$]>${INFO}Info:${OFF} ${1:-}" | tee -a "$LOGFILE" | cut -d ">" -f 2- >/dev/stderr
}
# Like `info` but without newlnes on stderr.
infonn() {
echo "$(date) [$$]>${INFO}Info:${OFF} ${1:-}" | tee -a "$LOGFILE" | cut -d ">" -f 2- | tr '\n' ' ' >/dev/stderr
}

View File

@@ -46,3 +46,8 @@ preview_artist() {
#link=$(printf "More info:\033]8;;%s\033\\ %s\033]8;;\033\\" "https://musicbrainz.org/" "[MusicBrainz]")
printf "$APV_FORMAT" "$desc" "${lifespan:-}"
}
# Print message if there is nothing to be shown
preview_nothing() {
echo "No preview available."
}

View File

@@ -6,15 +6,19 @@
# Colors (internal only)
ESC=$(printf '\033')
BOLD="${ESC}[1m"
FAINT="${ESC}[2m"
UNDERLINE="${ESC}[4m"
CARTIST="${ESC}[38;5;209m"
CTITLE="${ESC}[38;5;229m"
CRELINFO="${ESC}[38;5;179m"
CYEAR="${ESC}[38;5;179m"
CDISAMB="$FAINT${ESC}[38;5;172m"
CNOTE="${ESC}[38;5;242m"
CXXX="${ESC}[38;5;109m"
CDESC="${ESC}[38;5;254m"
CLIFE="${ESC}[38;5;251m"
CKB="${ESC}[38;5;224m"
OFF="${ESC}[m"
# Pointers
@@ -25,24 +29,24 @@ FORMAT_LOCAL="${FORMAT_LOCAL:-"🔆"}"
FORMAT_CURRENT="${FORMAT_CURRENT:-"👉"}"
export FORMAT_LOCAL FORMAT_CURRENT
# Input prompts
# Input prompt
# =============
# General search prompt
# Search prompt
SEARCH_PROMPT=${SEARCH_PROMPT:-"🔎 〉"}
# Prompt that takes an artist name as argument
ARTIST_PROMPT="${ARTIST_PROMPT:-"🎤 ${CARTIST}%s$OFF"}"
# Prompt that takes an artist name and a release name as arguments (in that
# order)
FULL_PROMPT="${FULL_PROMPT:-"🎤 ${CARTIST}%s$OFF${CTITLE}%s$OFF"}"
export SEARCH_PROMPT ARTIST_PROMPT FULL_PROMPT
export SEARCH_PROMPT
# Visual representation of current mode
# =====================================
# Sign to indicate `normal` mode
PROMPT_NORMAL="${PROMPT_NORMAL:-"${FAINT}[n]${OFF}"}"
# Sign to indicate `insert` mode
PROMPT_INSERT="${PROMPT_INSERT:-"${FAINT}[i]${OFF}"}"
export PROMPT_NORMAL PROMPT_INSERT
# Headers
# =======
# Header that displays artist's name
HEADER_ARTIST="${HEADER_ARTIST:-"🎤 ${CARTIST}%s$OFF"}"
# Header that displays the release-group name after artist's
HEADER_ARTIST_RELEASEGROUP="${HEADER_ARTIST_RELEASEGROUP:-"🎤 ${CARTIST}%s$OFF${CTITLE}%s$OFF"}"
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
# release information
HEADER_RELEASE="${HEADER_RELEASE:-"🎤 ${CARTIST}%s$OFF${CTITLE}%s$OFF 〉%s"}"
# The release information is formatted as follows (placeholders implicit):
HEADER_RELEASE_FORMAT="${HEADER_RELEASE_FORMAT:-"${CRELINFO}<<tracks>> tx <<media>> $OFF|$CRELINFO <<label>> <<country>> <<year>>$OFF"}"
export HEADER_ARTIST HEADER_ARTIST_RELEASEGROUP HEADER_RELEASE HEADER_RELEASE_FORMAT
# Artist view
# ===========
@@ -152,3 +156,13 @@ REC_FORMAT="${REC_FORMAT:-"${CNOTE}${FAINT}<<med>>\t${CNOTE}<<nr>>$OFF\t${CTITLE
# Format of a track in the playlist
REC_FORMAT_NO_NUMBER="${REC_FORMAT_NO_NUMBER:-"${CTITLE}<<title>>\t${CARTIST}<<artist>>\t${CXXX}<<duration>>$OFF"}"
export REC_FORMAT REC_FORMAT_NO_NUMBER
# Keybinding themes
# =================
# Format keybinding group
KBF_GROUP="${KBF_GROUP:-"${UNDERLINE}${CKB}%s$OFF"}"
# Format key
KBF_KEY="${KBF_KEY:-"${BOLD}${CKB}%s$OFF"}"
# Format description
KBF_DESC="${KBF_DESC:-"${CKB}%s$OFF"}"
export KBF_GROUP KBF_KEY KBF_DESC