diff --git a/ptgdp b/ptgdp index d99ff55..e80d9fb 100755 --- a/ptgdp +++ b/ptgdp @@ -13,6 +13,7 @@ _name="$(basename -- "$0")" _tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/$_name" _tmpfile="$_tmpdir/tmpfile-$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 12)" +_tmpplaylist="$_tmpdir/tmpplaylist-$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 12)" _xdguserdirs="${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" [ -z "$XDG_MUSIC_DIR" ] && [ -f "$_xdguserdirs" ] && source "$_xdguserdirs" _musicdir="${XDG_MUSIC_DIR:-$HOME/Music}" @@ -217,6 +218,12 @@ execqueue() { } execplaylists() { # Plays all playlists in _playlists + if [ -n "$_optquickplay" ]; then + for line in "${_playlists[@]}"; do + printf "%s\\n" "$line" >> "$_tmpplaylist" + done + _playlists=("$_tmpplaylist") + fi for list in "${_playlists[@]}"; do playlist "$list" || error "Failed to play playlist: \"$list\"" done @@ -272,6 +279,7 @@ sanitize() { trapexit() { kill $(jobs -p) > /dev/null 2>&1 [ -n "$_tmpdir" ] && rm "$_tmpfile"* > /dev/null 2>&1 + [ -f "$_tmpplaylist" ] && rm "$_tmpplaylist" > /dev/null 2>&1 } # Critical functions @@ -290,6 +298,9 @@ given plaintext FILEs with only search queries. -D Dry run; parse out all songs, downloaded or not, and print out the resolved names -p Play the playlist after it is enqueued + -q Interpret all arguments as songs, not playlists. A + temporary playlist will be created with all arguments + and executed as normal -s Shuffle the playlist before enqueueing -r Start up rofi, if installed, and present a listing of all .gdp files in the given directory. If notify-send @@ -399,7 +410,7 @@ playlist() { validateline "$line" || continue maxlines+=1 done < "$1" - log "Parsed playlist \"$1\" with $maxlines songs" + [ -z "$_optquickplay" ] && log "Parsed playlist \"$1\" with $maxlines songs" # Store old preprocessor settings declare -a oldsettings while read var; do @@ -434,7 +445,13 @@ playlist() { continue ;; esac - done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi) + done < <( + if [ -n "$_optshuffle" ]; then + shuf "$1" + else + cat "$1" + fi + ) # Return to normality for var in "${oldsettings[@]}"; do eval "$var" @@ -472,7 +489,7 @@ main() { trap trapexit EXIT # Get options - while getopts ":cdDf:pr:R:sh" opt; do + while getopts ":cdDf:pqr:R:sh" opt; do case $opt in c) clearcache @@ -487,6 +504,9 @@ main() { p) _optautoplay=1 ;; + q) + _optquickplay=1 + ;; r) _optrofi="$OPTARG" ;; @@ -512,7 +532,7 @@ main() { # Get program arguments (playlists) shift $((OPTIND - 1)) for list in "$@"; do - if ! [ -f "$list" ]; then + if ! [ -f "$list" ] && [ -z "$_optquickplay" ]; then error "Failed to find playlist: $list" continue fi