shithub: zuke

Download patch

ref: 811526f2abc5687de350ec4df3bd1588ef9a9ab3
parent: a7982edeb51aa586ed782996ef6aee52e6f1fba0
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 26 17:46:18 EST 2016

fall back to [Cc]over.jpg

--- a/zuke.c
+++ b/zuke.c
@@ -209,7 +209,7 @@
 coverload(void *player_)
 {
 	int p[2], pid, fd;
-	char *prog;
+	char *prog, *path, *s;
 	Meta *m;
 	Channel *ch;
 	Player *player;
@@ -220,6 +220,7 @@
 	m = &pl[player->pcur];
 	pid = -1;
 	ch = player->img;
+	fd = -1;
 
 	if(m->imagefmt == nil || m->imagereader != 0)
 		goto done;
@@ -227,13 +228,29 @@
 		prog = "png -9t | resize -x128";
 	else if(strcmp(m->imagefmt, "image/jpeg") == 0)
 		prog = "jpg -9t | resize -x128";
-	else
-		goto done;
+	else{
+		path = strdup(m->path);
+		prog = "jpg -9t | resize -x128";
+		if(path != nil && (s = utfrrune(path, '/')) != nil){
+			*s = 0;
+			if((s = smprint("%s/cover.jpg", path)) != nil && (fd = open(s, OREAD)) < 0){
+				free(s);
+				if((s = smprint("%s/Cover.jpg", path)) != nil)
+					fd = open(s, OREAD);
+			}
+			free(s);
+		}
+		free(path);
+		if(fd < 0)
+			goto done;
+	}
 
-	pipe(p);
-	if((pid = rfork(RFPROC|RFFDG|RFREND|RFNOTEG)) == 0){
+	if(fd < 0){
 		fd = open(m->path, OREAD);
 		seek(fd, m->imageoffset, 0);
+	}
+	pipe(p);
+	if((pid = rfork(RFPROC|RFFDG|RFREND|RFNOTEG)) == 0){
 		dup(fd, 0); close(fd);
 		dup(p[1], 1); close(p[1]);
 		close(2);
@@ -240,6 +257,7 @@
 		execl("/bin/rc", "rc", "-c", prog, nil);
 		sysfatal("execl: %r");
 	}
+	close(fd);
 	close(p[1]);
 
 	if(pid > 0){