ref: 06731838403de9fa6bb4eaa6c5010b3ed70f210e
parent: 4882f18a593355d94cf0e5ebe0735fb7f5d9a580
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Feb 19 13:37:23 EST 2024
libtags: add Tcomposer and Tcomment
--- a/sys/src/cmd/audio/libtags/id3v1.c
+++ b/sys/src/cmd/audio/libtags/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/sys/src/cmd/audio/libtags/id3v2.c
+++ b/sys/src/cmd/audio/libtags/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/sys/src/cmd/audio/libtags/m4a.c
+++ b/sys/src/cmd/audio/libtags/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/sys/src/cmd/audio/libtags/tags.h
+++ b/sys/src/cmd/audio/libtags/tags.h
@@ -18,6 +18,8 @@
Ttrackpeak,
Tgenre,
Timage,
+ Tcomposer,
+ Tcomment,
};
/* Format of the audio file. */
--- a/sys/src/cmd/audio/libtags/vorbis.c
+++ b/sys/src/cmd/audio/libtags/vorbis.c
@@ -4,31 +4,39 @@
*/
#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},
+ {"r128_track_gain", Ttrackgain},
+ {"replaygain_album_peak", Talbumpeak},
+ {"replaygain_album_gain", Talbumgain},
+ {"r128_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 || cistrcmp(k, "r128_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 || cistrcmp(k, "r128_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/sys/src/cmd/audio/libtags/wav.c
+++ b/sys/src/cmd/audio/libtags/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},
};
--- a/sys/src/cmd/audio/readtags/readtags.c
+++ b/sys/src/cmd/audio/readtags/readtags.c
@@ -22,6 +22,8 @@
[Ttrackpeak] = "trackpeak",
[Tgenre] = "genre",
[Timage] = "image",
+ [Tcomposer] = "composer",
+ [Tcomment] = "comment",
};
static int image;