Added the methods to check which kind of tags the file actually has.

This commit is contained in:
Tsuda Kageyu 2013-07-04 18:11:33 +09:00
parent 7e866e11ad
commit 1503909824
17 changed files with 164 additions and 8 deletions

View File

@ -47,7 +47,7 @@ using namespace TagLib;
namespace
{
enum { ApeAPEIndex, ApeID3v1Index };
enum { ApeAPEIndex = 0, ApeID3v1Index = 1 };
}
class APE::File::FilePrivate
@ -235,6 +235,16 @@ void APE::File::strip(int tags)
}
}
bool APE::File::hasAPETag() const
{
return d->hasAPE;
}
bool APE::File::hasID3v1Tag() const
{
return d->hasID3v1;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

View File

@ -186,6 +186,16 @@ namespace TagLib {
*/
void strip(int tags = AllTags);
/*!
* Returns whether or not the file on disk contains an APE tag.
*/
bool hasAPETag() const;
/*!
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -552,3 +552,17 @@ void FLAC::File::removePictures()
d->blocks = newBlocks;
}
bool FLAC::File::hasXiphComment() const
{
return d->hasXiphComment;
}
bool FLAC::File::hasID3v1Tag() const
{
return d->hasID3v1;
}
bool FLAC::File::hasID3v2Tag() const
{
return d->hasID3v2;
}

View File

@ -246,6 +246,21 @@ namespace TagLib {
*/
void addPicture(Picture *picture);
/*!
* Returns whether or not the file on disk contains a Xiph comment.
*/
bool hasXiphComment() const;
/*!
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the file on disk contains an ID3v2 tag.
*/
bool hasID3v2Tag() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -39,7 +39,7 @@ using namespace TagLib;
namespace
{
enum { MPCAPEIndex, MPCID3v1Index };
enum { MPCAPEIndex = 0, MPCID3v1Index = 1 };
}
class MPC::File::FilePrivate
@ -256,6 +256,15 @@ void MPC::File::remove(int tags)
strip(tags);
}
bool MPC::File::hasID3v1Tag() const
{
return d->hasID3v1;
}
bool MPC::File::hasAPETag() const
{
return d->hasAPE;
}
////////////////////////////////////////////////////////////////////////////////
// private members

View File

@ -187,6 +187,16 @@ namespace TagLib {
*/
void remove(int tags = AllTags);
/*!
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the file on disk contains an APE tag.
*/
bool hasAPETag() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -327,17 +327,17 @@ namespace TagLib {
long lastFrameOffset();
/*!
* Returns whether or not the file on disk contains ID3v1 tag.
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the file on disk contains ID3v2 tag.
* Returns whether or not the file on disk contains an ID3v2 tag.
*/
bool hasID3v2Tag() const;
/*!
* Returns whether or not the file on disk contains APE tag.
* Returns whether or not the file on disk contains an APE tag.
*/
bool hasAPETag() const;

View File

@ -287,3 +287,8 @@ void Ogg::FLAC::File::scan()
d->scanned = true;
}
bool Ogg::FLAC::File::hasXiphComment() const
{
return d->hasXiphComment;
}

View File

@ -128,6 +128,11 @@ namespace TagLib {
*/
long streamLength();
/*!
* Returns whether or not the file on disk contains a Xiph comment.
*/
bool hasXiphComment() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -123,6 +123,7 @@ bool RIFF::AIFF::File::save()
return true;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

View File

@ -113,6 +113,11 @@ namespace TagLib {
*/
virtual bool save();
/*!
* Returns whether or not the file on disk contains an ID3v2 tag.
*/
bool hasID3v2Tag() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -45,7 +45,9 @@ class RIFF::WAV::File::FilePrivate
public:
FilePrivate() :
properties(0),
tagChunkID("ID3 ")
tagChunkID("ID3 "),
hasID3v2(false),
hasInfo(false)
{
}
@ -59,6 +61,9 @@ public:
ByteVector tagChunkID;
TagUnion tag;
bool hasID3v2;
bool hasInfo;
};
////////////////////////////////////////////////////////////////////////////////
@ -143,8 +148,10 @@ bool RIFF::WAV::File::save(TagTypes tags, bool stripOthers, int id3v2Version)
ID3v2::Tag *id3v2tag = d->tag.access<ID3v2::Tag>(ID3v2Index, false);
if(!id3v2tag->isEmpty()) {
if(tags & ID3v2)
if(tags & ID3v2) {
setChunkData(d->tagChunkID, id3v2tag->render(id3v2Version));
d->hasID3v2 = true;
}
}
Info::Tag *infotag = d->tag.access<Info::Tag>(InfoIndex, false);
@ -155,12 +162,24 @@ bool RIFF::WAV::File::save(TagTypes tags, bool stripOthers, int id3v2Version)
setChunkData(chunkId, infotag->render());
else
setChunkData("LIST", infotag->render(), true);
d->hasInfo = true;
}
}
return true;
}
bool RIFF::WAV::File::hasID3v2Tag() const
{
return d->hasID3v2;
}
bool RIFF::WAV::File::hasInfoTag() const
{
return d->hasInfo;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
@ -174,6 +193,7 @@ void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle properties
if(name == "ID3 " || name == "id3 ") {
d->tagChunkID = chunkName(i);
d->tag.set(ID3v2Index, new ID3v2::Tag(this, chunkOffset(i)));
d->hasID3v2 = true;
}
else if(name == "fmt " && readProperties)
formatData = chunkData(i);
@ -183,8 +203,10 @@ void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle properties
ByteVector data = chunkData(i);
ByteVector type = data.mid(0, 4);
if(type == "INFO")
if(type == "INFO") {
d->tag.set(InfoIndex, new RIFF::Info::Tag(data));
d->hasInfo = true;
}
}
}

View File

@ -139,6 +139,16 @@ namespace TagLib {
virtual bool save();
bool save(TagTypes tags, bool stripOthers = true, int id3v2Version = 4);
/*!
* Returns whether or not the file on disk contains an ID3v2 tag.
*/
bool hasID3v2Tag() const;
/*!
* Returns whether or not the file on disk contains an RIFF INFO tag.
*/
bool hasInfoTag() const;
private:
File(const File &);

View File

@ -236,6 +236,16 @@ void TrueAudio::File::strip(int tags)
}
}
bool TrueAudio::File::hasID3v1Tag() const
{
return d->hasID3v1;
}
bool TrueAudio::File::hasID3v2Tag() const
{
return d->hasID3v2;
}
////////////////////////////////////////////////////////////////////////////////
// private members

View File

@ -209,7 +209,17 @@ namespace TagLib {
* \note In order to make the removal permanent save() still needs to be called
*/
void strip(int tags = AllTags);
/*!
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the file on disk contains an ID3v2 tag.
*/
bool hasID3v2Tag() const;
private:
File(const File &);
File &operator=(const File &);

View File

@ -231,6 +231,16 @@ void WavPack::File::strip(int tags)
}
}
bool WavPack::File::hasID3v1Tag() const
{
return d->hasID3v1;
}
bool WavPack::File::hasAPETag() const
{
return d->hasAPE;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

View File

@ -173,7 +173,17 @@ namespace TagLib {
* \note In order to make the removal permanent save() still needs to be called
*/
void strip(int tags = AllTags);
/*!
* Returns whether or not the file on disk contains an ID3v1 tag.
*/
bool hasID3v1Tag() const;
/*!
* Returns whether or not the file on disk contains an APE tag.
*/
bool hasAPETag() const;
private:
File(const File &);
File &operator=(const File &);