From: Jacob Moody <moody@mail.posixcafe.org>
To: 9front@9front.org
Subject: [9front] [PATCH] aux/cddb: parse and print year and artist if defined
Date: Sat, 10 Jul 2021 21:22:49 -0600 [thread overview]
Message-ID: <e99a1dfb-e04b-fcff-6f9e-f54db000c6d1@posixcafe.org> (raw)
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 != '.');
reply other threads:[~2021-07-11 10:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e99a1dfb-e04b-fcff-6f9e-f54db000c6d1@posixcafe.org \
--to=moody@mail.posixcafe.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).