shithub: libtags

Download patch

ref: 2450cb76aeeacc86063f746590ffac1f107ef85e
parent: a225c927060b13c9e37ac7ad60d7470d062d2075
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Feb 19 13:37:23 EST 2024

add Tcomposer and Tcomment

--- a/examples/readtags.c
+++ b/examples/readtags.c
@@ -35,6 +35,8 @@
 	[Ttrackpeak] = "trackpeak",
 	[Tgenre] = "genre",
 	[Timage] = "image",
+	[Tcomposer] = "composer",
+	[Tcomment] = "comment",
 };
 
 static void
--- a/id3v1.c
+++ b/id3v1.c
@@ -36,6 +36,9 @@
 	if((ctx->found & 1<<Tdate) == 0 && in[93] != 0)
 		txtcb(ctx, Tdate, "", &in[93]);
 
+	if((ctx->found & 1<<Tcomment) == 0 && in[97] != 0)
+		txtcb(ctx, Tcomment, "", &in[97]);
+
 	if((ctx->found & 1<<Ttrack) == 0 && in[125] == 0 && in[126] > 0){
 		snprint((char*)out, Outsz, "%d", in[126]);
 		txtcb(ctx, Ttrack, "", out);
--- a/id3v2.c
+++ b/id3v2.c
@@ -29,6 +29,8 @@
 		txtcb(ctx, Ttrack, k-1, v);
 	else if(strcmp(k, "LEN") == 0)
 		ctx->duration = atoi(v);
+	else if(strcmp(k, "CM") == 0 || strcmp(k, "COM") == 0)
+		txtcb(ctx, Tcomposer, k-1, v);
 	else if(strcmp(k, "CO") == 0 || strcmp(k, "CON") == 0){
 		for(; v[0]; v++){
 			if(v[0] == '(' && v[1] <= '9' && v[1] >= '0'){
@@ -62,6 +64,8 @@
 			txtcb(ctx, type, k-1, v+5);
 		else
 			return 0;
+	}else if(strcmp(k-1, "COM") == 0 || strcmp(k-1, "COMM") == 0){
+		txtcb(ctx, Tcomment, k-1, v);
 	}else{
 		txtcb(ctx, Tunknown, k-1, v);
 	}
--- a/m4a.c
+++ b/m4a.c
@@ -93,6 +93,10 @@
 			type = Timage;
 		else if(memcmp(d, "trkn", 4) == 0)
 			type = Ttrack;
+		else if(memcmp(d, "\251wrt", 4) == 0)
+			type = Tcomposer;
+		else if(memcmp(d, "\251cmt", 4) == 0)
+			type = Tcomment;
 		else if(memcmp(d, "mdhd", 4) == 0){
 			if(ctx->read(ctx, d, 4) != 4)
 				return -1;
--- a/tags.h
+++ b/tags.h
@@ -20,6 +20,8 @@
 	Ttrackpeak,
 	Tgenre,
 	Timage,
+	Tcomposer,
+	Tcomment,
 };
 
 /* Format of the audio file. */
--- a/vorbis.c
+++ b/vorbis.c
@@ -4,31 +4,37 @@
  */
 #include "tagspriv.h"
 
+static const struct {
+	char *s;
+	int type;
+}t[] = {
+	{"album", Talbum},
+	{"title", Ttitle},
+	{"artist", Tartist},
+	{"tracknumber", Ttrack},
+	{"date", Tdate},
+	{"replaygain_track_peak", Ttrackpeak},
+	{"replaygain_track_gain", Ttrackgain},
+	{"replaygain_album_peak", Talbumpeak},
+	{"replaygain_album_gain", Talbumgain},
+	{"genre", Tgenre},
+	{"composer", Tcomposer},
+	{"comment", Tcomment},
+};
+
 void
 cbvorbiscomment(Tagctx *ctx, char *k, char *v){
+	int i;
+
 	if(*v == 0)
 		return;
-	if(cistrcmp(k, "album") == 0)
-		txtcb(ctx, Talbum, k, v);
-	else if(cistrcmp(k, "title") == 0)
-		txtcb(ctx, Ttitle, k, v);
-	else if(cistrcmp(k, "artist") == 0)
-		txtcb(ctx, Tartist, k, v);
-	else if(cistrcmp(k, "tracknumber") == 0)
-		txtcb(ctx, Ttrack, k, v);
-	else if(cistrcmp(k, "date") == 0)
-		txtcb(ctx, Tdate, k, v);
-	else if(cistrcmp(k, "replaygain_track_peak") == 0)
-		txtcb(ctx, Ttrackpeak, k, v);
-	else if(cistrcmp(k, "replaygain_track_gain") == 0)
-		txtcb(ctx, Ttrackgain, k, v);
-	else if(cistrcmp(k, "replaygain_album_peak") == 0)
-		txtcb(ctx, Talbumpeak, k, v);
-	else if(cistrcmp(k, "replaygain_album_gain") == 0)
-		txtcb(ctx, Talbumgain, k, v);
-	else if(cistrcmp(k, "genre") == 0)
-		txtcb(ctx, Tgenre, k, v);
-	else
+	for(i = 0; i < nelem(t); i++){
+		if(cistrcmp(k, t[i].s) == 0){
+			txtcb(ctx, t[i].type, k, v);
+			break;
+		}
+	}
+	if(i == nelem(t))
 		txtcb(ctx, Tunknown, k, v);
 }
 
--- a/wav.c
+++ b/wav.c
@@ -2,7 +2,7 @@
 
 #define le16u(d) (u16int)((d)[0] | (d)[1]<<8)
 
-static struct {
+static const struct {
 	char *s;
 	int type;
 }t[] = {
@@ -12,6 +12,7 @@
 	{"INAM", Ttitle},
 	{"IPRD", Talbum},
 	{"ITRK", Ttrack},
+	{"ICMT", Tcomment},
 	{"????", Tunknown},
 };