Description of mp3 file
Binary ID3;
ByteOrder=MSB;
BitOrder=MSB;
StartMetadataKey ID3(offset=0, size=3);
checkKey(ID3)="ID3";
MetadataKey HeaderFlag(start, offset=5, size=1);
MetadataKey ID3_size(start, offset=6, size=4);
MetadataSize=getNumber(ID3_size);
if (getBit(HeaderFlag, 6)==1)
{
MetadataKey ExHeaderSize(start, offset=10, size=4);
MetadataKey FirstFrameID(start, offset=getNumber(ExHeaderSize)+10, size=4);
MetadataSize-=(10+getNumber(ExHeaderSize));
}
else
MetadataKey FirstFrameID(start, offset=10, size=4);
key=FirstFrameID;
while(MetadataSize>0)
{
MetadataKey sizeOfTag(key, offset=0, size=4);
if(getByte(key, 0)==0x00)
{
break;
}
else {
TagSize=getNumber(sizeOfTag);
if(getValue(key)=="TALB" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
SetTag Album(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TCOM" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Composer(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TDAT" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Date(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TRCK" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Track_number(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TIT2" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Title(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TENC" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Encoded_by(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
MetadataSize-=(10+getNumber(sizeOfTag));
shift(key, 10+getNumber(sizeOfTag));
}
}
Is generated parser
#include "MetadataKey.h"
#include "Tag.h"
#include "MetadataFunc.h"
#include
#include
int main(){
std::ifstream is;
int DefaultByteOrder=ByteOrderMSB;
int DefaultBitOrder=BitOrderMSB;
MetadataKey ExHeaderSize;
MetadataKey FirstFrameID;
MetadataKey HeaderFlag;
MetadataKey ID3_size;
int MetadataSize;
int TagSize;
MetadataKey encoding;
MetadataKey key;
MetadataKey sizeOfTag;
std::vector
is.open ("test.mp3", std::ifstream::in | std::ifstream::binary);
if (is.good()) {
MetadataKey ID3(is);
ID3.setOffset(0);
ID3.setSize(3);
if(!checkKey(ID3,"ID3")) return -1;
HeaderFlag.setStream(is);
HeaderFlag.setOffset(5);
HeaderFlag.setSize(1);
ID3_size.setStream(is);
ID3_size.setOffset(6);
ID3_size.setSize(4);
MetadataSize=ID3_size.getNumber(DefaultByteOrder);
if(HeaderFlag.getBit(6, DefaultBitOrder)==1){
ExHeaderSize.setStream(is);
ExHeaderSize.setOffset(10);
ExHeaderSize.setSize(4);
FirstFrameID.setStream(is);
FirstFrameID.setOffset(ExHeaderSize.getNumber(DefaultByteOrder)+10);
FirstFrameID.setSize(4);
MetadataSize-=(10+ExHeaderSize.getNumber(DefaultByteOrder));
}
else{
FirstFrameID.setStream(is);
FirstFrameID.setOffset(10);
FirstFrameID.setSize(4);
}
key=FirstFrameID;
while(MetadataSize>0){
sizeOfTag.setStream(is);
sizeOfTag.setBaseKey(key);
sizeOfTag.setOffset(0);
sizeOfTag.setSize(4);
if(key.getByte(0)==0x00){
break;}
else{
{
TagSize=sizeOfTag.getNumber(DefaultByteOrder);
if(key.getValue()=="TALB"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t0;
t0.setName("Album" );
t0.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t0);
}
if(key.getValue()=="TCOM"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t1;
t1.setName("Composer" );
t1.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t1);
}
if(key.getValue()=="TDAT"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t2;
t2.setName("Date" );
t2.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t2);
}
if(key.getValue()=="TRCK"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t3;
t3.setName("Track_number" );
t3.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t3);
}
if(key.getValue()=="TIT2"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t4;
t4.setName("Title" );
t4.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t4);
}
if(key.getValue()=="TENC"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t5;
t5.setName("Encoded_by" );
t5.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t5);
}
MetadataSize-=(10+sizeOfTag.getNumber(DefaultByteOrder));
key.setOffset(10+sizeOfTag.getNumber(DefaultByteOrder)+key.getSize());
}
}
}
}
return 0;
}
Комментариев нет:
Отправить комментарий