some playlist controls
This commit is contained in:
71
src/main.sh
71
src/main.sh
@@ -36,6 +36,9 @@ MODE_INSERT="show"
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
|
||||
# Load playlist tools
|
||||
. "sh/playlist.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
@@ -97,7 +100,6 @@ case "${1:-}" in
|
||||
mbid_current="${3:-}"
|
||||
mbid="${4:-}"
|
||||
path="${5:-}"
|
||||
debug "call to $*"
|
||||
pbcmd=$(playback_cmd_from_key "$FZF_KEY")
|
||||
case "$pbcmd" in
|
||||
"$PLAYBACK_CMD_PLAY")
|
||||
@@ -106,7 +108,7 @@ case "${1:-}" 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") 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")
|
||||
@@ -152,9 +154,13 @@ case "${1:-}" in
|
||||
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") j="$(mb_release "$mbid_cur" | $JQ -r --compact-output ".media | map(.tracks) | flatten[] | select(.id == \"$mbid\") | .\"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')"
|
||||
@@ -163,7 +169,6 @@ case "${1:-}" in
|
||||
exit 0
|
||||
;;
|
||||
"--draw")
|
||||
debug "call to $*"
|
||||
# Generate fzf command to draw screen.
|
||||
#
|
||||
# @argument $2: mode (default `normal`)
|
||||
@@ -304,6 +309,27 @@ case "${1:-}" in
|
||||
__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
|
||||
@@ -457,19 +483,42 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
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="r,ctrl-r:reload:$0 --playlist" \
|
||||
--bind="q:accept" \
|
||||
--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:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_RELOAD:reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_REMOVE:execute-silent($0 --playlistcmd $PLAYLIST_CMD_REMOVE)+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_UP:execute-silent($0 --playlistcmd $PLAYLIST_CMD_UP)+up+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_DOWN:execute-silent($0 --playlistcmd $PLAYLIST_CMD_DOWN)+down+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR)+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_ABOVE:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_ABOVE)+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_BELOW:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_BELOW)+reload:$0 --playlist" \
|
||||
--bind="$KEYS_PLAYLIST_QUIT:print($VIEW_LIST_ARTISTS)+accept" \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{1}" >/dev/null
|
||||
VIEW=""
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
ARGS="$(echo "$sel" | head -2 | tail -1)"
|
||||
debug "playlist terminated: view=$VIEW, ARGS=$ARGS"
|
||||
;;
|
||||
"$VIEW_QUIT")
|
||||
debug "Quitting..."
|
||||
|
Reference in New Issue
Block a user