I need to rewrite the TAG of an mp3 file, "change the name, album, date, etc." This is the code I use to read the information of an mp3:
//ID3 scan
#include <iostream>
#include <cstring>
using namespace std;
typedef unsigned char byte;
typedef unsigned int unit;
typedef struct {byte b3,b2,b1,b0;}sint;
struct header {
char mark [3];
byte version [2];
byte flags ;
sint size ;
};
struct frame {
char id [4];
sint size ;
byte flags [2];
};
uint unsych (sint value ){
return value.b0|value.b1<<8|value.b2<<16|value.b3<<24;
}
int main(){
FILE*file=fopen ("/home/caeforga/Descargas/cancion.mp3","r");
if (!file){
cout<<"file not found"<<endl;
return 0;
}
header hd;
fread(&hd,10,1,file);
if(strncmp(hd.mark,"ID3",3)!=0){
cout<< "this file has'nt TAG"<<endl;
fclose(file);
return 0;
}
cout<< "version: "
<<(int)hd.version[0]<<"."<<(int)hd.version[1]<<endl;
cout << "flags: "<<(int)hd.flags<<endl;
cout<< " size: "<<unsych(hd.size)<<endl;
if (hd.version[0]<3){
cout <<"version no complatible "<<endl;
fclose (file);
return 0;
}
while (true) {
frame fr;
fread (&fr,10,1,file);
if (fr.id[0]<'A') break;
cout<< endl;
cout<< fr.id[0]<<fr.id[1]<<fr.id[2]<<fr.id[3]<< " " << unsych(fr.size)<<" bytes "<< endl ;
if (fr.id[0]!='T'){
fseek(file, unsych( fr.size), SEEK_CUR);
}
else {
char buffer;
for (uint i =0;i <unsych(fr.size); i++){
fread(&buffer ,1,1,file);
if(buffer >=32&& buffer <=126){
cout<< buffer;
}
}
cout <<endl;
}
}
fclose (file );
return 0;
}