ref: 90b72c3a3282241e608f8bf778003f8afc96fdac
parent: fe4a4fbb32a90318da590e90b500cd42e95fa7ce
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Aug 30 14:09:32 EDT 2022
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.
--- a/flac.c
+++ b/flac.c
@@ -25,7 +25,7 @@
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;){
--- a/id3v2.c
+++ b/id3v2.c
@@ -27,6 +27,8 @@
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'){
@@ -387,6 +389,8 @@
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 */
--- a/tags.c
+++ b/tags.c
@@ -65,6 +65,7 @@
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 @@
ctx->format = g[i].format;
res = 0;
}
- ctx->seek(ctx, 0, 0);
+ ctx->seek(ctx, ctx->restart, 0);
}
return res;
--- a/tags.h
+++ b/tags.h
@@ -83,6 +83,7 @@
/* Private, don't touch. */
int found;
int num;
+ int restart;
};
/* Parse the file using this function. Returns 0 on success. */