shithub: libtags

ref: 4a7f42e378e27bf70c928b411ac859c870c23f24
dir: /tags.c/

View raw version
#include "tagspriv.h"

typedef struct Getter Getter;

struct Getter
{
	int (*f)(Tagctx *ctx);
	int format;
};

static const Getter g[] =
{
	{tagid3v2, Fmp3},
	{tagid3v1, Fmp3},
	{tagvorbis, Fvorbis},
	{tagflac, Fflac},
	{tagm4a, Fm4a},
	{tagopus, Fopus},
	{tagwav, Fwav},
	{tagit, Fit},
	{tagxm, Fxm},
	{tags3m, Fs3m},
	{tagmod, Fmod},
};

void
tagscallcb(Tagctx *ctx, int type, Tag *tag)
{
	char *s, *e;

	if(type != Timage){
		for(s = tag->text.v; (uint8_t)*s <= ' ' && *s; s++);
		e = s + strlen(s);
		while(e != s && (uint8_t)e[-1] <= ' ')
			e--;
		if(*e != 0)
			*e = 0;
		if(*s == 0)
			return;
		tag->text.v = s;
	}
	ctx->tag(ctx, type, tag);
	if(type != Tunknown)
		ctx->found |= 1<<type;
}

int
tagsget(Tagctx *ctx)
{
	int i, res;

	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++){
		if(g[i].f(ctx) == 0){
			ctx->format = g[i].format;
			res = 0;
		}
		ctx->seek(ctx, ctx->restart, 0);
	}

	return res;
}