summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorSigrid Solveig Haflínudóttir <sigrid@ftrv.se>2022-08-30 18:09:32 +0000
committerSigrid Solveig Haflínudóttir <sigrid@ftrv.se>2022-08-30 18:09:32 +0000
commiteaef2887f5787ec4740b9223589c94be64c5f061 (patch)
tree0dec64ffef3d39a7f5a483dde18481fb367656e6 /sys
parent2417e3f61def0443d8f75bcc5003a63e02fe880b (diff)
libtags: try other formats after id3v2 is found
Even though a valid id3v2 tag header may be present, the file format itself might not be mp3. Instead, retry other format parsers on the file after seeking right past the id3v2 header. This fixes FLACs that are ID3v2-tagged (the reasoning behind that is left with no comment). Also convert "TLEN" into duration while at it.
Diffstat (limited to 'sys')
-rw-r--r--sys/src/cmd/audio/libtags/flac.c2
-rw-r--r--sys/src/cmd/audio/libtags/id3v2.c4
-rw-r--r--sys/src/cmd/audio/libtags/tags.c3
-rw-r--r--sys/src/cmd/audio/libtags/tags.h1
4 files changed, 8 insertions, 2 deletions
diff --git a/sys/src/cmd/audio/libtags/flac.c b/sys/src/cmd/audio/libtags/flac.c
index 7bbc193a0..824f6abf1 100644
--- a/sys/src/cmd/audio/libtags/flac.c
+++ b/sys/src/cmd/audio/libtags/flac.c
@@ -25,7 +25,7 @@ tagflac(Tagctx *ctx)
ctx->duration = g * 1000 / ctx->samplerate;
/* skip the rest of the stream info */
- if(ctx->seek(ctx, sz-18, 1) != 8+sz)
+ if(ctx->seek(ctx, sz-18, 1) != ctx->restart+8+sz)
return -1;
for(last = 0; !last;){
diff --git a/sys/src/cmd/audio/libtags/id3v2.c b/sys/src/cmd/audio/libtags/id3v2.c
index a2ec8dcf5..dbb857fba 100644
--- a/sys/src/cmd/audio/libtags/id3v2.c
+++ b/sys/src/cmd/audio/libtags/id3v2.c
@@ -27,6 +27,8 @@ v2cb(Tagctx *ctx, char *k, char *v)
txtcb(ctx, Tdate, k-1, v);
else if(strcmp(k, "RK") == 0 || strcmp(k, "RCK") == 0)
txtcb(ctx, Ttrack, k-1, v);
+ else if(strcmp(k, "LEN") == 0)
+ ctx->duration = atoi(v);
else if(strcmp(k, "CO") == 0 || strcmp(k, "CON") == 0){
for(; v[0]; v++){
if(v[0] == '(' && v[1] <= '9' && v[1] >= '0'){
@@ -388,6 +390,8 @@ header:
if(ver == 2 && (d[5] & (1<<6)) != 0) /* compression */
return -1;
+ ctx->restart = sizeof(d)+sz;
+
if(ver > 2){
if((d[5] & (1<<4)) != 0) /* footer */
sz -= 10;
diff --git a/sys/src/cmd/audio/libtags/tags.c b/sys/src/cmd/audio/libtags/tags.c
index 44729a652..6c6b2b55e 100644
--- a/sys/src/cmd/audio/libtags/tags.c
+++ b/sys/src/cmd/audio/libtags/tags.c
@@ -65,6 +65,7 @@ tagsget(Tagctx *ctx)
ctx->channels = ctx->samplerate = ctx->bitrate = ctx->duration = 0;
ctx->found = 0;
ctx->format = Funknown;
+ ctx->restart = 0;
res = -1;
for(i = 0; i < nelem(g); i++){
ctx->num = 0;
@@ -72,7 +73,7 @@ tagsget(Tagctx *ctx)
ctx->format = g[i].format;
res = 0;
}
- ctx->seek(ctx, 0, 0);
+ ctx->seek(ctx, ctx->restart, 0);
}
return res;
diff --git a/sys/src/cmd/audio/libtags/tags.h b/sys/src/cmd/audio/libtags/tags.h
index 0c58220a1..4071c79e4 100644
--- a/sys/src/cmd/audio/libtags/tags.h
+++ b/sys/src/cmd/audio/libtags/tags.h
@@ -81,6 +81,7 @@ struct Tagctx
/* Private, don't touch. */
int found;
int num;
+ int restart;
};
/* Parse the file using this function. Returns 0 on success. */