playback controls
This commit is contained in:
51
src/main.sh
51
src/main.sh
@@ -33,6 +33,9 @@ MODE_INSERT="show"
|
|||||||
# Load filters
|
# Load filters
|
||||||
. "sh/filter.sh"
|
. "sh/filter.sh"
|
||||||
|
|
||||||
|
# Load playback helper
|
||||||
|
. "sh/playback.sh"
|
||||||
|
|
||||||
# Load AWK scripts
|
# Load AWK scripts
|
||||||
. "sh/awk.sh"
|
. "sh/awk.sh"
|
||||||
|
|
||||||
@@ -90,7 +93,46 @@ case "${1:-}" in
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"--playback")
|
"--playback")
|
||||||
debug "NOT IMPLEMENTED"
|
view=${2:-}
|
||||||
|
mbid_current="${3:-}"
|
||||||
|
mbid="${4:-}"
|
||||||
|
path="${5:-}"
|
||||||
|
debug "call to $*"
|
||||||
|
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") generate_playlist "$mbid_current" "$path" "$mbid" | mpv_play_list >/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
|
exit 0
|
||||||
;;
|
;;
|
||||||
"--filter")
|
"--filter")
|
||||||
@@ -423,10 +465,11 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
|
|||||||
--border-label=" Playlist " \
|
--border-label=" Playlist " \
|
||||||
--no-input \
|
--no-input \
|
||||||
--margin="2%,10%" \
|
--margin="2%,10%" \
|
||||||
--bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
|
||||||
--bind="r,ctrl-r:reload:$0 --playlist" \
|
--bind="r,ctrl-r:reload:$0 --playlist" \
|
||||||
|
--bind="q:accept" \
|
||||||
--delimiter="\t" \
|
--delimiter="\t" \
|
||||||
--with-nth="{1}" >/dev/null
|
--with-nth="{1}" >/dev/null
|
||||||
|
VIEW=""
|
||||||
;;
|
;;
|
||||||
"$VIEW_QUIT")
|
"$VIEW_QUIT")
|
||||||
debug "Quitting..."
|
debug "Quitting..."
|
||||||
@@ -500,8 +543,8 @@ open \"\$(dirname {4})\"" \
|
|||||||
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+accept" \
|
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+accept" \
|
||||||
--bind="$KEYS_QUIT:print($VIEW_QUIT)+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_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" \
|
--bind="$KEYS_PLAYBACK:transform:$0 --playback $FZF_CURRENT_VIEW {2} {3} {4}" \
|
||||||
--bind="$KEYS_N_PLAYBACK:transform:$IN_NORMAL_MODE && $0 --playback || $PUT_FZF_KEY_LOGIC" \
|
--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" \
|
--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-window="right,25%,border-left,wrap,<30(hidden)" \
|
||||||
--preview="$0 --preview-artist {3}" \
|
--preview="$0 --preview-artist {3}" \
|
||||||
|
@@ -117,17 +117,17 @@ KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
|
|||||||
|
|
||||||
# Playback:
|
# Playback:
|
||||||
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
||||||
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}"
|
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}" # That's actually alt-enter
|
||||||
KEYS_QUEUE_NEXT="${KEYS_QUEUE_NEXT:-"ctrl-alt-n"}"
|
KEYS_QUEUE_NEXT="${KEYS_QUEUE_NEXT:-"ctrl-alt-n"}"
|
||||||
KEYS_TOGGLE_PLAYBACK="${KEYS_TOGGLE_PLAYBACK:-"alt-space"}"
|
KEYS_TOGGLE_PLAYBACK="${KEYS_TOGGLE_PLAYBACK:-"ctrl-space"}"
|
||||||
KEYS_PLAY_NEXT="${KEYS_PLAY_NEXT:-"alt-right"}"
|
KEYS_PLAY_NEXT="${KEYS_PLAY_NEXT:-"alt-n"}"
|
||||||
KEYS_PLAY_PREV="${KEYS_PLAY_PREV:-"alt-left"}"
|
KEYS_PLAY_PREV="${KEYS_PLAY_PREV:-"alt-p"}"
|
||||||
KEYS_SEEK_FORWARD="${KEYS_SEEK_FORWARD:-"alt-shift-right,shift-right"}"
|
KEYS_SEEK_FORWARD="${KEYS_SEEK_FORWARD:-"alt-N"}"
|
||||||
KEYS_SEEK_BACKWARD="${KEYS_SEEK_BACKWARD:-"alt-shift-left,shift-left"}"
|
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_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_PLAY:-"."}"
|
KEYS_N_PLAY="${KEYS_N_PLAY:-"."}"
|
||||||
KEYS_N_QUEUE="${KEYS_QUEUE:-","}"
|
KEYS_N_QUEUE="${KEYS_N_QUEUE:-";"}"
|
||||||
KEYS_N_QUEUE_NEXT="${KEYS_QUEUE_NEXT:-";"}"
|
KEYS_N_QUEUE_NEXT="${KEYS_N_QUEUE_NEXT:-":"}"
|
||||||
KEYS_N_TOGGLE_PLAYBACK="${KEYS_N_TOGGLE_PLAYBACK:-"space"}"
|
KEYS_N_TOGGLE_PLAYBACK="${KEYS_N_TOGGLE_PLAYBACK:-"space"}"
|
||||||
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right,n"}"
|
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right,n"}"
|
||||||
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left,p"}"
|
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left,p"}"
|
||||||
|
@@ -22,6 +22,11 @@ mpv_playlist_position() {
|
|||||||
__mpv_get '${playlist-pos}'
|
__mpv_get '${playlist-pos}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpv_playlist_move() {
|
||||||
|
debug "moving $1 -> $2"
|
||||||
|
__mpv_command_with_args2 "playlist-move" "$1" "$2" >>/tmp/foo 2>/dev/stdout
|
||||||
|
}
|
||||||
|
|
||||||
mpv_quit() {
|
mpv_quit() {
|
||||||
__mpv_command "quit"
|
__mpv_command "quit"
|
||||||
}
|
}
|
||||||
@@ -47,6 +52,22 @@ mpv_queue_list() {
|
|||||||
rm -f "$t"
|
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_next() {
|
||||||
__mpv_command "playlist-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
|
||||||
|
}
|
Reference in New Issue
Block a user