From afcb98e06bf620cb5a8084e4c20d0ff6b0516711 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Wed, 14 Aug 2019 04:31:57 -0500
Subject: [PATCH] ptgdp: Figure out how many songs we need to grab

---
 ptgdp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/ptgdp b/ptgdp
index 5a9a744..24b8148 100755
--- a/ptgdp
+++ b/ptgdp
@@ -226,12 +226,26 @@ playlist() {
 	local -i dlexist=0
 	local -i dlsuccess=0
 	local -i dlfailure=0
+	local -i maxlines=0
 	while read line; do
-		[ -z "$line" ] && continue
-		# Ignore comment lines
-		if ! [ "${line#\#}" = "$line" ]; then
+		# Strictly speaking, this removes all whitespace from the line
+		# While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines
+		local linenows=${line//[[:space:]]}
+		if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
 			continue
 		fi
+		unset linenows
+		maxlines+=1
+	done < "$1"
+	log "Enqueued playlist with $maxlines lines"
+	while read line; do
+		[ -z "$line" ] && continue
+		# Ignore comments and blank lines
+		local linenows=${line//[[:space:]]}
+		if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
+			continue
+		fi
+		unset linenows
 		rm "$_tmpfile"* > /dev/null 2>&1
 		# Do the do
 		cachesong "$line"