shithub: zuke

Download patch

ref: cc90fbf9d5a4585753f1bdca62856b703a3f1825
parent: ff979be56b57de12d7e8ccb884d1aa284cd823a4
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Feb 3 10:54:22 EST 2021

write currently playing metadata to stdout unless it is /dev/cons

--- a/zuke.c
+++ b/zuke.c
@@ -56,6 +56,7 @@
 static int debug;
 static int audio = -1;
 static int volume;
+static int pnotifies;
 static Playlist *pl;
 static Player *playernext;
 static Player *playercurr;
@@ -465,6 +466,25 @@
 }
 
 static void
+pnotify(Player *p)
+{
+	Meta *m;
+	char *s;
+	int i;
+
+	if(!pnotifies)
+		return;
+
+	if(p != nil){
+		m = getmeta(p->pcur);
+		for(i = 0; cols[i] != 0; i++)
+			Bprint(&out, "%s\t", (s = getcol(m, cols[i])) ? s : "");
+	}
+	Bprint(&out, "\n");
+	Bflush(&out);
+}
+
+static void
 stop(Player *player)
 {
 	if(player == nil)
@@ -474,6 +494,8 @@
 		playernext = nil;
 	if(!getmeta(player->pcur)->filefmt[0])
 		playerret(player);
+	if(player == playercurr)
+		pnotify(nil);
 	sendul(player->ctl, Cstop);
 }
 
@@ -484,6 +506,7 @@
 		return;
 	if(!getmeta(player->pcur)->filefmt[0])
 		playerret(player);
+	pnotify(player);
 	sendul(player->ctl, Cstart);
 }
 
@@ -1146,6 +1169,7 @@
 		{ nil, nil, CHANEND },
 	};
 	int n, scrolling, oldpcur, oldbuttons, pnew, shuffled, themetid, nogui;
+	char buf[64];
 
 	shuffled = 0;
 	nogui = 0;
@@ -1175,12 +1199,13 @@
 	}
 	close(0);
 
+	Binit(&out, 1, OWRITE);
 	if(nogui){
-		Binit(&out, 1, OWRITE);
 		writeplist();
 		Bterm(&out);
 		threadexitsall(nil);
 	}
+	pnotifies = fd2path(1, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/cons") != 0;
 
 	if(initdraw(nil, nil, "zuke") < 0)
 		sysfatal("initdraw: %r");