shithub: zuke

Download patch

ref: f0d9d0399f0923caae9adb54c93200ac72e3588f
parent: 26490a3fc445034d1de7505d50594d1d026190e1
author: Sigrid Haflínudóttir <[email protected]>
date: Sat May 23 15:25:12 EDT 2020

use a specific decoder directly, bypassing /bin/play

--- a/mkplist.c
+++ b/mkplist.c
@@ -19,6 +19,13 @@
 static int firstiscomposer;
 static int keepfirstartist;
 
+static char *fmts[] = {
+	[Fmp3] = "mp3",
+	[Fogg] = "ogg",
+	[Fflac] = "flac",
+	[Fm4a] = "m4a",
+};
+
 static Meta *
 newmeta(void)
 {
@@ -122,7 +129,7 @@
 	char *path, *s;
 	Dir *buf, *d;
 	long n;
-	int dirfd, len, flen;
+	int dirfd, len, res;
 
 	if((dirfd = open(*dir, OREAD)) < 0)
 		sysfatal("%s: %r", *dir);
@@ -144,16 +151,6 @@
 			if(strcmp(d->name, ".") == 0 || strcmp(d->name, "..") == 0)
 				continue;
 
-			if((d->mode & DMDIR) == 0){ /* if it's a regular file, apply filter */
-				if((flen = strlen(d->name)) < 5)
-					continue;
-				if(strcmp(&d->name[flen-4], ".mp3") != 0 &&
-				   strcmp(&d->name[flen-4], ".ogg") != 0 &&
-				   strcmp(&d->name[flen-5], ".flac") != 0){
-					continue;
-				}
-			}
-
 			path[len+1+Maxname-2] = 0;
 			strncpy(&path[len+1], d->name, Maxname);
 			if(path[len+1+Maxname-2] != 0)
@@ -160,15 +157,21 @@
 				sysfatal("Maxname=%d was a bad choice", Maxname);
 
 			if((d->mode & DMDIR) == 0){
-				ctx.filename = path;
 				if((bf = Bopen(path, OREAD)) == nil)
 					fprint(2, "%s: %r\n", path);
-				else if((curr = newmeta()) == nil)
-					sysfatal("no memory");
 				else{
+					if((curr = newmeta()) == nil)
+						sysfatal("no memory");
 					firstiscomposer = keepfirstartist = 0;
-					if(tagsget(&ctx) != 0)
-						fprint(2, "%s: no tags\n", path);
+					res = tagsget(&ctx);
+					if(ctx.format != Funknown){
+						if(res != 0)
+							fprint(2, "%s: no tags\n", path);
+					}else{
+						numall--;
+						continue;
+					}
+
 					if(ctx.duration == 0)
 						fprint(2, "%s: no duration\n", path);
 					if(curr->title == nil){
@@ -180,6 +183,7 @@
 					}
 					curr->path = strdup(path);
 					curr->duration = ctx.duration;
+					curr->filefmt = ctx.format < nelem(fmts) ? fmts[ctx.format] : "FIXMEFMT";
 				}
 				Bterm(bf);
 			}else if(depth < Maxdepth){ /* recurse into the directory */
@@ -221,7 +225,7 @@
 		s = seprint(s, buf+sizeof(buf), "%c %d\n", Pduration, m->duration);
 	if(m->imagesize > 0)
 		s = seprint(s, buf+sizeof(buf), "%c %d %d %d %s\n", Pimage, m->imageoffset, m->imagesize, m->imagereader, m->imagefmt);
-	s = seprint(s, buf+sizeof(buf), "%c %s\n", Ppath, m->path);
+	s = seprint(s, buf+sizeof(buf), "%c %s\n%c %s\n", Pfilefmt, m->filefmt, Ppath, m->path);
 
 	if(buf[sizeof(buf)-2] != 0)
 		sysfatal("buffer size of %d bytes was a bad choice", sizeof(buf));
--- a/plist.h
+++ b/plist.h
@@ -19,6 +19,7 @@
 	Ptitle=			't',
 	Ptrack=			'T',
 	Ppath=			'p',
+	Pfilefmt=		'f',
 
 	/* unused */
 	Pchannels=		'c',
@@ -38,6 +39,7 @@
 	char *track;
 	char *path;
 	char *imagefmt;
+	char *filefmt;
 	int numartist;
 	int duration;
 	int imageoffset;
--- a/zuke.c
+++ b/zuke.c
@@ -375,7 +375,7 @@
 static void
 playerthread(void *player_)
 {
-	char *buf;
+	char *buf, cmd[32];
 	Player *player;
 	Ioproc *io;
 	Image *thiscover;
@@ -406,7 +406,8 @@
 		dup(fd, 0); close(fd);
 		close(p[1]);
 		dup(open("/dev/null", OWRITE), 2);
-		execl("/bin/play", "play", "-o", "/fd/1", nil);
+		snprint(cmd, sizeof(cmd), "/bin/audio/%sdec", pl[player->pcur].filefmt);
+		execl(cmd, cmd, nil);
 		sysfatal("execl: %r");
 	}
 	if(pid < 0)
@@ -629,6 +630,9 @@
 			}else if(s[0] == Ppath){
 				m->path = s+2;
 				break; /* always the last one */
+			}else if(s[0] == Pfilefmt){
+				m->filefmt = s+2;
+				s = strchr(s+2, '\n') + 1;
 			}else{
 				tagsz = strtol(s+1, &e, 10);
 				if(e+tagsz >= plraw+plrawsize)