ref: 5449f10ad59bc28d4c35847cfc2415bbea402b85
parent: 9a8645b20bd5a5a4a4295b5116d09720d6bc6c8d
author: Tevo <estevan.cps@gmail.com>
date: Sat Jan 16 20:59:30 EST 2021
Improve FLAC metadata handling, add TRACKNUMBER
--- a/cuefs.h
+++ b/cuefs.h
@@ -11,6 +11,7 @@
void* erealloc(void*, ulong);
void* emallocz(ulong, int);
void* emalloc(ulong);
+char* esmprint(char*, ...);
char* setstr(char*, char**, char*);
char* strreplace(char*, char, char);
--- a/fs.c
+++ b/fs.c
@@ -353,6 +353,46 @@
return pid;
}
+static char**
+spush(int *sz, char **arr, char *str)
+{
+ /* maybe reallocating in chunks is a better idea? */
+ arr = erealloc(arr, sizeof(*arr) * ++(*sz));
+ arr[(*sz)-1] = str;
+ return arr;
+}
+
+static char**
+tagflag(int *sz, char **arr, char* tag)
+{
+ arr = spush(sz, arr, "-T");
+ arr = spush(sz, arr, tag);
+ return arr;
+}
+
+char**
+metaflags(char *enc, Entry *e)
+{
+ char **ret;
+ int c = 0;
+
+ ret = emalloc(sizeof(*ret));
+
+ ret = spush(&c, ret, enc);
+ ret = tagflag(&c, ret, esmprint("TITLE=%s", e->title));
+ ret = tagflag(&c, ret, esmprint("TRACKNUMBER=%d", e->index));
+ if(e->performer != nil)
+ ret = tagflag(&c, ret, esmprint("ARTIST=%s", e->performer));
+ if(e->sheet->performer != nil)
+ ret = tagflag(&c, ret, esmprint("ALBUMARTIST=%s", e->sheet->performer));
+ if(e->sheet->title != nil)
+ ret = tagflag(&c, ret, esmprint("ALBUM=%s", e->sheet->title));
+
+ ret = spush(&c, ret, nil);
+
+ return ret;
+}
+
int
_flacenc(Entry *e, int infd, int outfd)
{
@@ -368,15 +408,7 @@
close(outfd);
{
/* TODO better metadata handling */
- char *argv[] =
- {
- enc,
- "-T", smprint("TITLE=%s", e->title),
- "-T", smprint("ARTIST=%s", e->performer),
- "-T", smprint("ALBUMARTIST=%s", e->sheet->performer),
- "-T", smprint("ALBUM=%s", e->sheet->title),
- nil
- };
+ char **argv = metaflags(enc, e);
exec(enc, argv);
enc = smprint("/bin/%s", enc);
if(enc == nil)
--- a/misc.c
+++ b/misc.c
@@ -36,6 +36,21 @@
return p;
}
+char*
+esmprint(char *fmt, ...)
+{
+ char *str;
+ va_list args;
+
+ va_start(args, fmt);
+ str = vsmprint(fmt, args);
+ if(str == nil)
+ sysfatal("vsmprint: %r");
+ va_end(args);
+
+ return str;
+}
+
void
yyerror(char *str)
{