ptgdp: Define function for line validation
This commit is contained in:
21
ptgdp
21
ptgdp
@@ -133,6 +133,14 @@ validatedeps() {
|
|||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
validateline() {
|
||||||
|
# $1: A line to check for comments or whitespace
|
||||||
|
local linenows=${1//[[:space:]]}
|
||||||
|
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
sanitize() {
|
sanitize() {
|
||||||
[ -z "$1" ] && return 1 # String to strip special chars from
|
[ -z "$1" ] && return 1 # String to strip special chars from
|
||||||
_return="${1//[^ a-zA-Z0-9\[\]|()_-]/}"
|
_return="${1//[^ a-zA-Z0-9\[\]|()_-]/}"
|
||||||
@@ -230,22 +238,13 @@ playlist() {
|
|||||||
while read line; do
|
while read line; do
|
||||||
# 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=${line//[[:space:]]}
|
validateline "$line" || continue
|
||||||
if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
unset linenows
|
|
||||||
maxlines+=1
|
maxlines+=1
|
||||||
done < "$1"
|
done < "$1"
|
||||||
log "Enqueued playlist with $maxlines lines"
|
log "Enqueued playlist with $maxlines lines"
|
||||||
while read line; do
|
while read line; do
|
||||||
[ -z "$line" ] && continue
|
[ -z "$line" ] && continue
|
||||||
# Ignore comments and blank lines
|
validateline "$line" || continue
|
||||||
local linenows=${line//[[:space:]]}
|
|
||||||
if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
unset linenows
|
|
||||||
rm "$_tmpfile"* > /dev/null 2>&1
|
rm "$_tmpfile"* > /dev/null 2>&1
|
||||||
# Do the do
|
# Do the do
|
||||||
cachesong "$line"
|
cachesong "$line"
|
||||||
|
Reference in New Issue
Block a user