cleaned up
This commit is contained in:
167
src/main.sh
167
src/main.sh
@@ -40,23 +40,15 @@ VIEW_QUIT="quit"
|
||||
MODE_NORMAL="hidden"
|
||||
MODE_INSERT="show"
|
||||
|
||||
# Load helper methods
|
||||
# Methods and variables used in main instance and subprocesses
|
||||
# Load application information
|
||||
. "sh/info.sh"
|
||||
|
||||
# Load helper methods
|
||||
. "sh/helper.sh"
|
||||
# Load logging methods
|
||||
. "sh/log.sh"
|
||||
|
||||
# Load configuration
|
||||
. "sh/config.sh"
|
||||
|
||||
# Load theme
|
||||
. "sh/theme.sh"
|
||||
|
||||
# Load keys
|
||||
. "sh/keys.sh"
|
||||
|
||||
# Load filters
|
||||
. "sh/filter.sh"
|
||||
# Load query methods
|
||||
. "sh/query.sh"
|
||||
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
@@ -64,12 +56,6 @@ MODE_INSERT="show"
|
||||
# Load playlist tools
|
||||
. "sh/playlist.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
# Load tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
# Load MusicBrainz and Discogs methods
|
||||
. "sh/api.sh"
|
||||
|
||||
@@ -129,82 +115,22 @@ case "${1:-}" in
|
||||
exit 0
|
||||
;;
|
||||
"--playback")
|
||||
# Control mpv instance
|
||||
# Control mpv instance (see `src/sh/playback.sh`)
|
||||
#
|
||||
# @argument $2: view
|
||||
# @argument $3: MusicBrainz ID of current object
|
||||
# @argument $4: MusicBrainz ID of selected object
|
||||
# @argument $5: Path to decoration file
|
||||
#
|
||||
# This option controls the mpv instance via a key pressed in fzf. The key
|
||||
# pressed is stored in the environment variable FZF_KEY and is resolved to
|
||||
# the playback command through the method `playback_cmd_from_key` (see
|
||||
# `src/sh/playback.sh` for a description of all playback commands).
|
||||
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
|
||||
shift
|
||||
playback "$@"
|
||||
exit 0
|
||||
;;
|
||||
"--playlist")
|
||||
# Run playback commands
|
||||
# Run playback commands (see `src/sh/playlits.sh`)
|
||||
#
|
||||
# @argument $2: playback command (see `src/sh/playback.sh`)
|
||||
#
|
||||
# This is a wrapper to execute mpv commands.
|
||||
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
|
||||
# @argument $2: playlist command
|
||||
shift
|
||||
playlist "$@"
|
||||
exit 0
|
||||
;;
|
||||
"--action-playlistcursor")
|
||||
@@ -254,9 +180,9 @@ case "${1:-}" in
|
||||
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_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") j="$(mb_releasegroup "$mbid" | $JQ '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASEGROUP") j="$(mb_release "$mbid" | $JQ '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASE" | "$VIEW_PLAYLIST") j="$(mb_release "$mbid_cur" | $JQ ".media | map(.tracks) | flatten[] | select(.id == \"$mbid\") | .\"artist-credit\"")" ;;
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") aid="$mbid" ;;
|
||||
esac
|
||||
if [ "$view" = "$VIEW_PLAYLIST" ]; then
|
||||
@@ -265,7 +191,7 @@ case "${1:-}" in
|
||||
fi
|
||||
if [ "${j:-}" ]; then
|
||||
cnt=$(echo "$j" | $JQ 'length')
|
||||
[ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ -r '.[0].artist.id')"
|
||||
[ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ '.[0].artist.id')"
|
||||
fi
|
||||
[ "${aid:-}" ] && $0 --action-draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur"
|
||||
exit 0
|
||||
@@ -322,11 +248,11 @@ case "${1:-}" in
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
view="$VIEW_ARTIST"
|
||||
mbid="$(mb_releasegroup "$mbid" | $JQ -r --compact-output '."artist-credit"[0].artist.id')"
|
||||
mbid="$(mb_releasegroup "$mbid" | $JQ '."artist-credit"[0].artist.id')"
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
view="$VIEW_RELEASEGROUP"
|
||||
mbid="$(mb_release "$mbid" | $JQ -r --compact-output '."release-group".id')"
|
||||
mbid="$(mb_release "$mbid" | $JQ '."release-group".id')"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
@@ -501,10 +427,39 @@ case "${1:-}" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# Start application: Set title, get temporary directory, start mpv daemon, and
|
||||
# enter main fzf loop.
|
||||
# Start application:
|
||||
# - load configuration
|
||||
# - load and export theme
|
||||
# - load and export preset filters
|
||||
# - load and export keys
|
||||
# - load and export tools
|
||||
# - load and export awk scripts
|
||||
# - set title
|
||||
# - get temporary directory for temporary files
|
||||
# - start mpv daemon
|
||||
# - enter main loop and start fzf
|
||||
|
||||
# Load configuration
|
||||
. "sh/config.sh"
|
||||
|
||||
# Load theme
|
||||
. "sh/theme.sh"
|
||||
|
||||
# Load filters
|
||||
. "sh/filter.sh"
|
||||
|
||||
# Load keys
|
||||
. "sh/keys.sh"
|
||||
|
||||
# Load tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
# Set window title
|
||||
printf '\033]0;%s\007' "$WINDOW_TITLE"
|
||||
|
||||
# Generate filenames for temporary files
|
||||
tmpdir=$(mktemp -d)
|
||||
LOCKFILE="$tmpdir/lock"
|
||||
@@ -512,6 +467,7 @@ RESULTS="$tmpdir/results"
|
||||
PIDFILE="$tmpdir/pid"
|
||||
trap 'rm -rf "$tmpdir"' EXIT INT
|
||||
export LOCKFILE RESULTS PIDFILE
|
||||
|
||||
# Start mpv
|
||||
mpv_start
|
||||
|
||||
@@ -541,6 +497,8 @@ PUT_FZF_KEY_LOGIC="case \$FZF_KEY in space) echo \"put( )\";; left) echo backwar
|
||||
while true; do
|
||||
case "$VIEW" in
|
||||
"$VIEW_SELECT_ARTIST")
|
||||
info "SELECT ARTIST VIEW with ARGS=$ARGS"
|
||||
info "$(echo "$ARGS" | list_artists_from_json)"
|
||||
sel=$(
|
||||
echo "$ARGS" | list_artists_from_json | $FZF \
|
||||
--bind="$KEYS_DOWN:down" \
|
||||
@@ -548,13 +506,13 @@ while true; do
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="enter,$KEYS_IN:print($VIEW_ARTIST)+accept" \
|
||||
--bind="$KEYS_OUT,$KEYS_QUIT:print($LASTVIEW)+print($LASTARG)+print($VIEW_SELECT_ARTIST)+print($ARGS)+accept" \
|
||||
--bind="$KEYS_OUT,$KEYS_QUIT:print($LASTVIEW)+print($LASTARG)+accept" \
|
||||
--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/artist/{r3}\"" \
|
||||
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+print()+print($VIEW_SELECT_ARTIST)+print($ARGS)+accept" \
|
||||
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+print()+accept" \
|
||||
-0 -1 \
|
||||
--border="bold" \
|
||||
--border-label="Select artist" \
|
||||
@@ -565,11 +523,16 @@ while true; do
|
||||
--accept-nth="{3}" \
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
debug "$sel"
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
MBID="$(echo "$sel" | head -2 | tail -1)"
|
||||
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
|
||||
LASTARG="$(echo "$sel" | head -4 | tail -1)"
|
||||
lines=$(echo "$sel" | wc -l)
|
||||
if [ "$lines" -eq 1 ]; then
|
||||
VIEW="$VIEW_ARTIST"
|
||||
MBID="$sel"
|
||||
else
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
MBID="$(echo "$sel" | head -2 | tail -1)"
|
||||
fi
|
||||
LASTVIEW="$VIEW_SELECT_ARTIST"
|
||||
LASTARG="$ARGS"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
sel=$(
|
||||
|
Reference in New Issue
Block a user