mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Add a method to check if an MP4 file on disk actually has a tag.
This commit is contained in:
parent
6775cef651
commit
762581fe3f
@ -34,7 +34,7 @@ using namespace TagLib;
|
||||
|
||||
namespace
|
||||
{
|
||||
bool checkValid(const MP4::AtomList &list)
|
||||
inline bool checkValid(const MP4::AtomList &list)
|
||||
{
|
||||
for(MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
||||
|
||||
@ -55,7 +55,8 @@ public:
|
||||
FilePrivate() :
|
||||
tag(0),
|
||||
atoms(0),
|
||||
properties(0) {}
|
||||
properties(0),
|
||||
hasMP4Tag(false) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
@ -67,6 +68,8 @@ public:
|
||||
MP4::Tag *tag;
|
||||
MP4::Atoms *atoms;
|
||||
MP4::Properties *properties;
|
||||
|
||||
bool hasMP4Tag;
|
||||
};
|
||||
|
||||
MP4::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) :
|
||||
@ -130,12 +133,15 @@ MP4::File::read(bool readProperties)
|
||||
}
|
||||
|
||||
// must have a moov atom, otherwise consider it invalid
|
||||
MP4::Atom *moov = d->atoms->find("moov");
|
||||
if(!moov) {
|
||||
if(!d->atoms->find("moov")) {
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if(d->atoms->find("moov", "udta", "meta", "ilst")) {
|
||||
d->hasMP4Tag = true;
|
||||
}
|
||||
|
||||
d->tag = new Tag(this, d->atoms);
|
||||
if(readProperties) {
|
||||
d->properties = new Properties(this, d->atoms);
|
||||
@ -155,6 +161,16 @@ MP4::File::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
return d->tag->save();
|
||||
const bool success = d->tag->save();
|
||||
if(success) {
|
||||
d->hasMP4Tag = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool
|
||||
MP4::File::hasMP4Tag() const
|
||||
{
|
||||
return d->hasMP4Tag;
|
||||
}
|
||||
|
@ -117,6 +117,11 @@ namespace TagLib {
|
||||
*/
|
||||
bool save();
|
||||
|
||||
/*!
|
||||
* Returns whether or not the file on disk actually has an MP4 tag.
|
||||
*/
|
||||
bool hasMP4Tag() const;
|
||||
|
||||
private:
|
||||
void read(bool readProperties);
|
||||
|
||||
|
@ -69,6 +69,10 @@ public:
|
||||
CPPUNIT_ASSERT(!f.isValid());
|
||||
MP4::File f2(TEST_FILE_PATH_C("has-tags.m4a"));
|
||||
CPPUNIT_ASSERT(f2.isValid());
|
||||
CPPUNIT_ASSERT(f2.hasMP4Tag());
|
||||
MP4::File f3(TEST_FILE_PATH_C("no-tags.m4a"));
|
||||
CPPUNIT_ASSERT(f3.isValid());
|
||||
CPPUNIT_ASSERT(!f3.hasMP4Tag());
|
||||
}
|
||||
|
||||
void testIsEmpty()
|
||||
|
Loading…
Reference in New Issue
Block a user