ref: 32bb880971ed6c746c42d5c14d0319ad4cee4390
parent: 09382d6f208f24076988e6ae69146adc185ab53a
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Mar 5 07:40:28 EST 2021
mkplist: use audio/moddec (if available) to read duration
--- a/mkplist.c
+++ b/mkplist.c
@@ -133,6 +133,44 @@
.aux = nil,
};
+static uvlong
+modduration(char *path)
+{
+ static int moddec = -1;
+ int f, pid, p[2], n;
+ char t[1024], *s;
+
+ if(moddec < 0)
+ moddec = close(open("/bin/audio/moddec", OEXEC)) == 0;
+ if(!moddec)
+ return 0;
+
+ pipe(p);
+ if((pid = rfork(RFPROC|RFFDG|RFNOTEG|RFCENVG|RFNOWAIT)) == 0){
+ dup(f = open(path, OREAD), 0); close(f);
+ close(1);
+ dup(p[1], 2); close(p[1]);
+ close(p[0]);
+ execl("/bin/audio/moddec", "moddec", nil);
+ sysfatal("execl: %r");
+ }
+ close(p[1]);
+
+ n = pid > 0 ? readn(p[0], t, sizeof(t)-1) : -1;
+ close(p[0]);
+ if(n > 0){
+ t[n] = 0;
+ for(s = t; s != nil; s = strchr(s+1, '\n')){
+ if(*s == '\n')
+ s++;
+ if(strncmp(s, "duration: ", 10) == 0)
+ return strtod(s+10, nil)*1000.0;
+ }
+ }
+
+ return 0;
+}
+
static void
scanfile(char *path)
{
@@ -156,8 +194,12 @@
return;
}
- if(ctx.duration == 0)
- fprint(2, "%s: no duration\n", path);
+ if(ctx.duration == 0){
+ if(ctx.format == Fit || ctx.format == Fxm)
+ ctx.duration = modduration(path);
+ if(ctx.duration == 0)
+ fprint(2, "%s: no duration\n", path);
+ }
if(curr->title == nil){
if((s = utfrrune(path, '/')) == nil)
s = path;