-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
241 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include "id3tag.h" | ||
|
||
ID3tag::ID3tag(QObject *parent) : QObject(parent) | ||
{ | ||
|
||
} | ||
|
||
ID3tag::~ID3tag() | ||
{ | ||
delete fileN; | ||
delete fileS; | ||
delete fileImage; | ||
delete dStreamS; | ||
delete dStream; | ||
// delete tStream; | ||
} | ||
|
||
ID3tag::ID3tag(QString fileName) | ||
{ | ||
mp3FileName=fileName; | ||
mp3FileNameTmp=fileName+QString(".tmp"); | ||
fileS=new QFile(mp3FileName); | ||
fileS->open(QIODevice::ReadOnly); | ||
fileN=new QFile(mp3FileNameTmp); | ||
fileN->open(QIODevice::WriteOnly); | ||
dStream=new QDataStream(fileN); | ||
memset(&tagHeader,0,sizeof(tagHeader)); | ||
memset(&titleHeader,0,sizeof(titleHeader)); | ||
memset(&artistHeader,0,sizeof(artistHeader)); | ||
memset(&albumHeader,0,sizeof(albumHeader)); | ||
memset(&picHeader,0,sizeof(picHeader)); | ||
tagHeader.identifier[0]='I'; | ||
tagHeader.identifier[1]='D'; | ||
tagHeader.identifier[2]='3'; | ||
tagHeader.version[0]=0x03; | ||
titleHeader.frameID[0]='T';titleHeader.frameID[1]='I';titleHeader.frameID[2]='T';titleHeader.frameID[3]='2'; | ||
artistHeader.frameID[0]='T';artistHeader.frameID[1]='P';artistHeader.frameID[2]='E';artistHeader.frameID[3]='1'; | ||
albumHeader.frameID[0]='T';albumHeader.frameID[1]='A';albumHeader.frameID[2]='L';albumHeader.frameID[3]='B'; | ||
picHeader.frameID[0]='A';picHeader.frameID[1]='P';picHeader.frameID[2]='I';picHeader.frameID[3]='C'; | ||
|
||
//获取mp3音频内容 | ||
dStreamS =new QDataStream(fileS); | ||
dStreamS->readRawData((char*)&tagHeaderOld,10); | ||
int oldHeaderSize=128*128*128*tagHeaderOld.size[0]+128*128*tagHeaderOld.size[1]+128*tagHeaderOld.size[2]+tagHeaderOld.size[3]; | ||
fileS->seek(10+oldHeaderSize); | ||
mp3File=fileS->readAll(); | ||
} | ||
|
||
void ID3tag::setTitle(QString t) | ||
{ | ||
title=t; | ||
titleSize=2*sizeof(title)+3; | ||
titleHeader.size[3]=titleSize; | ||
} | ||
|
||
void ID3tag::setArtist(QString a) | ||
{ | ||
artist=a; | ||
artistSize=2*sizeof(a)+3; | ||
artistHeader.size[3]=artistSize; | ||
} | ||
|
||
void ID3tag::setAlbum(QString a) | ||
{ | ||
album=a; | ||
albumSize=2*sizeof(album)+3; | ||
albumHeader.size[3]=albumSize; | ||
} | ||
|
||
void ID3tag::setPic(QString imageFileName) | ||
{ | ||
fileImage=new QFile(imageFileName); | ||
fileImage->open(QIODevice::ReadOnly); | ||
image=fileImage->readAll(); | ||
memset(mimeInfo,0,14); | ||
char tmp[14]={0x00,0x69,0x6D,0x61,0x67,0x65,0x2F,0x6A,0x70,0x65,0x67,0x00,0x03,0x00}; | ||
memcpy(mimeInfo,tmp,14); | ||
picSize=image.size()+14; | ||
picHeader.size[0]=picSize/(256*256*256); | ||
picHeader.size[1]=picSize%(256*256*256)/(256*256); | ||
picHeader.size[2]=picSize%(256*256*256)%(256*256)/256; | ||
picHeader.size[3]=picSize%(256*256*256)%(256*256)%256; | ||
} | ||
|
||
void ID3tag::doJob() | ||
{ | ||
uchar unicodeBom[3]={0x01,0xFF,0xFE}; | ||
int size=40+titleSize+artistSize+albumSize+picSize; | ||
tagHeader.size[0]=size/(128*128*128); | ||
tagHeader.size[1]=size%(128*128*128)/(128*128); | ||
tagHeader.size[2]=size%(128*128*128)%(128*128)/128; | ||
tagHeader.size[3]=size%(128*128*128)%(128*128)%128; | ||
dStream->writeRawData((char*)&tagHeader,10); | ||
dStream->writeRawData((char*)&titleHeader,10); | ||
dStream->writeRawData((char*)unicodeBom,3); | ||
dStream->writeRawData((char*)title.data(),sizeof(title)*2); | ||
dStream->writeRawData((char*)&artistHeader,10); | ||
dStream->writeRawData((char*)unicodeBom,3); | ||
dStream->writeRawData((char*)artist.data(),sizeof(artist)*2); | ||
dStream->writeRawData((char*)&albumHeader,10); | ||
dStream->writeRawData((char*)unicodeBom,3); | ||
dStream->writeRawData((char*)album.data(),sizeof(album)*2); | ||
dStream->writeRawData((char*)&picHeader,10); | ||
dStream->writeRawData(mimeInfo,14); | ||
dStream->writeRawData((char*)image.data(),image.size()); | ||
dStream->writeRawData((char*)mp3File.data(),mp3File.size()); | ||
fileImage->close(); | ||
fileN->close(); | ||
fileS->close(); | ||
fileS->remove(); | ||
fileN->rename(mp3FileName); | ||
emit finished(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef ID3TAG_H | ||
#define ID3TAG_H | ||
|
||
#include <QObject> | ||
#include <QFile> | ||
#include <QTextStream> | ||
#include <QDataStream> | ||
|
||
typedef struct ID3HEADER{ | ||
char identifier[3]; | ||
char version[2]; | ||
char flags; | ||
char size[4]; | ||
}id3Header; | ||
|
||
typedef struct FRAMEHEADER{ | ||
char frameID[4]; | ||
char size[4]; | ||
char flags[2]; | ||
}frameHeader; | ||
|
||
class ID3tag : public QObject | ||
{ | ||
Q_OBJECT | ||
private: | ||
id3Header tagHeaderOld; | ||
QString mp3FileName; | ||
QString mp3FileNameTmp; | ||
|
||
id3Header tagHeader; | ||
frameHeader titleHeader; | ||
frameHeader artistHeader; | ||
frameHeader albumHeader; | ||
frameHeader picHeader; | ||
|
||
int titleSize; | ||
int artistSize; | ||
int albumSize; | ||
int picSize; | ||
|
||
QString title; | ||
QString artist; | ||
QString album; | ||
QByteArray image; | ||
QByteArray mp3File; | ||
char mimeInfo[14]; | ||
|
||
QFile *fileN; //新的的文件 | ||
QFile *fileS; //原来的文件 | ||
QFile *fileImage; | ||
QDataStream *dStreamS; | ||
QDataStream *dStream; | ||
// QTextStream *tStream; | ||
|
||
public: | ||
explicit ID3tag(QObject *parent = nullptr); | ||
ID3tag(QString fileName); | ||
~ID3tag(); | ||
void setTitle(QString t); | ||
void setArtist(QString a); | ||
void setAlbum(QString a); | ||
void setPic(QString imageFileName); | ||
void doJob(); | ||
|
||
signals: | ||
processState(QString ); | ||
finished(); | ||
public slots: | ||
}; | ||
|
||
#endif // ID3TAG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.