* [9front] [PATCH] aux/cddb: parse and print year and artist if defined
@ 2021-07-11 3:22 Jacob Moody
0 siblings, 0 replies; only message in thread
From: Jacob Moody @ 2021-07-11 3:22 UTC (permalink / raw)
To: 9front
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; i<t->ntrack; 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; i<t->ntrack; i++)
+ t->artist = "";
+ t->year = "";
+ for(i=0; i<t->ntrack; 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 != '.');
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-11 10:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 3:22 [9front] [PATCH] aux/cddb: parse and print year and artist if defined Jacob Moody
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).