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