[mad-dev] MP3 tag
Craig Elliott
mospdude at hotmail.com
Wed Jan 17 01:01:17 PST 2007
Hi,
Mr Sayak has his tag names the other way round (ID3v1 is at the end, ID3v2
can be anywhere but tends to be at the start) but libid3tag can take care of
all that for you, but I'd recommend using a fixed version for writing ID3v2
tags as the library downloaded from the FTP cannot rewrite a file should the
tag change too much. If you search Hydrogenaudio forums for an updated
in_mad Winamp plug-in, it contains a copy of the libid3tag library source
that I've been patching to enable ID3v2 tag support in that plug-in.
The general way to access and to write a tag is,
#include <id3tag.h>
char filename[] = "input.mp3";
struct id3_file *file = id3_file_open(filename, ID3_FILE_MODE_READWRITE);
if (file != NULL)
{
int newframe = 0;
char framename[] = "TCON"; //genre frame (any ID3v2.4 frame)
struct id3_tag *tag = id3_file_tag(file);
struct id3_tag *frame = id3_tag_findframe(tag, framename, 0);
if (frame != NULL)
{
// here you can read the values from a field in the frame
// frametypes are listed in frametype.c
} else {
newframe = 1;
frame = id3_frame_new(framename);
}
// here you can set new values to a field in the frame
// frametypes are listed in frametype.c
if (newframe == 1) id3_tag_attatchframe(tag, frame);
id3_tag_options(tag, ID3_TAG_OPTION_ID3V1, ~0); //enable ID3V1 writing - wil
convert Id3v2->v1
id3_file_update(file);
}
Reading and writing text to and from the fields within a frame isn't too
difficult.
Depending on field type and position in frame (found from frametype.c),
For ID3_FIELD_TYPE_LATIN1,
id3_latin1_t *out = id3_field_getlatin1(&frame->fields[1]);
id3_field_setlatin1(&frame->fields[1], in);
For ID3_FIELD_TYPE_STRING,
id3_ucs4_t *out_ucs4 = id3_field_getstring(&frame->fields[1]);
id3_field_setstring(&frame->fields[1], in_ucs4);
For ID3_FIELD_TYPE_STRINGLIST,
int max_strs = id3_field_getnstrings(&frame->fields[n]);
id3_ucs4_t *out_sl = id3_field_getstrings(&frame->fields[1], n); // n =
string within list (< max_strs)
id3_ucs4_t *in_sls[255];
id3_ucs4_t in_sls[0] = id3_latin1_ucs4duplicate(in_sl);
n = 1;
id3_field_setstrings(&frame->fields[1], n, in_sls);
free(in_sls[0]);
>From: Sayak <sayak.ghosh at samsung.com>
>To: mad-dev at lists.mars.org
>CC: khalid.aallouche at tut.fi
>Subject: [mad-dev] Re: mad-dev Digest, Vol 18, Issue 3
>Date: Thu, 17 Jan 2008 09:50:13 +0530
>
>Hi Khalid,
>
>If I have understood your problem correctly, you want to extract ID3 tag
>and if possible Lyrics Tag in MP3 file. For version2(v2), it is stored
>after the encoded data, to extract it, you have to go at the end of the
>file. I have done this in my own way. What I did was like this,
>
>1. fseek(pFile, filesize - 10000, SEEK_SET);
>
>This 10000 number was arbitrary. To accomodate Lyrics space. But if it is
>only ID3 tag present in the file, you can reduce this number to a mere 100.
>
>2. fread(pBuffer, 1, 1000, pFile);//Lyrics Tag is also present
>Otherwise go 10 byte at a time.
>ststr(pBuffer,"ID3"). If strstr does not work in your compile(possible), go
>by the stupid process of matching byte by byte.
>
>When you found the ID3 tag, extract the information as per the
>specification of ID3 tag.
>
>You have to do this even before start decoding MP3 file.
>
>In case of encoding write the information, write the information after
>encoding is done.
><ID3>
><FILE>
><Artist>
>
>
>
>
></Artist>
></FILE>
></ID3>
>
>
>
>In Case of version 1(v1) however ID3 tag is at the beginning of the file.
>Then you dont have to go at the end of the file.
>
>Kind Regards,
>
>Sayak
>
>----- Original Message ----- From: <mad-dev-request at lists.mars.org>
>To: <mad-dev at lists.mars.org>
>Sent: Wednesday, January 17, 2007 1:30 AM
>Subject: mad-dev Digest, Vol 18, Issue 3
>
>>
>>Hi all,
>>
>>I send you that email because I want to extract the Genre (rock,
>>salsa...) from the MP3
>>file. I have studied libid3tag source code and I don't know how to
>>perform that. I will
>>be very grateful if someone can help me.
>>
>>In a second step, I want to write tags in an MP3 file (tagg v2).If
>>someone can tell if
>>it's possible to do that with libid3tag.
>>
>>Thank you for your comprehension
>>b.r,
>>Khalid
>>
>
_________________________________________________________________
Get Hotmail, News, Sport and Entertainment from MSN on your mobile.
http://www.msn.txt4content.com/
More information about the mad-dev
mailing list