feat: playlist store
This commit is contained in:
97
src/main.sh
97
src/main.sh
@@ -36,6 +36,8 @@ VIEW_LIST_ARTISTS="list-artists"
|
||||
VIEW_LIST_ALBUMS="list-albums"
|
||||
VIEW_SELECT_ARTIST="select-artist"
|
||||
VIEW_PLAYLIST="playlist"
|
||||
VIEW_PLAYLIST_PLAYLISTSTORE="playlist-list"
|
||||
VIEW_PLAYLIST_STORE="playlist-store"
|
||||
VIEW_QUIT="quit"
|
||||
MODE_NORMAL="hidden"
|
||||
MODE_INSERT="show"
|
||||
@@ -50,21 +52,24 @@ MODE_INSERT="show"
|
||||
# Load configuration
|
||||
. "sh/config.sh"
|
||||
|
||||
# Load mpv methods
|
||||
. "sh/mpv.sh"
|
||||
|
||||
# Load query methods
|
||||
. "sh/query.sh"
|
||||
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
# Load local file handling
|
||||
. "sh/local.sh"
|
||||
|
||||
# Load playlist tools
|
||||
. "sh/playlist.sh"
|
||||
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
|
||||
# Load MusicBrainz, Discogs, and wiki methods
|
||||
. "sh/api.sh"
|
||||
|
||||
# Load mpv methods
|
||||
. "sh/mpv.sh"
|
||||
|
||||
# Load preview methods
|
||||
. "sh/preview.sh"
|
||||
|
||||
@@ -74,9 +79,6 @@ MODE_INSERT="show"
|
||||
# Load MusicBrainz wrappers
|
||||
. "sh/mb.sh"
|
||||
|
||||
# Load local file handling
|
||||
. "sh/local.sh"
|
||||
|
||||
# Load list-generating methods
|
||||
. "sh/lists.sh"
|
||||
|
||||
@@ -419,6 +421,11 @@ case "${1:-}" in
|
||||
info "Done"
|
||||
exit 0
|
||||
;;
|
||||
"--playlists")
|
||||
# List available playlists
|
||||
stored_playlists
|
||||
exit 0
|
||||
;;
|
||||
"--help")
|
||||
# Print help string
|
||||
cat <<EOF
|
||||
@@ -433,6 +440,8 @@ GENERAL OPTIONS:
|
||||
--artist <mbid> List release groups of given artist <mbid>
|
||||
--releasegroup <mbid> List releases in given release group <mbid>
|
||||
--release <mbid> Show release given by <mbid>
|
||||
--playlists List stored playlists and exit
|
||||
--load-playlist <playlist> Load specified playlist
|
||||
|
||||
MANAGE LOCAL MUSIC:
|
||||
--decorate <path> Decorate directory containing a tagged release
|
||||
@@ -485,12 +494,22 @@ case "${1:-}" in
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
"--load-playlist")
|
||||
# We will load and play later
|
||||
VIEW="$VIEW_PLAYLIST"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
*)
|
||||
err "Unknown option $1 (see --help)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# For history purpose: previous view is always:
|
||||
LASTVIEW="$VIEW_LIST_ARTISTS"
|
||||
LASTARG=""
|
||||
|
||||
# Start application:
|
||||
# - set title
|
||||
# - check for missing data from MusicBrainz
|
||||
@@ -521,6 +540,9 @@ export LOCKFILE RESULTS PIDFILE
|
||||
# Start mpv
|
||||
mpv_start
|
||||
|
||||
# Playback possible now
|
||||
[ "${1:-}" = "--load-playlist" ] && $0 --playlist "$PLAYLIST_CMD_LOAD" "${2:-}"
|
||||
|
||||
# main loop
|
||||
# states are stored in (in)visible labels
|
||||
#
|
||||
@@ -594,6 +616,63 @@ while true; do
|
||||
LASTVIEW="$VIEW_SELECT_ARTIST"
|
||||
LASTARG="$ARGS"
|
||||
;;
|
||||
"$VIEW_PLAYLIST_STORE")
|
||||
VIEW="$VIEW_PLAYLIST"
|
||||
ARGS=""
|
||||
MBID=""
|
||||
tmpf=$(mktemp)
|
||||
list_playlist | cut -d "$(printf '\t')" -f "3,4" >"$tmpf"
|
||||
# Make sure we store only nonempty playlists
|
||||
[ -s "$tmpf" ] || continue
|
||||
while true; do
|
||||
infonn "Enter playlist name:"
|
||||
read -r playlistname
|
||||
[ "$playlistname" ] || continue
|
||||
case "$playlistname" in
|
||||
*[!a-zA-Z0-9._-]*)
|
||||
info "Please use only alaphnumeric symbols and any of \".-_\" for the playlist name."
|
||||
;;
|
||||
*)
|
||||
f="$PLAYLIST_DIRECTORY/$playlistname"
|
||||
if [ -s "$f" ]; then
|
||||
while true; do
|
||||
infonn "Playlist with name \"$playlistname\" already exists. Do you want to overwrite it? (yes/no)"
|
||||
read -r yn
|
||||
case $yn in
|
||||
"yes" | "no") break ;;
|
||||
*) info "Please answer \"yes\" or \"no\"." ;;
|
||||
esac
|
||||
done
|
||||
[ "$yn" = "yes" ] || continue
|
||||
fi
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
mv "$tmpf" "$f"
|
||||
;;
|
||||
"$VIEW_PLAYLIST_PLAYLISTSTORE")
|
||||
sel=$(
|
||||
stored_playlists | $FZF \
|
||||
--border=double \
|
||||
--border-label="$TITLE_PLYLST_LIST" \
|
||||
--margin="2%,10%" \
|
||||
--bind="$KEYS_I_NORMAL:" \
|
||||
--bind="$KEYS_DOWN:down" \
|
||||
--bind="$KEYS_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="$KEYS_OUT,$KEYS_QUIT:accept" \
|
||||
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $VIEW_PLAYLIST_PLAYLISTSTORE" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
|
||||
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
|
||||
--bind="$KEYS_PLAYLISTSTORE_SELECT:transform:[ {1} ] && $0 --playlist $PLAYLIST_CMD_LOAD {1} && echo accept" \
|
||||
--bind="$KEYS_PLAYLISTSTORE_DELETE:transform:[ {1} ] && rm \"$PLAYLIST_DIRECTORY/{r1}\" && echo \"reload($0 --playlists\)\"" \
|
||||
--wrap-sign="" || true
|
||||
)
|
||||
VIEW="$VIEW_PLAYLIST"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
sel=$(
|
||||
list_playlist | $FZF \
|
||||
@@ -637,6 +716,8 @@ while true; do
|
||||
--bind="$KEYS_PLAYLIST_SHUFFLE:execute-silent($0 --playlist $PLAYLIST_CMD_SHUFFLE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_UNSHUFFLE:execute-silent($0 --playlist $PLAYLIST_CMD_UNSHUFFLE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_GOTO_RELEASE:print($VIEW_RELEASE)+accept" \
|
||||
--bind="$KEYS_PLAYLIST_STORE:print($VIEW_PLAYLIST_STORE)+print("")+print($LASTVIEW)+print($LASTARG)+accept" \
|
||||
--bind="$KEYS_PLAYLIST_OPEN_STORE:print($VIEW_PLAYLIST_PLAYLISTSTORE)+print("")+print($LASTVIEW)+print($LASTARG)+accept" \
|
||||
--preview-window="hidden" \
|
||||
--wrap-sign="" \
|
||||
--delimiter="\t" \
|
||||
|
||||
Reference in New Issue
Block a user