shithub: libtags

Download patch

ref: 01e1d5d4b4211b7c804eb344b47c0a9a26593114
parent: 63b1d8e124c602cf5bec357e1f04653a86e6af52
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat May 23 23:32:16 EDT 2020

extension shouldn't matter, remove this logic and add Funknown

--- a/examples/readtags.c
+++ b/examples/readtags.c
@@ -94,7 +94,6 @@
 		if((aux.fd = open(argv[i], OREAD)) < 0)
 			print("failed to open\n");
 		else{
-			ctx.filename = argv[i];
 			if(tagsget(&ctx) != 0)
 				print("no tags or failed to read tags\n");
 			else{
--- a/tags.c
+++ b/tags.c
@@ -5,8 +5,6 @@
 struct Getter
 {
 	int (*f)(Tagctx *ctx);
-	const char *ext;
-	int extlen;
 	int format;
 };
 
@@ -18,11 +16,11 @@
 
 static const Getter g[] =
 {
-	{tagid3v2, ".mp3", 4, Fmp3},
-	{tagid3v1, ".mp3", 4, Fmp3},
-	{tagvorbis, ".ogg", 4, Fogg},
-	{tagflac, ".flac", 5, Fflac},
-	{tagm4a, ".m4a", 4, Fm4a},
+	{tagid3v2, Fmp3},
+	{tagid3v1, Fmp3},
+	{tagvorbis, Fogg},
+	{tagflac, Fflac},
+	{tagm4a, Fm4a},
 };
 
 void
@@ -38,25 +36,19 @@
 int
 tagsget(Tagctx *ctx)
 {
-	int i, len, res;
+	int i, res;
 
-	/* enough for having an extension */
-	len = 0;
-	if(ctx->filename != nil && (len = strlen(ctx->filename)) < 5)
-		return -1;
 	ctx->channels = ctx->samplerate = ctx->bitrate = ctx->duration = 0;
 	ctx->found = 0;
-	ctx->format = -1;
+	ctx->format = Funknown;
 	res = -1;
 	for(i = 0; i < (int)(sizeof(g)/sizeof(g[0])); i++){
-		if(ctx->filename == nil || memcmp(&ctx->filename[len-g[i].extlen], g[i].ext, g[i].extlen) == 0){
-			ctx->num = 0;
-			if(g[i].f(ctx) == 0 && ctx->num > 0){
-				res = 0;
-				ctx->format = g[i].format;
-			}
-			ctx->seek(ctx, 0, 0);
+		ctx->num = 0;
+		if(g[i].f(ctx) == 0 && ctx->num > 0){
+			res = 0;
+			ctx->format = g[i].format;
 		}
+		ctx->seek(ctx, 0, 0);
 	}
 
 	return res;
--- a/tags.h
+++ b/tags.h
@@ -25,6 +25,7 @@
 /* Format of the audio file. */
 enum
 {
+	Funknown = -1,
 	Fmp3,
 	Fogg,
 	Fflac,
@@ -34,9 +35,6 @@
 /* Tag parser context. You need to set it properly before parsing an audio file using libtags. */
 struct Tagctx
 {
-	/* Set it to the filename. Doesn't have to be a full path, but extension must be there. */
-	const char *filename;
-
 	/* Read function. This is what libtags uses to read the file. */
 	int (*read)(Tagctx *ctx, void *buf, int cnt);