From 0c4b8fa378be8b81f0532e8194ddd56c79df8338 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Fri, 18 Oct 2019 23:32:04 -0500
Subject: [PATCH] Add support for piping a playlist in through STDIN

---
 ptgdp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ptgdp b/ptgdp
index 84ffc9c..e90cf3d 100755
--- a/ptgdp
+++ b/ptgdp
@@ -290,13 +290,8 @@ playlist() {
 	local -i totallines=0
 	while read line; do
 		totallines+=1
-		validateline "$line" || continue
-		goodlines+=1
-	done < "$1"
-	log "Parsed playlist \"$1\" with $goodlines songs"
-	log "Playlist has $totallines total lines" 2
-	while read line; do
 		if validateline "$line"; then
+			goodlines+=1
 			queuesong "$line" || error "Failed to enqueue song: \"$line\""
 			case $_returnstatus in
 				dl)
@@ -321,6 +316,7 @@ playlist() {
 		backend-execqueue
 	fi
 	log "Finished: $dlcache cached, $dlsuccess downloaded, $dlerr failed"
+	log "Playlist has $totallines total lines, $goodlines of them songs" 1
 }
 
 # Main
@@ -404,9 +400,13 @@ main() {
 		error "Failed to find program: $_return" 1
 	fi
 	if [ -n "${_args[*]}" ]; then
+		# Files specified on the command line have priority
 		for arg in "${_args[@]}"; do
 			playlist "$arg"
 		done
+	elif ! [ -t 0 ]; then
+		# If there are none of those, read from STDIN
+		playlist "/dev/stdin"
 	else
 		warn "Nothing to do"
 		exit 0