ref: d9b4a120f0c7d48e2901361eb6faa9704ca2d608
dir: /icy.c/
int icyfill(Meta *m) { char *s, *e, *p, *path, *d; int f, n; path = strdup(m->path); s = strchr(path, ':')+3; if((e = strchr(s, '/')) != nil) *e++ = 0; if((p = strchr(s, ':')) != nil) *p = '!'; p = smprint("tcp!%s", s); free(path); d = netmkaddr(p, "tcp", "80"); free(p); 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); n = readn(f, s, 4095); s[n] = 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; }