Compare commits
21 Commits
1883109616
...
20104a25b4
Author | SHA1 | Date | |
---|---|---|---|
20104a25b4 | |||
32087d8736 | |||
4cb9c8c46f | |||
e9fafe278f | |||
60f7426709 | |||
6ff6e4bbcc | |||
9b898898c8 | |||
7e01349abe | |||
655359dea3 | |||
93359f99c5 | |||
62f7e38e47 | |||
48976cbfc5 | |||
eb9ce5164f | |||
c46c64d639 | |||
dac9e5c332 | |||
45d75fe9cc | |||
e90cdda8b7 | |||
9f8d2cc189 | |||
274fa5edcc | |||
8c37cb2fea | |||
b15848887b |
@@ -58,5 +58,5 @@ BEGIN {
|
||||
line_year = year ? format_year : ""
|
||||
sub("<<year>>", year, line_year)
|
||||
sortk = year ? year : 0
|
||||
print sortk, l, line_type, line_release, line_year, line_sectype, "0", id
|
||||
print sortk, l, line_type, line_release, line_year, line_sectype, artistid ? artistid : "0", id
|
||||
}
|
||||
|
@@ -9,18 +9,17 @@ BEGIN {
|
||||
}
|
||||
}
|
||||
{
|
||||
parentid = $1
|
||||
id = $2
|
||||
status = $3
|
||||
year = substr($4, 1, 4) + 0
|
||||
id = $1
|
||||
status = $2
|
||||
year = substr($3, 1, 4) + 0
|
||||
year = year == 0 ? "" : year
|
||||
covercount = $5
|
||||
label = $6
|
||||
trackcnt = $7
|
||||
media = $8
|
||||
country = $9
|
||||
title = $10
|
||||
artist = $11
|
||||
covercount = $4
|
||||
label = $5
|
||||
trackcnt = $6
|
||||
media = $7
|
||||
country = $8
|
||||
title = $9
|
||||
artist = $10
|
||||
switch (status) {
|
||||
case "Official": line_status = release_official; break
|
||||
case "Promotion": line_status = release_promotion; break
|
||||
@@ -54,5 +53,5 @@ BEGIN {
|
||||
sub("<<country>>", country, line)
|
||||
sortk = year ? year : 0
|
||||
l = local_releases[id] ? format_local : ""
|
||||
print sortk, l, line, parentid, id ":" local_releases[id]
|
||||
print sortk, l, line, rgid ? rgid : "0", id ":" local_releases[id]
|
||||
}
|
||||
|
455
src/main.sh
455
src/main.sh
@@ -2,6 +2,19 @@
|
||||
|
||||
set -eu
|
||||
|
||||
VIEW_ARTIST="artist"
|
||||
VIEW_RELEASEGROUP="rg"
|
||||
VIEW_RELEASE="release"
|
||||
VIEW_SEARCH_ARTIST="search-artist"
|
||||
VIEW_SEARCH_ALBUM="search-album"
|
||||
VIEW_LIST_ARTISTS="list-artists"
|
||||
VIEW_LIST_ALBUMS="list-albums"
|
||||
VIEW_SELECT_ARTIST="select-artist"
|
||||
VIEW_PLAYLIST="playlist"
|
||||
VIEW_QUIT="quit"
|
||||
MODE_NORMAL="hidden"
|
||||
MODE_INSERT="show"
|
||||
|
||||
# Load helper methods
|
||||
. "sh/info.sh"
|
||||
|
||||
@@ -17,6 +30,15 @@ set -eu
|
||||
# Load keys
|
||||
. "sh/keys.sh"
|
||||
|
||||
# Load filters
|
||||
. "sh/filter.sh"
|
||||
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
|
||||
# Load playlist tools
|
||||
. "sh/playlist.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
@@ -51,6 +73,197 @@ set -eu
|
||||
. "sh/fzf.sh"
|
||||
|
||||
case "${1:-}" in
|
||||
"--lines")
|
||||
view=${2:-}
|
||||
mbid=${3:-}
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
list_releasegroups "$mbid"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
list_releases "$mbid"
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
list_recordings "$mbid"
|
||||
;;
|
||||
"$VIEW_LIST_ARTISTS")
|
||||
list_local_artists
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS")
|
||||
list_local_releasegroups
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
"--playback")
|
||||
view=${2:-}
|
||||
mbid_current="${3:-}"
|
||||
mbid="${4:-}"
|
||||
path="${5:-}"
|
||||
pbcmd=$(playback_cmd_from_key "$FZF_KEY")
|
||||
case "$pbcmd" in
|
||||
"$PLAYBACK_CMD_PLAY")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") debug "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") generate_playlist "$mbid" "$path" | mpv_play_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_play_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") mpv_play_index $((FZF_POS - 1)) >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_QUEUE")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") debug "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") generate_playlist "$mbid" "$path" | mpv_queue_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_list >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_QUEUE_NEXT")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") debug "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") generate_playlist "$mbid" "$path" | mpv_queue_next_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_next_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_next_list >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_TOGGLE_PLAYBACK") mpv_toggle_pause ;;
|
||||
"$PLAYBACK_CMD_PLAY_NEXT") mpv_next ;;
|
||||
"$PLAYBACK_CMD_PLAY_PREV") mpv_prev ;;
|
||||
"$PLAYBACK_CMD_SEEK_FORWARD") mpv_seek_forward ;;
|
||||
"$PLAYBACK_CMD_SEEK_BACKWARD") mpv_seek_backward ;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
"--filter")
|
||||
mode=$2
|
||||
view=$3
|
||||
q="$(default_query "$view" "$FZF_KEY")"
|
||||
[ "$q" ] && q="$q "
|
||||
printf "show-input+change-query(%s)" "$q"
|
||||
[ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input"
|
||||
exit 0
|
||||
;;
|
||||
"--jumpto-artist")
|
||||
mode=$2
|
||||
view=$3
|
||||
mbid_cur="${4:-}"
|
||||
mbid="${5:-}"
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") j="$(mb_releasegroup "$mbid" | $JQ -r --compact-output '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASEGROUP") j="$(mb_release "$mbid" | $JQ -r --compact-output '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASE" | "$VIEW_PLAYLIST") j="$(mb_release "$mbid_cur" | $JQ -r --compact-output ".media | map(.tracks) | flatten[] | select(.id == \"$mbid\") | .\"artist-credit\"")" ;;
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") aid="$mbid" ;;
|
||||
esac
|
||||
if [ "$view" = "$VIEW_PLAYLIST" ]; then
|
||||
printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j"
|
||||
exit 0
|
||||
fi
|
||||
if [ "${j:-}" ]; then
|
||||
cnt=$(echo "$j" | $JQ 'length')
|
||||
[ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ -r '.[0].artist.id')"
|
||||
fi
|
||||
[ "${aid:-}" ] && $0 --draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j"
|
||||
exit 0
|
||||
;;
|
||||
"--draw")
|
||||
# Generate fzf command to draw screen.
|
||||
#
|
||||
# @argument $2: mode (default `normal`)
|
||||
# @argument $3: view (default list artists)
|
||||
# @argument $4: MusicBrainz ID (optional)
|
||||
# @argument $5: level (optional)
|
||||
#
|
||||
# The argument `level` specifies the view relative to `view`: If `level` is
|
||||
# set to +1, then the specified MusicBrainz ID is an ID of an object one level
|
||||
# deeper than `view`. Alternatively, the argument `level` may be set to `-1`.
|
||||
# Anything else is interpreted as "on the level of `view`".
|
||||
#
|
||||
# The choice of possible arguments ($5) depends on the view.
|
||||
# These views are independent of the MusicBrainz ID ($4) and of the argument
|
||||
# ($5):
|
||||
# - VIEW_SEARCH_ARTIST: Get ready to query MusicBrainz for artists
|
||||
# - VIEW_SEARCH_ALBUM: Get ready to query MusicBrainz for albums
|
||||
# - VIEW_LIST_ARTISTS: List all locally available artists
|
||||
# - VIEW_LIST_ALBUMS: List al locally available albums
|
||||
#
|
||||
# If no argument ($5) is specified, then the remaining views act as follows:
|
||||
# - VIEW_ARTIST: Display all release groups of that artist
|
||||
# - VIEW_RELEASEGROUP: Display all releases within that release group
|
||||
# - VIEW_RELEASE: Display track list of specified release
|
||||
#
|
||||
# Here, if the argument is set to `-1`, then the parent entry is displayed:
|
||||
# - VIEW_ARTIST: Divert view to VIEW_LIST_ARTISTS
|
||||
# - VIEW_RELEASEGROUP: For single-artist release groups, divert to
|
||||
# VIEW_ARTIST of that artist, else display the artist selection.
|
||||
# - VIEW_RELEASE: Divert view to VIEW_LIST_RELEASEGROUP.
|
||||
#
|
||||
# Alternatively, if the argument is set to `+1`, then the child entry is
|
||||
# displayed:
|
||||
# - VIEW_ARTIST: Divert view to VIEW_LIST_ARTISTS
|
||||
# - VIEW_RELEASEGROUP: For single-artist release groups, divert to
|
||||
# VIEW_ARTIST of that artist, else display the artist selection.
|
||||
# - VIEW_RELEASE: Divert view to VIEW_LIST_RELEASEGROUP.
|
||||
#
|
||||
# Hence, the view is only diverted in this last case.
|
||||
mode="${2:-"$MODE_NORMAL"}"
|
||||
view="${3:-"$VIEW_LIST_ARTISTS"}"
|
||||
mbid="${4:-}"
|
||||
level="${5:-}"
|
||||
# Change state, if we are being diverted.
|
||||
case "$level" in
|
||||
"-1")
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
view="$VIEW_LIST_ARTISTS"
|
||||
mbid=""
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
view="$VIEW_ARTIST"
|
||||
mbid="$(mb_releasegroup "$mbid" | $JQ -r --compact-output '."artist-credit"[0].artist.id')"
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
view="$VIEW_RELEASEGROUP"
|
||||
mbid="$(mb_release "$mbid" | $JQ -r --compact-output '."release-group".id')"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"+1")
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") view="$VIEW_ARTIST" ;;
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") view="$VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASEGROUP") view="$VIEW_RELEASE" ;;
|
||||
esac
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
# Set initial query
|
||||
q="$(default_query "$view")"
|
||||
[ "$q" ] && q="$q "
|
||||
printf "show-input+change-query(%s)" "$q"
|
||||
# Store current state
|
||||
printf "+change-border-label(%s)+change-list-label(%s)" "$view" "$mbid"
|
||||
# Set header
|
||||
fzf_command_set_header "$view" "$mbid"
|
||||
# Set preview window
|
||||
case "$view" in
|
||||
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST") printf "+show-preview" ;;
|
||||
*) printf "+hide-preview" ;;
|
||||
esac
|
||||
# Handle MusicBrainz search views
|
||||
# - `change` trigger for async. MusicBrainz search
|
||||
# - input visible but search disabled
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM") printf "+rebind(change)+disable-search" ;;
|
||||
*) printf "+unbind(change)+enable-search" ;;
|
||||
esac
|
||||
# Load lines
|
||||
printf "+reload($0 --lines %s %s)" "$view" "$mbid"
|
||||
[ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input"
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-reload")
|
||||
fzf_handle_reload
|
||||
exit 0
|
||||
@@ -68,7 +281,7 @@ case "${1:-}" in
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-change")
|
||||
fzf_handle_change
|
||||
fzf_handle_change "$2"
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-key")
|
||||
@@ -92,10 +305,31 @@ case "${1:-}" in
|
||||
info "Done"
|
||||
exit 0
|
||||
;;
|
||||
"--internal-preview-artist")
|
||||
"--preview-artist")
|
||||
__preview_artist "$2"
|
||||
exit 0
|
||||
;;
|
||||
"--playlistcmd")
|
||||
case "$2" in
|
||||
"$PLAYLIST_CMD_REMOVE") mpv_rm_index $((FZF_POS - 1)) ;;
|
||||
"$PLAYLIST_CMD_UP") mpv_playlist_move $((FZF_POS - 1)) $((FZF_POS - 2)) ;;
|
||||
"$PLAYLIST_CMD_DOWN") mpv_playlist_move $((FZF_POS - 0)) $((FZF_POS - 1)) ;;
|
||||
"$PLAYLIST_CMD_CLEAR") mpv_playlist_clear ;;
|
||||
"$PLAYLIST_CMD_CLEAR_ABOVE")
|
||||
for i in $(seq "$FZF_POS"); do
|
||||
mpv_rm_index 0
|
||||
done
|
||||
;;
|
||||
"$PLAYLIST_CMD_CLEAR_BELOW")
|
||||
cnt=$(mpv_playlist_count)
|
||||
rem=$((cnt - FZF_POS + 1))
|
||||
for i in $(seq "$rem"); do
|
||||
mpv_rm_index $((FZF_POS - 1))
|
||||
done
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
"--playlist")
|
||||
list_playlist
|
||||
exit 0
|
||||
@@ -148,38 +382,47 @@ touch "$STATEFILE" "$ARGSFILE" "$STATEFILE_LAST" "$ARGSFILE_LAST"
|
||||
export STATEFILE ARGSFILE STATEFILE_LAST ARGSFILE_LAST
|
||||
|
||||
# Views and modes
|
||||
VIEW_ARTIST="artist"
|
||||
VIEW_RELEASEGROUP="rg"
|
||||
VIEW_RELEASE="release"
|
||||
VIEW_SEARCH_ARTIST="search-artist"
|
||||
VIEW_SEARCH_ALBUM="search-album"
|
||||
VIEW_LIST_ARTISTS="list-artists"
|
||||
VIEW_LIST_ALBUMS="list-albums"
|
||||
VIEW_SELECT_ARTIST="select-artist"
|
||||
VIEW_PLAYLIST="playlist"
|
||||
MODE_NORMAL="normal"
|
||||
MODE_INSERT="insert"
|
||||
export VIEW_ARTIST VIEW_RELEASEGROUP VIEW_RELEASE VIEW_SEARCH_ARTIST \
|
||||
VIEW_SEARCH_ALBUM VIEW_LIST_ARTISTS VIEW_LIST_ALBUMS VIEW_SELECT_ARTIST \
|
||||
VIEW_PLAYLIST MODE_NORMAL MODE_INSERT
|
||||
|
||||
case "${1:-}" in
|
||||
"--artist")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Artist ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_ARTIST" "$MODE_NORMAL" "$2"
|
||||
VIEW="$VIEW_ARTIST"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--releasegroup")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release-Group ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_RELEASEGROUP" "$MODE_NORMAL" "$2"
|
||||
VIEW="$VIEW_RELEASEGROUP"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--release")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_RELEASE" "$MODE_NORMAL" "$2"
|
||||
VIEW="$VIEW_RELEASE"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--search-artist")
|
||||
state_init "$VIEW_SEARCH_ARTIST" "$MODE_INSERT" "${2:-}"
|
||||
VIEW="$VIEW_SEARCH_ARTIST"
|
||||
MODE="$MODE_INSERT"
|
||||
MBID=""
|
||||
;;
|
||||
"--search-album")
|
||||
VIEW="$VIEW_SEARCH_ALBUM"
|
||||
MODE="$MODE_INSERT"
|
||||
MBID=""
|
||||
;;
|
||||
"--artists" | "")
|
||||
VIEW="$VIEW_LIST_ARTISTS"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
"--albums")
|
||||
VIEW="$VIEW_LIST_ALBUMS"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
"--search-artist") state_init "$VIEW_SEARCH_ARTIST" "$MODE_INSERT" "${2:-}" ;;
|
||||
"--search-album") state_init "$VIEW_SEARCH_ALBUM" "$MODE_INSERT" "${2:-}" ;;
|
||||
"--artists" | "") state_init "$VIEW_LIST_ARTISTS" "$MODE_NORMAL" "" ;;
|
||||
"--albums") state_init "$VIEW_LIST_ALBUMS" "$MODE_NORMAL" "" ;;
|
||||
*)
|
||||
err "Unknown option $1 (see --help)"
|
||||
exit 1
|
||||
@@ -189,15 +432,35 @@ esac
|
||||
# Start mpv
|
||||
mpv_start
|
||||
|
||||
# $KEYS_PLAY main loop
|
||||
# main loop
|
||||
# states are stored in (in)visible labels
|
||||
#
|
||||
# mode: [$MODE_NORMAL, $MODE_INSERT]
|
||||
# The mode is reflected on the input visibility. The variable $FZF_INPUT_STATE
|
||||
# is set to "hidden" if and only if the mode is `normal`. To swtich to `normal`
|
||||
# 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)`.
|
||||
#
|
||||
# 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_LIST_ARTISTS_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_LIST_ARTISTS")"
|
||||
IN_LIST_ALBUMS_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_LIST_ALBUMS")"
|
||||
IN_SEARCH_ARTIST_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_SEARCH_ARTIST")"
|
||||
IN_SEARCH_ALBUM_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_SEARCH_ALBUM")"
|
||||
FZF_CURRENT_MODE="\$FZF_INPUT_STATE"
|
||||
FZF_CURRENT_VIEW="\$FZF_BORDER_LABEL"
|
||||
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"
|
||||
while true; do
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
case "$view" in
|
||||
case "$VIEW" in
|
||||
"$VIEW_SELECT_ARTIST")
|
||||
sel=$(
|
||||
echo "$args" |
|
||||
echo "$ARGS" |
|
||||
list_artists_from_json |
|
||||
$FZF \
|
||||
--bind="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,\
|
||||
@@ -214,39 +477,139 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
--accept-nth="{3}" \
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
[ "$sel" ] && state_update "$VIEW_ARTIST" "$mode" "$sel" || state_revert
|
||||
[ "$sel" ] || continue
|
||||
MODE="$MODE_NORMAL"
|
||||
VIEW="$VIEW_ARTIST"
|
||||
MBID="$sel"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
list_playlist |
|
||||
$FZF \
|
||||
sel=$(
|
||||
list_playlist | $FZF \
|
||||
--reverse \
|
||||
--no-sort \
|
||||
--border=double \
|
||||
--border-label=" Playlist " \
|
||||
--border-label="╢ Playlist ╟" \
|
||||
--no-input \
|
||||
--margin="2%,10%" \
|
||||
--bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
--bind="r,ctrl-r:reload:$0 --playlist" \
|
||||
--bind="$KEYS_DOWN,$KEYS_N_DOWN:down" \
|
||||
--bind="$KEYS_UP,$KEYS_N_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="$KEYS_N_BOT:last" \
|
||||
--bind="$KEYS_N_TOP:first" \
|
||||
--bind="$KEYS_SELECT_ARTIST:transform:$0 --jumpto-artist $MODE_NORMAL $VIEW_PLAYLIST {2} {3}" \
|
||||
--bind="$KEYS_LIST_ARTISTS:print($VIEW_LIST_ARTISTS)+accept" \
|
||||
--bind="$KEYS_LIST_ALBUMS:print($VIEW_LIST_ALBUMS)+accept" \
|
||||
--bind="$KEYS_SEARCH_ARTIST:print($VIEW_SEARCH_ARTIST)+accept" \
|
||||
--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_PLAYBACK,$KEYS_N_PLAYBACK:transform($0 --playback $VIEW_PLAYLIST {2} {3} {4})+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_RELOAD:reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_REMOVE:execute-silent($0 --playlistcmd $PLAYLIST_CMD_REMOVE)+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_UP:execute-silent($0 --playlistcmd $PLAYLIST_CMD_UP)+up+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_DOWN:execute-silent($0 --playlistcmd $PLAYLIST_CMD_DOWN)+down+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR)+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_ABOVE:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_ABOVE)+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_BELOW:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_BELOW)+reload-sync:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_GOTO_RELEASE:print($VIEW_RELEASE)+accept" \
|
||||
--bind="$KEYS_PLAYLIST_QUIT:print($VIEW_LIST_ARTISTS)+accept" \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{1}" >/dev/null
|
||||
--with-nth="{1}" \
|
||||
--accept-nth="{2}" || true
|
||||
)
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
ARGS="$(echo "$sel" | head -2 | tail -1)"
|
||||
MBID=$ARGS
|
||||
debug "playlist terminated: view=$VIEW, ARGS=$ARGS"
|
||||
;;
|
||||
*) # Main instance
|
||||
"$VIEW_QUIT")
|
||||
debug "Quitting..."
|
||||
break
|
||||
;;
|
||||
*)
|
||||
# Main instance
|
||||
#
|
||||
# KEY-BINDINGS:
|
||||
# Key variables contain comma-delimited sequences of keys. Every key
|
||||
# variable starts with `KEYS_`. Key variables with the prefix `KEYS_I_` are
|
||||
# exclusive to the `insert` mode. Key variables with the prefix `KEYS_N_`
|
||||
# are exclusive to the `normal` mode. All other keys are bound to both
|
||||
# modes. It is important that the keys used in `KEYS_N_` variables are
|
||||
# naturally printable or modifications of the input string. See
|
||||
# `$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" \
|
||||
sel=$(
|
||||
$FZF \
|
||||
printf "" | $FZF \
|
||||
--reverse \
|
||||
--bind="start:reload:$0 --fzf-reload" \
|
||||
--bind="load:transform:$0 --fzf-load" \
|
||||
--bind="change:execute-silent($0 --fzf-change &)+reload:$0 --fzf-change-reload" \
|
||||
--bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
--expect="ctrl-c" \
|
||||
--info="inline-right" \
|
||||
--info-command="$0 --fzf-info" \
|
||||
--header-first \
|
||||
--header-border="bottom" \
|
||||
--bind="start:transform:$0 --draw $MODE $VIEW $MBID" \
|
||||
--bind="$KEYS_I_NORMAL:transform:$IN_NORMAL_MODE || echo hide-input" \
|
||||
--bind="$KEYS_N_INSERT:transform:$IN_NORMAL_MODE && echo show-input || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_DOWN:down" \
|
||||
--bind="$KEYS_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="$KEYS_N_DOWN:transform:$IN_NORMAL_MODE && echo down || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_UP:transform:$IN_NORMAL_MODE && echo up || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_BOT:transform:$IN_NORMAL_MODE && echo last || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_TOP:transform:$IN_NORMAL_MODE && echo first || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_IN:transform:[ {3} ] && $0 --draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {3} \"+1\"" \
|
||||
--bind="$KEYS_OUT:transform:[ {2} ] && $0 --draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} \"-1\"" \
|
||||
--bind="$KEYS_N_IN:transform:$IN_NORMAL_MODE && ([ {3} ] && $0 --draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {3} \"+1\") || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_OUT:transform:$IN_NORMAL_MODE && ([ {2} ] && $0 --draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} \"-1\") || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_SELECT_ARTIST:transform:$0 --jumpto-artist $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} {3}" \
|
||||
--bind="$KEYS_LIST_ARTISTS:transform:$0 --draw \$FZF_INPUT_STATE $VIEW_LIST_ARTISTS" \
|
||||
--bind="$KEYS_LIST_ALBUMS:transform:$0 --draw \$FZF_INPUT_STATE $VIEW_LIST_ALBUMS" \
|
||||
--bind="$KEYS_SEARCH_ARTIST:transform:$0 --draw $MODE_INSERT $VIEW_SEARCH_ARTIST" \
|
||||
--bind="$KEYS_SEARCH_ALBUM:transform:$0 --draw $MODE_INSERT $VIEW_SEARCH_ALBUM" \
|
||||
--bind="$KEYS_SWITCH_ARTIST_ALBUM:transform:case $FZF_CURRENT_VIEW in
|
||||
$VIEW_LIST_ARTISTS) $0 --draw $FZF_CURRENT_MODE $VIEW_LIST_ALBUMS ;;
|
||||
$VIEW_LIST_ALBUMS) $0 --draw $FZF_CURRENT_MODE $VIEW_LIST_ARTISTS ;;
|
||||
$VIEW_SEARCH_ARTIST) $0 --draw $MODE_INSERT $VIEW_SEARCH_ALBUM ;;
|
||||
$VIEW_SEARCH_ALBUM) $0 --draw $MODE_INSERT $VIEW_SEARCH_ARTIST ;;
|
||||
esac" \
|
||||
--bind="$KEYS_SWITCH_LOCAL_REMOTE:transform:case $FZF_CURRENT_VIEW in
|
||||
$VIEW_LIST_ARTISTS) $0 --draw $MODE_INSERT $VIEW_SEARCH_ARTIST ;;
|
||||
$VIEW_LIST_ALBUMS) $0 --draw $MODE_INSERT $VIEW_SEARCH_ALBUM ;;
|
||||
$VIEW_SEARCH_ARTIST) $0 --draw $MODE_NORMAL $VIEW_LIST_ARTISTS ;;
|
||||
$VIEW_SEARCH_ALBUM) $0 --draw $MODE_NORMAL $VIEW_LIST_ALBUMS ;;
|
||||
esac" \
|
||||
--bind="$KEYS_FILTER:transform:$0 --filter $FZF_CURRENT_MODE $FZF_CURRENT_VIEW" \
|
||||
--bind="$KEYS_BROWSE:execute-silent:
|
||||
[ {3} ] || exit 0
|
||||
case \$FZF_BORDER_LABEL in
|
||||
$VIEW_LIST_ARTISTS | $VIEW_SEARCH_ARTIST) t=artist ;;
|
||||
$VIEW_ARTIST | $VIEW_SEARCH_ALBUM | $VIEW_LIST_ALBUMS) t=release-group ;;
|
||||
$VIEW_RELEASEGROUP) t=release ;;
|
||||
$VIEW_RELEASE) t=track ;;
|
||||
esac
|
||||
open \"https://musicbrainz.org/\$t/{r3}\"" \
|
||||
--bind="$KEYS_OPEN:execute-silent:
|
||||
[ {4} ] || exit 0
|
||||
open \"\$(dirname {4})\"" \
|
||||
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+accept" \
|
||||
--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 --draw $MODE_NORMAL $VIEW_LIST_ARTISTS) || $PUT_FZF_KEY_LOGIC" \
|
||||
--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="change:execute-silent($0 --fzf-change $FZF_CURRENT_VIEW &)+reload:$0 --fzf-change-reload" \
|
||||
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
|
||||
--preview="$0 --internal-preview-artist {3}" \
|
||||
--preview="$0 --preview-artist {3}" \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
[ "$(echo "$sel" | head -1)" = "ctrl-c" ] && break
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
ARGS="$(echo "$sel" | head -2 | tail -1)"
|
||||
debug "FZF terminated: view=$VIEW, ARGS=$ARGS"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
#[ \"$MODE\" = \"$MODE_NORMAL\" ] && echo \"+hide-input\" || echo \"+show-input\"
|
||||
# --bind="load:transform:$0 --fzf-load" \
|
||||
# --bind="change:execute-silent($0 --fzf-change &)+reload:$0 --fzf-change-reload" \
|
||||
# --bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
|
214
src/sh/filter.sh
Normal file
214
src/sh/filter.sh
Normal file
@@ -0,0 +1,214 @@
|
||||
# The default queries depend on the current view, and are usually derived from
|
||||
# the theme. Nevertheless, they may be overwritten with the configuration file.
|
||||
# Note that filters are not used in the views VIEW_SEARCH_ARTIST and
|
||||
# VIEW_SEARCH_ALBUM. The reason for this is that in those modes, changing the
|
||||
# query string triggers a search on the MusicBrainz website (the input is not a
|
||||
# filter, but a query).
|
||||
#
|
||||
# The keybinding KEYS_FILTER_LOCAL triggers a filter of QUERY_LOCAL in the
|
||||
# views VIEW_ARTIST, VIEW_RELEASEGROUP, and VIEW_RELEASE only. Here, it is only
|
||||
# possible to adjust QUERY_LOCAL via the configuration. The keybinding KEYS_FILTER_0
|
||||
# resets the query. F_1_.. filters are the default filters when the respective
|
||||
# view is entered. For all other keys, the filters are individually
|
||||
# configurable, by specifying e.g., F_3_VIEW_LIST_ALBUMS.
|
||||
#
|
||||
# Derived queries
|
||||
# To derive the queries from the theme, we must perform some steps: 1) remove
|
||||
# colors, and 2) escape white spaces. This is implemented in the method
|
||||
# `__clean_filter`.
|
||||
#
|
||||
# List of derived queries:
|
||||
# - QUERY_LOCAL: Hide items that are not locally available
|
||||
# - q_has_secondary: Release groups with secondary types
|
||||
# - q_album: Release group is of type Album
|
||||
# - q_ep: Release group is of type EP
|
||||
# - q_single: Release group is of type single
|
||||
# - q_official: Release is official
|
||||
|
||||
__clean_filter() {
|
||||
cat | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g"
|
||||
}
|
||||
|
||||
QUERY_LOCAL="${QUERY_LOCAL:-"$(printf "'%s'" "$FORMAT_LOCAL" | __clean_filter)"}"
|
||||
q_has_seconary="$(printf "$FORMAT_TYPE_HAS_SECONDARY" "" | __clean_filter)"
|
||||
q_album="$(printf "%s" "$FORMAT_TYPE_ALBUM" | __clean_filter)"
|
||||
q_ep=$(printf "%s" "$FORMAT_TYPE_EP" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
q_single=$(printf "%s" "$FORMAT_TYPE_SINGLE" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
if printf "$RV_FORMAT" | grep -q "<<status>>"; then
|
||||
q_official=$(printf "'%s'" "$FORMAT_STATUS_OFFICIAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
fi
|
||||
|
||||
F_1_VIEW_ARTIST="${F_1_VIEW_ARTIST:-"!'$q_has_seconary'"}"
|
||||
F_2_VIEW_ARTIST="${F_2_VIEW_ARTIST:-"'$q_album'"}"
|
||||
F_3_VIEW_ARTIST="${F_3_VIEW_ARTIST:-"'$q_ep'"}"
|
||||
F_4_VIEW_ARTIST="${F_4_VIEW_ARTIST:-"'$q_single'"}"
|
||||
F_5_VIEW_ARTIST="${F_5_VIEW_ARTIST:-}"
|
||||
F_6_VIEW_ARTIST="${F_6_VIEW_ARTIST:-}"
|
||||
F_7_VIEW_ARTIST="${F_7_VIEW_ARTIST:-}"
|
||||
F_8_VIEW_ARTIST="${F_8_VIEW_ARTIST:-}"
|
||||
F_9_VIEW_ARTIST="${F_9_VIEW_ARTIST:-}"
|
||||
|
||||
F_1_VIEW_RELEASEGROUP="${F_1_VIEW_RELEASEGROUP:-"${q_official:-}"}"
|
||||
F_2_VIEW_RELEASEGROUP="${F_2_VIEW_RELEASEGROUP:-}"
|
||||
F_3_VIEW_RELEASEGROUP="${F_3_VIEW_RELEASEGROUP:-}"
|
||||
F_4_VIEW_RELEASEGROUP="${F_4_VIEW_RELEASEGROUP:-}"
|
||||
F_5_VIEW_RELEASEGROUP="${F_5_VIEW_RELEASEGROUP:-}"
|
||||
F_6_VIEW_RELEASEGROUP="${F_6_VIEW_RELEASEGROUP:-}"
|
||||
F_7_VIEW_RELEASEGROUP="${F_7_VIEW_RELEASEGROUP:-}"
|
||||
F_8_VIEW_RELEASEGROUP="${F_8_VIEW_RELEASEGROUP:-}"
|
||||
F_9_VIEW_RELEASEGROUP="${F_9_VIEW_RELEASEGROUP:-}"
|
||||
|
||||
F_1_VIEW_RELEASE="${F_1_VIEW_RELEASE:-}"
|
||||
F_2_VIEW_RELEASE="${F_2_VIEW_RELEASE:-}"
|
||||
F_3_VIEW_RELEASE="${F_3_VIEW_RELEASE:-}"
|
||||
F_4_VIEW_RELEASE="${F_4_VIEW_RELEASE:-}"
|
||||
F_5_VIEW_RELEASE="${F_5_VIEW_RELEASE:-}"
|
||||
F_6_VIEW_RELEASE="${F_6_VIEW_RELEASE:-}"
|
||||
F_7_VIEW_RELEASE="${F_7_VIEW_RELEASE:-}"
|
||||
F_8_VIEW_RELEASE="${F_8_VIEW_RELEASE:-}"
|
||||
F_9_VIEW_RELEASE="${F_9_VIEW_RELEASE:-}"
|
||||
|
||||
F_1_LIST_ARTISTS="${F_1_LIST_ARTISTS:-}"
|
||||
F_2_LIST_ARTISTS="${F_2_LIST_ARTISTS:-}"
|
||||
F_3_LIST_ARTISTS="${F_3_LIST_ARTISTS:-}"
|
||||
F_4_LIST_ARTISTS="${F_4_LIST_ARTISTS:-}"
|
||||
F_5_LIST_ARTISTS="${F_5_LIST_ARTISTS:-}"
|
||||
F_6_LIST_ARTISTS="${F_6_LIST_ARTISTS:-}"
|
||||
F_7_LIST_ARTISTS="${F_7_LIST_ARTISTS:-}"
|
||||
F_8_LIST_ARTISTS="${F_8_LIST_ARTISTS:-}"
|
||||
F_9_LIST_ARTISTS="${F_9_LIST_ARTISTS:-}"
|
||||
|
||||
F_1_LIST_ALBUMS="${F_1_LIST_ALBUMS:-}"
|
||||
F_2_LIST_ALBUMS="${F_2_LIST_ALBUMS:-}"
|
||||
F_3_LIST_ALBUMS="${F_3_LIST_ALBUMS:-}"
|
||||
F_4_LIST_ALBUMS="${F_4_LIST_ALBUMS:-}"
|
||||
F_5_LIST_ALBUMS="${F_5_LIST_ALBUMS:-}"
|
||||
F_6_LIST_ALBUMS="${F_6_LIST_ALBUMS:-}"
|
||||
F_7_LIST_ALBUMS="${F_7_LIST_ALBUMS:-}"
|
||||
F_8_LIST_ALBUMS="${F_8_LIST_ALBUMS:-}"
|
||||
F_9_LIST_ALBUMS="${F_9_LIST_ALBUMS:-}"
|
||||
|
||||
# Determine preset query
|
||||
# @argument $1: Current view
|
||||
# @argument $2: Key pressed (optional)
|
||||
#
|
||||
# If the key is not given, then the F_1_.. query is used for the respective
|
||||
# view, i.e, its as if a key from KEYS_FILTER_1 has been pressed.
|
||||
default_query() {
|
||||
view=$1
|
||||
key="${2:-"$(echo "$KEYS_FILTER_1" | cut -d ',' -f 1)"}"
|
||||
case ",$KEYS_FILTER_LOCAL," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_RELEASEGROUP" | "$VIEW_RELEASE") echo "$QUERY_LOCAL" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_1," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_1_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_1_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_1_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_1_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_1_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_2," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_2_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_2_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_2_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_2_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_2_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_3," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_3_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_3_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_3_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_3_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_3_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_4," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_4_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_4_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_4_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_4_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_4_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_5," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_5_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_5_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_5_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_5_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_5_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_6," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_6_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_6_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_6_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_6_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_6_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_7," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_7_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_7_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_7_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_7_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_7_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_8," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_8_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_8_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_8_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_8_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_8_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_9," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_9_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_9_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_9_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_9_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_9_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
# Doing nothing is the same as this last block:
|
||||
# case ",$KEYS_FILTER_0," in
|
||||
# *",$key,"*)
|
||||
# case "$view" in
|
||||
# "$VIEW_ARTIST" | "$VIEW_RELEASEGROUP" | "$VIEW_RELEASE" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") echo "" ;;
|
||||
# esac
|
||||
# ;;
|
||||
# esac
|
||||
}
|
@@ -1,3 +1,54 @@
|
||||
# Print the command that sets the header.
|
||||
# @argument $1: view
|
||||
# @argument $2: mbid
|
||||
fzf_command_set_header() {
|
||||
view=$1
|
||||
mbid=$2
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST") header="Search artist on MusicBrainz" ;;
|
||||
"$VIEW_SEARCH_ALBUM") header="Search album on MusicBrainz" ;;
|
||||
"$VIEW_LIST_ARTISTS") header="Search locally available artist" ;;
|
||||
"$VIEW_LIST_ALBUMS") header="Search locally available album" ;;
|
||||
"$VIEW_ARTIST")
|
||||
name="$(mb_artist "$mbid" | $JQ -r '.name')"
|
||||
header=$(printf "$ARTIST_PROMPT" "$name")
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
title="$(mb_releasegroup "$mbid" |
|
||||
$JQ -r '.title')"
|
||||
artist="$(mb_releasegroup "$mbid" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
header=$(printf "$FULL_PROMPT" "$artist" "$title")
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
title="$(mb_release "$mbid" |
|
||||
$JQ -r '.title')"
|
||||
artist="$(mb_release "$mbid" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
header=$(printf "$FULL_PROMPT" "$artist" "$title")
|
||||
;;
|
||||
esac
|
||||
printf "+change-header(%s)" "${header:-"???"}"
|
||||
}
|
||||
|
||||
# Print the command that tells fzf to load the data
|
||||
# @argument $1: view
|
||||
# @argument $2: mbid
|
||||
fzf_command_load_data() {
|
||||
view=$1
|
||||
mbid=${2:-}
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST") ;;
|
||||
"$VIEW_SEARCH_ALBUM") ;;
|
||||
"$VIEW_LIST_ARTISTS") ;;
|
||||
"$VIEW_LIST_ALBUMS") ;;
|
||||
"$VIEW_ARTIST") ;;
|
||||
"$VIEW_RELEASEGROUP") ;;
|
||||
"$VIEW_RELEASE") ;;
|
||||
esac
|
||||
printf "+reload($0 --lines %s %s)" "$VIEW_LIST_ARTISTS" ""
|
||||
}
|
||||
|
||||
# Set prompt of input field
|
||||
# @argument $1: view
|
||||
# @argument $2: mode
|
||||
@@ -25,7 +76,7 @@ __set_prompt() {
|
||||
;;
|
||||
esac
|
||||
[ "$mode" = "$MODE_INSERT" ] && PT="$PROMPT_INSERT" || PT="$PROMPT_NORMAL"
|
||||
printf "+change-prompt(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
|
||||
printf "+change-header(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
|
||||
}
|
||||
|
||||
# Reload data for FZF
|
||||
@@ -78,7 +129,7 @@ fzf_handle_load() {
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS") ;;
|
||||
esac
|
||||
[ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)" "${QUERY:-}"
|
||||
[ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)+disable-search" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)+enable-search" "${QUERY:-}"
|
||||
[ "${SHOW_PREVIEW:-}" ] && printf "+show-preview" || printf "+hide-preview"
|
||||
[ "${ENABLE_CHANGE:-}" ] && printf "+rebind(change)" || printf "+unbind(change)"
|
||||
__set_prompt "$view" "$mode"
|
||||
@@ -123,12 +174,13 @@ fzf_reload_after_change() {
|
||||
sleep 1
|
||||
done
|
||||
# Show results
|
||||
column -t -s "$(printf '\t')" -E 0 "$RESULTS" |
|
||||
column -t -s "$(printf '\t')" "$RESULTS" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
# Handle change in query
|
||||
fzf_handle_change() {
|
||||
view="$1"
|
||||
# Kill any running search
|
||||
if [ -f "$PIDFILE" ]; then
|
||||
pid=$(cat "$PIDFILE")
|
||||
@@ -141,7 +193,6 @@ fzf_handle_change() {
|
||||
echo "$$" >"$PIDFILE"
|
||||
touch "$LOCKFILE"
|
||||
sleep 1
|
||||
view=$(state_get_view)
|
||||
if [ "$view" = "$VIEW_SEARCH_ARTIST" ]; then
|
||||
api_mb_search_artist "$FZF_QUERY" |
|
||||
$JQ -r '.artists[] | [
|
||||
@@ -518,7 +569,7 @@ fzf_handle_key() {
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_TOGGLE_PLAY_PAUSE," in
|
||||
case ",$KEYS_N_TOGGLE_PLAYBACK," in
|
||||
*",$FZF_KEY,"*) mpv_toggle_pause >/dev/null ;;
|
||||
esac
|
||||
|
||||
@@ -547,6 +598,7 @@ fzf_handle_key() {
|
||||
if [ "${VIEW_NEXT:-}" ]; then
|
||||
[ "$VIEW_NEXT" = "$VIEW_PLAYLIST" ] && MODE_NEXT="$MODE_NORMAL"
|
||||
state_update "$VIEW_NEXT" "${MODE_NEXT:-"$mode"}" "${VIEW_NEXT_ARGS:-}"
|
||||
[ "$MODE_NEXT" = "$MODE_INSERT" ] && printf "+enable-search" || printf "+disable-search"
|
||||
[ "${ACCEPT:-}" ] && printf "+accept" || printf "+reload:%s" "$0 --fzf-reload"
|
||||
fi
|
||||
}
|
||||
|
220
src/sh/keys.sh
220
src/sh/keys.sh
@@ -1,64 +1,196 @@
|
||||
# List of keys, organized in groups
|
||||
#
|
||||
# Mode selection:
|
||||
# - KEYS_I_NORMAL: Switch to normal mode (insert mode)
|
||||
# - KEYS_N_INSERT: Switch to insert mode (normal mode)
|
||||
#
|
||||
# Vertical navigation:
|
||||
# - KEYS_DOWN: Move cursor to the next line
|
||||
# - KEYS_UP: Move cursor to the previous line
|
||||
# - KEYS_HALFPAGE_UP: Move cursor half a page up
|
||||
# - KEYS_HALFPAGE_DOWN: Move cursor half a page up
|
||||
# - KEYS_N_DOWN: Move cursor to the next line (normal mode)
|
||||
# - KEYS_N_UP: Move cursor to the previous line (normal mode)
|
||||
# - KEYS_N_BOT: Move cursor to the last line (normal mode)
|
||||
# - KEYS_N_TOP: Move cursor to the first line (normal mode)
|
||||
#
|
||||
# Horizontal navigation:
|
||||
# - KEYS_IN: Enter into selected item, down the hierarchy
|
||||
# - KEYS_OUT: Leave current item, up the hierarchy
|
||||
# - KEYS_N_IN: Enter into selected item, down the hierarchy (normal mode)
|
||||
# - KEYS_N_OUT: Leave current item, up the hierarchy (normal mode)
|
||||
# - KEYS_SELECT_ARTIST: Go to artist of selected entry (in case of multiple
|
||||
# artists, provide a choice)
|
||||
# - KEYS_LIST_ARTISTS: Go to VIEW_LIST_ARTISTS
|
||||
# - KEYS_LIST_ALBUMS: Go to VIEW_LIST_ALBUMS
|
||||
# - KEYS_SEARCH_ARTIST: Go to VIEW_SEARCH_ARTIST
|
||||
# - KEYS_SEARCH_ALBUM: Go to VIEW_SEARCH_ALBUM
|
||||
# - KEYS_SWITCH_ARTIST_ALBUM: Switch artist and album views, i.e.,
|
||||
# VIEW_LIST_ARTISTS <-> VIEW_LIST_ALBUMS, and VIEW_SEARCH_ARTIST <->
|
||||
# VIEW_SEARCH_ALBUM.
|
||||
# - KEYS_SWITCH_LOCAL_REMOTE: Switch between locally available music and remote
|
||||
# search views, i.e., VIEW_LIST_ARTISTS <-> VIEW_SEARCH_ARTIST, and
|
||||
# VIEW_LIST_ALBUMS <-> VIEW_SEARCH_ALBUM.
|
||||
#
|
||||
# Filtering:
|
||||
# - KEYS_FILTER_LOCAL: List only locally available entries
|
||||
# - KEYS_FILTER_0: Clear query
|
||||
# - KEYS_FILTER_1: Reset query to the default one for the current view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_2: Preset query `2` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_3: Preset query `3` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_4: Preset query `4` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_5: Preset query `5` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_6: Preset query `6` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_7: Preset query `7` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_8: Preset query `8` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_9: Preset query `9` depending on the view (see `src/sh/filter.sh`)
|
||||
#
|
||||
# Specials:
|
||||
# - KEYS_BROWSE: Open MusicBrainz webpage of the selected item
|
||||
# - KEYS_OPEN: Open file manager in the directory of the selected item
|
||||
# - KEYS_SHOW_PLAYLIST: Switch to playlist view
|
||||
# - 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)
|
||||
#
|
||||
# Playback:
|
||||
# - KEYS_PLAY: Play selected release or selected track
|
||||
# - KEYS_QUEUE: Queue selected release or selected track
|
||||
# - KEYS_QUEUE_NEXT: Queue selected release or selected track as next entry in
|
||||
# the playlist
|
||||
# - KEYS_N_TOGGLE_PLAYBACK: Play-pause toggle
|
||||
# - 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
|
||||
#
|
||||
# Playlist (in the playlist, there is no `insert` mode):
|
||||
# - KEYS_PLAYLIST_RELOAD: Manually reload playlist
|
||||
# - KEYS_PLAYLIST_REMOVE: Remove item from playlist
|
||||
# - KEYS_PLAYLIST_UP: Move item one position up
|
||||
# - KEYS_PLAYLIST_DOWN: Move item one position down
|
||||
# - KEYS_PLAYLIST_CLEAR: Clear playlist
|
||||
# - KEYS_PLAYLIST_CLEAR_ABOVE: Remove all items above incl. the selected one
|
||||
# - KEYS_PLAYLIST_CLEAR_BELOW: Remove all items below incl. the selected one
|
||||
# - KEYS_PLAYLIST_GOTO_RELEASE: Jump to release or seleted enry
|
||||
# - KEYS_PLAYLIST_STORE: Store current playlist as file
|
||||
# - KEYS_PLAYLIST_LOAD: Load playlist from file
|
||||
# - KEYS_PLAYLIST_QUIT: Quit playlist view
|
||||
#
|
||||
|
||||
# Mode selection:
|
||||
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
|
||||
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/,?"}"
|
||||
|
||||
# Vertical navigation:
|
||||
KEYS_DOWN="${KEYS_DOWN:-"ctrl-j,down"}"
|
||||
KEYS_UP="${KEYS_UP:-"ctrl-k,up"}"
|
||||
KEYS_HALFPAGE_DOWN="${KEYS_HALFPAGE_DOWN:-"ctrl-d"}"
|
||||
KEYS_HALFPAGE_UP="${KEYS_HALFPAGE_UP:-"ctrl-u"}"
|
||||
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
|
||||
KEYS_N_UP="${KEYS_N_UP:-"k"}"
|
||||
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
|
||||
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
|
||||
|
||||
# Horizontal navigation:
|
||||
KEYS_IN="${KEYS_IN:-"ctrl-l"}"
|
||||
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
|
||||
KEYS_N_IN="${KEYS_N_IN:-"l"}"
|
||||
KEYS_N_OUT="${KEYS_N_OUT:-"h"}"
|
||||
KEYS_SELECT_ARTIST="${KEYS_SELECT_ARTIST:-"ctrl-a"}"
|
||||
KEYS_LIST_ARTISTS="${KEYS_LIST_ARTISTS:-"alt-a"}"
|
||||
KEYS_LIST_ALBUMS="${KEYS_LIST_ALBUMS:-"alt-s"}"
|
||||
KEYS_SEARCH_ARTIST="${KEYS_SEARCH_ARTIST:-"alt-z"}"
|
||||
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-/"}"
|
||||
|
||||
# Filtering:
|
||||
KEYS_FILTER_LOCAL="${KEYS_FILTER_LOCAL:-"alt-l"}"
|
||||
KEYS_FILTER_1="${KEYS_FILTER_1:-"alt-1"}"
|
||||
KEYS_FILTER_2="${KEYS_FILTER_2:-"alt-2"}"
|
||||
KEYS_FILTER_3="${KEYS_FILTER_3:-"alt-3"}"
|
||||
KEYS_FILTER_4="${KEYS_FILTER_4:-"alt-4"}"
|
||||
KEYS_FILTER_5="${KEYS_FILTER_5:-"alt-5"}"
|
||||
KEYS_FILTER_6="${KEYS_FILTER_6:-"alt-6"}"
|
||||
KEYS_FILTER_7="${KEYS_FILTER_7:-"alt-7"}"
|
||||
KEYS_FILTER_8="${KEYS_FILTER_8:-"alt-8"}"
|
||||
KEYS_FILTER_9="${KEYS_FILTER_9:-"alt-9"}"
|
||||
KEYS_FILTER_0="${KEYS_FILTER_0:-"alt-0"}"
|
||||
KEYS_FILTER="$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_FILTER_5,$KEYS_FILTER_6,$KEYS_FILTER_7,$KEYS_FILTER_8,$KEYS_FILTER_9,$KEYS_FILTER_0"
|
||||
|
||||
# Specials:
|
||||
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
|
||||
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
|
||||
KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}"
|
||||
KEYS_QUIT="${KEYS_QUIT:-"ctrl-c"}"
|
||||
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
|
||||
|
||||
# Playback:
|
||||
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
||||
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}" # That's actually alt-enter
|
||||
KEYS_QUEUE_NEXT="${KEYS_QUEUE_NEXT:-"ctrl-alt-n"}"
|
||||
KEYS_TOGGLE_PLAYBACK="${KEYS_TOGGLE_PLAYBACK:-"ctrl-space"}"
|
||||
KEYS_PLAY_NEXT="${KEYS_PLAY_NEXT:-"alt-n"}"
|
||||
KEYS_PLAY_PREV="${KEYS_PLAY_PREV:-"alt-p"}"
|
||||
KEYS_SEEK_FORWARD="${KEYS_SEEK_FORWARD:-"alt-N"}"
|
||||
KEYS_SEEK_BACKWARD="${KEYS_SEEK_BACKWARD:-"alt-P"}"
|
||||
KEYS_PLAYBACK="$KEYS_PLAY,$KEYS_QUEUE,$KEYS_QUEUE_NEXT,$KEYS_TOGGLE_PLAYBACK,$KEYS_PLAY_NEXT,$KEYS_PLAY_PREV,$KEYS_SEEK_FORWARD,$KEYS_SEEK_BACKWARD"
|
||||
KEYS_N_PLAY="${KEYS_N_PLAY:-"."}"
|
||||
KEYS_N_QUEUE="${KEYS_N_QUEUE:-";"}"
|
||||
KEYS_N_QUEUE_NEXT="${KEYS_N_QUEUE_NEXT:-":"}"
|
||||
KEYS_N_TOGGLE_PLAYBACK="${KEYS_N_TOGGLE_PLAYBACK:-"space"}"
|
||||
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right,n"}"
|
||||
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left,p"}"
|
||||
KEYS_N_SEEK_FORWARD="${KEYS_N_SEEK_FORWARD:-"N,f"}"
|
||||
KEYS_N_SEEK_BACKWARD="${KEYS_N_SEEK_BACKWARD:-"P,b"}"
|
||||
KEYS_N_PLAYBACK="$KEYS_N_PLAY,$KEYS_N_QUEUE,$KEYS_N_QUEUE_NEXT,$KEYS_N_TOGGLE_PLAYBACK,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD"
|
||||
|
||||
# Playlist (in the playlist, there is no `insert` mode):
|
||||
KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r,ctrl-r"}"
|
||||
KEYS_PLAYLIST_REMOVE="${KEYS_PLAYLIST_REMOVE:-"x,delete"}"
|
||||
KEYS_PLAYLIST_UP="${KEYS_PLAYLIST_UP:-"u"}"
|
||||
KEYS_PLAYLIST_DOWN="${KEYS_PLAYLIST_DOWN:-"d"}"
|
||||
KEYS_PLAYLIST_CLEAR="${KEYS_PLAYLIST_CLEAR:-"C"}"
|
||||
KEYS_PLAYLIST_CLEAR_ABOVE="${KEYS_PLAYLIST_CLEAR_ABOVE:-"U"}"
|
||||
KEYS_PLAYLIST_CLEAR_BELOW="${KEYS_PLAYLIST_CLEAR_BELOW:-"D"}"
|
||||
KEYS_PLAYLIST_GOTO_RELEASE="${KEYS_PLAYLIST_GOTO_RELEASE:-"ctrl-g"}"
|
||||
KEYS_PLAYLIST_STORE="${KEYS_PLAYLIST_STORE:-"ctrl-s"}"
|
||||
KEYS_PLAYLIST_LOAD="${KEYS_PLAYLIST_LOAD:-"ctrl-o"}"
|
||||
KEYS_PLAYLIST_QUIT="${KEYS_PLAYLIST_QUIT:-"q,ctrl-c,esc"}"
|
||||
|
||||
## Not yet characterized
|
||||
##########################
|
||||
|
||||
KEYS_INPUT_SINGLE='0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,!,",#,$,%,&,\,(,),*,+,,,-,.,/,:,;,<,=,>,?,@,[,\,\,],^,_,`,{,|,},~'
|
||||
KEYS_INPUT_SINGLE="$KEYS_INPUT_SINGLE,'"
|
||||
KEYS_INPUT_SPECIAL="space,backspace,delete,left,right"
|
||||
export KEYS_INPUT_SINGLE KEYS_INPUT_SPECIAL
|
||||
|
||||
# Normal and insert mode
|
||||
KEYS_HALFPAGE_DOWN="${KEYS_HALFPAGE_DOWN:-"ctrl-d"}"
|
||||
KEYS_HALFPAGE_UP="${KEYS_HALFPAGE_UP:-"ctrl-u"}"
|
||||
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
|
||||
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
|
||||
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
|
||||
KEYS_IN="${KEYS_IN:-"ctrl-l"}"
|
||||
KEYS_SELECT_ARTIST="${KEYS_SELECT_ARTIST:-"ctrl-a"}"
|
||||
KEYS_FILTER_LOCAL="${KEYS_FILTER_LOCAL:-"alt-l"}"
|
||||
KEYS_FILTER_1="${KEYS_FILTER_1:-"alt-1"}"
|
||||
KEYS_FILTER_2="${KEYS_FILTER_2:-"alt-2"}"
|
||||
KEYS_FILTER_3="${KEYS_FILTER_3:-"alt-3"}"
|
||||
KEYS_FILTER_4="${KEYS_FILTER_4:-"alt-4"}"
|
||||
KEYS_SWITCH_ARTIST_ALBUM="${KEYS_SWITCH_ARTIST_ALBUM:-"tab"}"
|
||||
KEYS_SWITCH_LOCAL_REMOTE="${KEYS_SWITCH_LOCAL_REMOTE:-"ctrl-/"}"
|
||||
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
||||
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}"
|
||||
KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}"
|
||||
KEYS_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_BROWSE,$KEYS_OPEN,$KEYS_OUT,$KEYS_IN,$KEYS_SELECT_ARTIST,$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_SWITCH_ARTIST_ALBUM,$KEYS_SWITCH_LOCAL_REMOTE,$KEYS_PLAY,$KEYS_QUEUE,$KEYS_SHOW_PLAYLIST"
|
||||
export KEYS_NI
|
||||
|
||||
# Keys in normal mode only
|
||||
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
|
||||
KEYS_N_UP="${KEYS_N_UP:-"k"}"
|
||||
KEYS_N_OUT="${KEYS_N_OUT:-"h"}"
|
||||
KEYS_N_IN="${KEYS_N_IN:-"l"}"
|
||||
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
|
||||
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
|
||||
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
|
||||
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/"}"
|
||||
KEYS_N_TOGGLE_PLAY_PAUSE="${KEYS_N_TOGGLE_PLAY_PAUSE:-"space"}"
|
||||
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right"}"
|
||||
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left"}"
|
||||
KEYS_N_SEEK_FORWARD="${KEYS_N_SEEK_FORWARD:-"shift-right"}"
|
||||
KEYS_N_SEEK_BACKWARD="${KEYS_N_SEEK_BACKWARD:-"shift-left"}"
|
||||
|
||||
# Special playlist keys
|
||||
KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r"}"
|
||||
KEYS_N="$KEYS_N_DOWN,$KEYS_N_UP,$KEYS_N_OUT,$KEYS_N_IN,$KEYS_N_TOP,$KEYS_N_BOT,$KEYS_N_QUIT,$KEYS_N_INSERT,$KEYS_N_TOGGLE_PLAYBACK,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD"
|
||||
export KEYS_N
|
||||
|
||||
# Keys in insert mode only
|
||||
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
|
||||
KEYS_I="$KEYS_I_NORMAL"
|
||||
export KEYS_I
|
||||
|
||||
# Special playlist keys
|
||||
KEYS_PLAYLIST="$KEYS_PLAYLIST_RELOAD"
|
||||
export KEYS_PLAYLIST
|
||||
|
||||
# Grouping
|
||||
KEYS_GROUP_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_OPEN,$KEYS_BROWSE,$KEYS_OUT,$KEYS_IN,$KEYS_SELECT_ARTIST,$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_SWITCH_ARTIST_ALBUM,$KEYS_SWITCH_LOCAL_REMOTE,$KEYS_PLAY,$KEYS_QUEUE,$KEYS_SHOW_PLAYLIST"
|
||||
|
||||
KEYS_GROUP_N="$KEYS_N_DOWN,$KEYS_N_UP,$KEYS_N_OUT,$KEYS_N_IN,$KEYS_N_TOP,$KEYS_N_BOT,$KEYS_N_QUIT,$KEYS_N_INSERT,$KEYS_N_TOGGLE_PLAY_PAUSE,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD"
|
||||
|
||||
KEYS_GROUP_I="$KEYS_I_NORMAL"
|
||||
|
||||
KEYS_PLAYLIST="$KEYS_PLAYLIST_RELOAD"
|
||||
|
||||
KEYS_ALL="$KEYS_GROUP_NI,$KEYS_GROUP_N,$KEYS_GROUP_I,$KEYS_INPUT_SINGLE,$KEYS_INPUT_SPECIAL,$KEYS_PLAYLIST"
|
||||
KEYS_ALL="$KEYS_NI,$KEYS_N,$KEYS_I,$KEYS_INPUT_SINGLE,$KEYS_INPUT_SPECIAL,$KEYS_PLAYLIST"
|
||||
|
||||
export KEYS_HALFPAGE_DOWN KEYS_HALFPAGE_UP KEYS_OPEN KEYS_BROWSE KEYS_OUT KEYS_IN \
|
||||
KEYS_SELECT_ARTIST KEYS_FILTER_LOCAL KEYS_FILTER_1 KEYS_FILTER_2 KEYS_FILETER_3 KEYS_FILTER_4 \
|
||||
KEYS_SWITCH_ARTIST_ALBUM KEYS_SWITCH_LOCAL_REMOTE KEYS_PLAY KEYS_QUEUE \
|
||||
KEYS_N_DOWN KEYS_N_UP KEYS_N_OUT KEYS_N_IN KEYS_N_TOP KEYS_N_BOT KEYS_N_QUIT KEYS_N_INSERT \
|
||||
KEYS_N_TOGGLE_PLAY_PAUSE KEYS_N_PLAY_NEXT KEYS_N_PLAY_PREV KEYS_N_SEEK_FORWARD \
|
||||
KEYS_N_TOGGLE_PLAYBACK KEYS_N_PLAY_NEXT KEYS_N_PLAY_PREV KEYS_N_SEEK_FORWARD \
|
||||
KEYS_N_SEEK_BACKWARD KEYS_SHOW_PLAYLIST \
|
||||
KEYS_I_NORMAL \
|
||||
KEYS_GROUP_NI KEYS_GROUP_N KEYS_GROUP_I KEYS PLAYLIST KEYS_ALL
|
||||
|
@@ -14,6 +14,7 @@ list_releasegroups() {
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v artist="$name" \
|
||||
-v artistid="$1" \
|
||||
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
|
||||
-v format_release="$RGV_RELEASE" \
|
||||
-v format_release_w_artist="$RGV_RELEASE_W_ARTIST" \
|
||||
@@ -41,7 +42,7 @@ list_releasegroups() {
|
||||
"$AWK_RELEASEGROUPS" |
|
||||
sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
column -t -s "$(printf '\t')" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
@@ -53,8 +54,7 @@ list_releases() {
|
||||
artist="$(mb_releasegroup "$1" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
mb_releasegroup_releases "$1" |
|
||||
$JQ -r --arg rid "$1" '."releases"[] | [
|
||||
$rid,
|
||||
$JQ -r '."releases"[] | [
|
||||
.id,
|
||||
.status,
|
||||
.date,
|
||||
@@ -82,11 +82,12 @@ list_releases() {
|
||||
-v release_format_artist="$RV_ARTIST" \
|
||||
-v rg_artist="$artist" \
|
||||
-v rg_title="$title" \
|
||||
-v rgid="$1" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASES" |
|
||||
sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
column -t -s "$(printf '\t')" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ list_recordings() {
|
||||
"$AWK_RECORDINGS" |
|
||||
sort -k1,1n -k2,2g |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -R 3,4,7 -E 0 |
|
||||
column -t -s "$(printf '\t')" -R 3,4,7 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
if [ "${rectmp:-}" ] && [ -f "$rectmp" ]; then
|
||||
rm -f "$rectmp"
|
||||
@@ -198,7 +199,7 @@ list_artists_from_json() {
|
||||
-v format_disambiguation="$AV_DISAMBIGUATION" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_ARTISTS" |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
column -t -s "$(printf '\t')" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
@@ -228,7 +229,7 @@ list_playlist() {
|
||||
-v current_id="$current_id" \
|
||||
"$AWK_RECORDINGS" |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -R 5 -E 0 |
|
||||
column -t -s "$(printf '\t')" -R 5 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
rm -f "$rectmp" "$mpvtmp"
|
||||
}
|
||||
|
@@ -173,7 +173,6 @@ precompute_view() {
|
||||
cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" |
|
||||
while IFS= read -r rid; do
|
||||
mb_release "$rid" | $JQ -r '[
|
||||
"0",
|
||||
.id,
|
||||
.status,
|
||||
.date,
|
||||
|
@@ -22,6 +22,14 @@ mpv_playlist_position() {
|
||||
__mpv_get '${playlist-pos}'
|
||||
}
|
||||
|
||||
mpv_playlist_move() {
|
||||
__mpv_command_with_args2 "playlist-move" "$1" "$2" >>/tmp/foo
|
||||
}
|
||||
|
||||
mpv_playlist_clear() {
|
||||
__mpv_command "playlist-clear"
|
||||
}
|
||||
|
||||
mpv_quit() {
|
||||
__mpv_command "quit"
|
||||
}
|
||||
@@ -32,10 +40,17 @@ mpv_start() {
|
||||
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
|
||||
}
|
||||
|
||||
mpv_play_index() {
|
||||
__mpv_command_with_arg "playlist-play-index" "$1"
|
||||
}
|
||||
|
||||
mpv_rm_index() {
|
||||
__mpv_command_with_arg "playlist-remove" "$1"
|
||||
}
|
||||
|
||||
mpv_play_list() {
|
||||
t=$(mktemp)
|
||||
cat >"$t"
|
||||
debug "Playing $(cat "$t")"
|
||||
__mpv_command_with_arg "loadlist" "$t"
|
||||
rm -f "$t"
|
||||
}
|
||||
@@ -47,6 +62,22 @@ mpv_queue_list() {
|
||||
rm -f "$t"
|
||||
}
|
||||
|
||||
mpv_queue_next_list() {
|
||||
t=$(mktemp)
|
||||
cat >"$t"
|
||||
pos=$(mpv_playlist_position)
|
||||
cnt1=$(mpv_playlist_count)
|
||||
__mpv_command_with_args2 "loadlist" "$t" "append-play"
|
||||
rm -f "$t"
|
||||
cnt2=$(mpv_playlist_count)
|
||||
diff=$((cnt2 - cnt1))
|
||||
[ "$diff" -gt 0 ] || return
|
||||
# Move added items right after current item (numbers are 0 based)
|
||||
for i in $(seq "$diff"); do
|
||||
mpv_playlist_move $((cnt1 + i - 1)) $((pos + i))
|
||||
done
|
||||
}
|
||||
|
||||
mpv_next() {
|
||||
__mpv_command "playlist-next"
|
||||
}
|
||||
|
31
src/sh/playback.sh
Normal file
31
src/sh/playback.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
# Available playback commands
|
||||
PLAYBACK_CMD_PLAY="play"
|
||||
PLAYBACK_CMD_QUEUE="queue"
|
||||
PLAYBACK_CMD_QUEUE_NEXT="queue-next"
|
||||
PLAYBACK_CMD_TOGGLE_PLAYBACK="toggle"
|
||||
PLAYBACK_CMD_PLAY_NEXT="next"
|
||||
PLAYBACK_CMD_PLAY_PREV="prev"
|
||||
PLAYBACK_CMD_SEEK_FORWARD="seekf"
|
||||
PLAYBACK_CMD_SEEK_BACKWARD="seekb"
|
||||
|
||||
# Obtain playback command from key press
|
||||
# @argument $1: key
|
||||
playback_cmd_from_key() {
|
||||
key=$1
|
||||
case ",$KEYS_PLAY," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY" && return ;; esac
|
||||
case ",$KEYS_N_PLAY," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY" && return ;; esac
|
||||
case ",$KEYS_QUEUE," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE" && return ;; esac
|
||||
case ",$KEYS_N_QUEUE," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE" && return ;; esac
|
||||
case ",$KEYS_QUEUE_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE_NEXT" && return ;; esac
|
||||
case ",$KEYS_N_QUEUE_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE_NEXT" && return ;; esac
|
||||
case ",$KEYS_TOGGLE_PLAYBACK," in *",$key,"*) echo "$PLAYBACK_CMD_TOGGLE_PLAYBACK" && return ;; esac
|
||||
case ",$KEYS_N_TOGGLE_PLAYBACK," in *",$key,"*) echo "$PLAYBACK_CMD_TOGGLE_PLAYBACK" && return ;; esac
|
||||
case ",$KEYS_PLAY_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_NEXT" && return ;; esac
|
||||
case ",$KEYS_N_PLAY_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_NEXT" && return ;; esac
|
||||
case ",$KEYS_PLAY_PREV," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_PREV" && return ;; esac
|
||||
case ",$KEYS_N_PLAY_PREV," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_PREV" && return ;; esac
|
||||
case ",$KEYS_SEEK_FORWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_FORWARD" && return ;; esac
|
||||
case ",$KEYS_N_SEEK_FORWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_FORWARD" && return ;; esac
|
||||
case ",$KEYS_SEEK_BACKWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_BACKWARD" && return ;; esac
|
||||
case ",$KEYS_N_SEEK_BACKWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_BACKWARD" && return ;; esac
|
||||
}
|
6
src/sh/playlist.sh
Normal file
6
src/sh/playlist.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
PLAYLIST_CMD_REMOVE="rm"
|
||||
PLAYLIST_CMD_UP="up"
|
||||
PLAYLIST_CMD_DOWN="down"
|
||||
PLAYLIST_CMD_CLEAR="clear"
|
||||
PLAYLIST_CMD_CLEAR_ABOVE="clear-above"
|
||||
PLAYLIST_CMD_CLEAR_BELOW="clear-below"
|
@@ -132,21 +132,3 @@ FORMAT_STATUS_CANCELLED="${FORMAT_STATUS_CANCELLED:-"❌"}"
|
||||
REC_FORMAT="${REC_FORMAT:-"${CNOTE}${FAINT}<<med>>\t${CNOTE}<<nr>>$OFF\t${CTITLE}<<title>>\t${CARTIST}<<artist>>\t${CXXX}<<duration>>$OFF"}"
|
||||
# Format of a track in the playlist
|
||||
REC_FORMAT_NO_NUMBER="${REC_FORMAT_NO_NUMBER:-"${CTITLE}<<title>>\t${CARTIST}<<artist>>\t${CXXX}<<duration>>$OFF"}"
|
||||
|
||||
# Derivatives
|
||||
# ===========
|
||||
QUERY_LOCAL=$(printf "%s" "$FORMAT_LOCAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_HAS_SECONDARY=$(printf "$FORMAT_TYPE_HAS_SECONDARY" "" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_ALBUM=$(printf "%s" "$FORMAT_TYPE_ALBUM" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_EP=$(printf "%s" "$FORMAT_TYPE_EP" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_SINGLE=$(printf "%s" "$FORMAT_TYPE_SINGLE" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_BROADCAST=$(printf "%s" "$FORMAT_TYPE_BROADCAST" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_OTHER=$(printf "%s" "$FORMAT_TYPE_OTHER" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
if printf "$RV_FORMAT" | grep -q "<<status>>"; then
|
||||
QUERY_RV=$(printf "%s" "$FORMAT_STATUS_OFFICIAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
else
|
||||
QUERY_RV=""
|
||||
fi
|
||||
|
||||
# Necessary exports
|
||||
export QUERY_LOCAL QUERY_HAS_SECONDARY QUERY_ALBUM QUERY_EP QUERY_SINGLE QUERY_BROADCAST QUERY_OTHER QUERY_RV
|
||||
|
Reference in New Issue
Block a user