ptgdp: Implement barebones preprocessor commands

Now to put them to use
This commit is contained in:
2019-09-13 21:25:18 -05:00
parent ae55cb3ce3
commit 06712e971b

24
ptgdp
View File

@@ -50,6 +50,12 @@ notify() {
"$1" \ "$1" \
"$2" > /dev/null 2>&1 "$2" > /dev/null 2>&1
} }
execpreprocessor() {
# Execute a preprocessor line
# $1: The line, either stripped or not of the leading #:
line="${1#\#:}"
log "pp: $line"
}
checkforsong() { checkforsong() {
# $1: A song name to validate # $1: A song name to validate
[ -z "$1" ] && return 1 [ -z "$1" ] && return 1
@@ -209,6 +215,11 @@ validateline() {
# Strictly speaking, this removes all whitespace from the line # Strictly speaking, this removes all whitespace from the line
# While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines # While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines
local linenows=${1//[[:space:]]} local linenows=${1//[[:space:]]}
# Preprocessor commands
if ! [ "${1#\#:}" = "$1" ]; then
return 100
fi
# Comments and whitespace-only lines
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
return 1 return 1
fi fi
@@ -355,8 +366,9 @@ playlist() {
done < "$1" done < "$1"
log "Parsed playlist \"$1\" with $maxlines songs" log "Parsed playlist \"$1\" with $maxlines songs"
while read line; do while read line; do
[ -z "$line" ] && continue validateline "$line"
validateline "$line" || continue case $? in
0)
rm "$_tmpfile"* > /dev/null 2>&1 rm "$_tmpfile"* > /dev/null 2>&1
# Do the do # Do the do
queuesong "$line" queuesong "$line"
@@ -373,6 +385,14 @@ playlist() {
dlfailure+=1 dlfailure+=1
;; ;;
esac esac
;;
100)
execpreprocessor "$line"
;;
*)
continue
;;
esac
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi) done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
if [ "$dlexist" = "0" ] && [ "$dlsuccess" = "0" ] && [ -z "$_optdryrun" ]; then if [ "$dlexist" = "0" ] && [ "$dlsuccess" = "0" ] && [ -z "$_optdryrun" ]; then
notify "Failed to download playlist" \ notify "Failed to download playlist" \