shithub: zuke

Download patch

ref: c87b8ced7e890bc8f961f5095133ff32afc5b490
parent: fdbf31f12cf811f66a123fa5abcd87b68ec771b7
author: Sigrid Haflínudóttir <[email protected]>
date: Wed Jun 10 14:47:24 EDT 2020

mkplist: query IceCast metadata

--- /dev/null
+++ b/icy.c
@@ -1,0 +1,39 @@
+int
+icyfill(Meta *m)
+{
+	char *s, *e, *p, *d, tmp[128];
+	int f, r, n;
+
+	s = strchr(m->path, ':')+3;
+	if((e = strchr(s, '/')) != nil)
+		*e++ = 0;
+	if((p = strchr(s, ':')) != nil)
+		*p = '!';
+	sprint(tmp, "tcp!%s", s);
+	d = netmkaddr(tmp, "tcp", "80");
+	if((f = dial(d, nil, nil, nil)) < 0)
+		return -1;
+	fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
+	s = malloc(4096);
+	for(r = 0; r < 4096; r += n){
+		if((n = read(f, s+r, 4096-r)) < 1)
+			break;
+	}
+	s[r] = 0;
+	for(; s = strchr(s, '\n');){
+		s++;
+		if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
+			*e = 0;
+			m->artist[0] = strdup(s+9);
+			m->numartist = 1;
+			s = e+1;
+		}else if(strncmp(s, "icy-url:", 8) == 0 && (e = strchr(s, '\r')) != nil){
+			*e = 0;
+			m->title = strdup(s+8);
+			s = e+1;
+		}
+	}
+	close(f);
+
+	return 0;
+}
--- a/mkplist.c
+++ b/mkplist.c
@@ -3,6 +3,7 @@
 #include <bio.h>
 #include <tags.h>
 #include "plist.h"
+#include "icy.c"
 
 enum
 {
@@ -301,6 +302,8 @@
 			curr->title = argv[i];
 			curr->path = argv[i];
 			curr->filefmt = "";
+			if(icyfill(curr) != 0)
+				fprint(2, "%s: %r\n", argv[i]);
 		}else{
 			dir = strdup(argv[i]);
 			scan(&dir, 0);