From 44708588eec604f8ff8a2d7fe6ec73b6f972927a Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Fri, 27 Sep 2019 21:58:44 -0500
Subject: [PATCH] Fix queueing up files, validate files (loosely) before
 continuing

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

diff --git a/ptgdp b/ptgdp
index ea30cab..84ffc9c 100755
--- a/ptgdp
+++ b/ptgdp
@@ -125,7 +125,16 @@ cachesong() {
 			"$1")
 		then
 			# Sanitize removes all periods, so this is safe
-			_return="$filename".*
+			for file in "$filename".*; do
+				if [ -f "$file" ]; then
+					_return="$file"
+				else
+					error "Downloaded song \"$_return\" but could not find output file"
+					log "$ytdllog" 2
+					_returnstatus="err"
+					return 1
+				fi
+			done
 			_returnstatus="dl"
 			log "Downloaded song to \"$_return\"" 2
 			log "$ytdllog" 2
@@ -202,7 +211,8 @@ backend-enqueue() { # Enqueues a song
 		mpd)
 			file=${1##$_mpdroot/}
 			if ! mpc add "$file" > /dev/null 2>&1; then
-				error "Could not add file: \"$file\" ($?)"
+				errorval="$?"
+				error "Could not add file: \"$file\" ($errorval)"
 			fi
 			return 0
 			;;