From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, RDNS_NONE autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 16481 invoked from network); 11 Jul 2021 10:27:50 -0000 Received: from unknown (HELO 1ess.inri.net) (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 11 Jul 2021 10:27:50 -0000 Received: from mail.posixcafe.org ([45.76.19.58]) by 1ess; Sat Jul 10 23:23:14 -0400 2021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posixcafe.org; s=20200506; t=1625973785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=w1HIxulvrlUXRvXU5PD0cT8/FmttM5DoJgdyjhUwcjw=; b=MgCmGTW2i2ZnmGS9fE9+2nJFbidAnNeKv+bFZI+j/kx0pdNaEyB8j+ePre/qGpo941k22x UVC1Dqp9o0asQwVhK6NVTJlYYRSdGSb5zFl7Of+qMZ9RwRxkwtIEb2lrsaY5rBh1PCMywT tJa8zaegnvkV8NYikSyUu8L+UxiesJg= Received: from [192.168.168.200] ( [161.97.228.135]) by mail.posixcafe.org (OpenSMTPD) with ESMTPSA id 4ecf9acf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <9front@9front.org>; Sat, 10 Jul 2021 22:23:05 -0500 (CDT) To: 9front@9front.org From: Jacob Moody Message-ID: Date: Sat, 10 Jul 2021 21:22:49 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: optimized immutable realtime-java-oriented service Subject: [9front] [PATCH] aux/cddb: parse and print year and artist if defined Reply-To: 9front@9front.org Precedence: bulk When poking around cddb I found that some CDs would have artist information within the title fields. I figured cddb could parse them if present. --- diff 51a351e84570e8ac4322ad202bfc57f648755019 be3d56ee5c74fd681e94f7bcf5781b3f4137b2e5 --- a/sys/src/cmd/aux/cddb.c Sat Jul 10 09:57:46 2021 +++ b/sys/src/cmd/aux/cddb.c Sat Jul 10 21:17:26 2021 @@ -14,6 +14,7 @@ struct Track { int n; char *title; + char *artist; }; enum { @@ -25,6 +26,8 @@ ulong diskid; int ntrack; char *title; + char *year; + char *artist; Track track[MTRACK]; }; @@ -55,17 +58,23 @@ { int i, n, s; - print("title %s\n", t->title); + print("title\t%s\n", t->title); + if(t->year[0] != 0) + print("year\t%s\n", t->year); + if(t->artist[0] != 0) + print("artist\t%s\n", t->artist); for(i=0; intrack; i++){ + print("%d\t%s", i+1, t->track[i].title); if(tflag){ n = t->track[i+1].n; if(i == t->ntrack-1) n *= 75; s = (n - t->track[i].n)/75; - print("%d\t%s\t%d:%2.2d\n", i+1, t->track[i].title, s/60, s%60); + print("\t%d:%2.2d", s/60, s%60); } - else - print("%d\t%s\n", i+1, t->track[i].title); + if(t->track[i].artist[0] != 0) + print("\t%s", t->track[i].artist); + print("\n"); } if(Tflag){ s = t->track[i].n; @@ -84,12 +93,26 @@ return c; } +char* +split(char *s) +{ + char *p; + + for(p=s; *p != '/' && *p != 0; p++) + ; + if(*p == '/'){ + p[-1] = 0; + return p+2; + } + return nil; +} + static int cddbfilltoc(Toc *t) { int fd; int i; - char *p, *q; + char *p, *q, *a; Biobuf bin; char *f[10]; int nf; @@ -183,8 +206,12 @@ } t->title = ""; - for(i=0; intrack; i++) + t->artist = ""; + t->year = ""; + for(i=0; intrack; i++) { t->track[i].title = ""; + t->track[i].artist = ""; + } /* fetch results for this cd */ fprint(fd, "cddb read %s %s\r\n", categ, id); @@ -195,8 +222,18 @@ while(isspace(*q)) *q-- = 0; DPRINT(2, "cddb %s\n", p); - if(strncmp(p, "DTITLE=", 7) == 0) - t->title = append(t->title, p+7); + if(strncmp(p, "DTITLE=", 7) == 0) { + p += 7; + a = split(p); + if(a != nil) { + t->artist = append(t->title, p); + p = a; + } + t->title = append(t->title, p); + } + else if(strncmp(p, "DYEAR=", 6) == 0) { + t->year = append(t->year, p+6); + } else if(strncmp(p, "TTITLE", 6) == 0 && isdigit(p[6])) { i = atoi(p+6); if(i < t->ntrack) { @@ -205,8 +242,12 @@ p++; if(*p == '=') p++; - - t->track[i].title = append(t->track[i].title, estrdup(p)); + a = split(p); + if(a != nil) { + t->track[i].artist = append(t->track[i].artist, estrdup(p)); + p = a; + } + t->track[i].title = append(t->track[i].title, estrdup(p)); } } } while(*p != '.');