Update taglib

This commit is contained in:
Jonas Kvinge
2019-09-20 18:07:13 +02:00
parent 2d4efd6cf0
commit e7b5e02657
58 changed files with 581 additions and 351 deletions

View File

@@ -89,7 +89,7 @@ namespace TagLib {
* This is an implementation of the ID3v1 format. ID3v1 is both the simplest
* and most common of tag formats but is rather limited. Because of its
* pervasiveness and the way that applications have been written around the
* fields that it provides, the generic Strawberry_TagLib::TagLib::Tag API is a mirror of what is
* fields that it provides, the generic TagLib::Tag API is a mirror of what is
* provided by ID3v1.
*
* ID3v1 tags should generally only contain Latin1 information. However because

View File

@@ -267,7 +267,7 @@ void ChapterFrame::parseFields(const ByteVector &data)
return;
while(embPos < size - header()->size()) {
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), (d->tagHeader != 0));
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), d->tagHeader);
if(!frame)
return;

View File

@@ -132,12 +132,12 @@ namespace TagLib {
/*!
* \deprecated Always returns master volume.
*/
ChannelType channelType() const;
TAGLIB_DEPRECATED ChannelType channelType() const;
/*!
* \deprecated This method no longer has any effect.
*/
void setChannelType(ChannelType t);
TAGLIB_DEPRECATED void setChannelType(ChannelType t);
/*
* There was a terrible API goof here, and while this can't be changed to

View File

@@ -304,7 +304,7 @@ void TableOfContentsFrame::parseFields(const ByteVector &data)
return;
while(embPos < size - header()->size()) {
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), (d->tagHeader != 0));
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), d->tagHeader);
if(!frame)
return;

26
3rdparty/taglib/mpeg/id3v2/id3v2.h vendored Normal file
View File

@@ -0,0 +1,26 @@
#ifndef TAGLIB_ID3V2_H
#define TAGLIB_ID3V2_H
namespace Strawberry_TagLib {
namespace TagLib {
//! An ID3v2 implementation
/*!
* This is a relatively complete and flexible framework for working with ID3v2
* tags.
*
* \see ID3v2::Tag
*/
namespace ID3v2 {
/*!
* Used to specify which version of the ID3 standard to use when saving tags.
*/
enum Version {
v3 = 3, //<! ID3v2.3
v4 = 4 //<! ID3v2.4
};
}
}
}
#endif

View File

@@ -90,14 +90,15 @@ namespace TagLib {
* non-binary compatible release this will be made into a non-static
* member that checks the internal ID3v2 version.
*/
static unsigned int headerSize(); // BIC: remove and make non-static
static unsigned int headerSize(); // BIC: make non-static
/*!
* Returns the size of the frame header for the given ID3v2 version.
*
* \deprecated Please see the explanation above.
*/
static unsigned int headerSize(unsigned int version); // BIC: remove and make non-static
// BIC: remove
static unsigned int headerSize(unsigned int version);
/*!
* Sets the data that will be used as the frame. Since the length is not
@@ -335,7 +336,7 @@ namespace TagLib {
* \deprecated Please use the constructor below that accepts a version
* number.
*/
Header(const ByteVector &data, bool synchSafeInts);
TAGLIB_DEPRECATED Header(const ByteVector &data, bool synchSafeInts);
/*!
* Construct a Frame Header based on \a data. \a data must at least
@@ -412,6 +413,7 @@ namespace TagLib {
* removed in the next binary incompatible release (2.0) and will be
* replaced with a non-static method that checks the frame version.
*/
// BIC: make non-static
static unsigned int size();
/*!
@@ -420,6 +422,7 @@ namespace TagLib {
*
* \deprecated Please see the explanation in the version above.
*/
// BIC: remove
static unsigned int size(unsigned int version);
/*!
@@ -503,7 +506,7 @@ namespace TagLib {
/*!
* \deprecated
*/
bool frameAlterPreservation() const;
TAGLIB_DEPRECATED bool frameAlterPreservation() const;
private:
Header(const Header &);

View File

@@ -126,6 +126,11 @@ Frame *FrameFactory::createFrame(const ByteVector &data, unsigned int version) c
}
Frame *FrameFactory::createFrame(const ByteVector &origData, Header *tagHeader) const
{
return createFrame(origData, const_cast<const Header *>(tagHeader));
}
Frame *FrameFactory::createFrame(const ByteVector &origData, const Header *tagHeader) const
{
ByteVector data = origData;
unsigned int version = tagHeader->majorVersion();

View File

@@ -87,12 +87,17 @@ namespace TagLib {
*/
Frame *createFrame(const ByteVector &data, unsigned int version = 4) const;
/*!
* \deprecated
*/
// BIC: remove
Frame *createFrame(const ByteVector &data, Header *tagHeader) const;
/*!
* Create a frame based on \a data. \a tagHeader should be a valid
* ID3v2::Header instance.
*/
// BIC: make virtual
Frame *createFrame(const ByteVector &data, Header *tagHeader) const;
Frame *createFrame(const ByteVector &data, const Header *tagHeader) const;
/*!
* After a tag has been read, this tries to rebuild some of them

View File

@@ -207,14 +207,14 @@ void Header::parse(const ByteVector &data)
if(sizeData.size() != 4) {
d->tagSize = 0;
debug("Strawberry_TagLib::TagLib::ID3v2::Header::parse() - The tag size as read was 0 bytes!");
debug("TagLib::ID3v2::Header::parse() - The tag size as read was 0 bytes!");
return;
}
for(ByteVector::ConstIterator it = sizeData.begin(); it != sizeData.end(); it++) {
if(static_cast<unsigned char>(*it) >= 128) {
d->tagSize = 0;
debug("Strawberry_TagLib::TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
return;
}
}

View File

@@ -28,6 +28,7 @@
#include "tbytevector.h"
#include "taglib_export.h"
#include "id3v2.h"
namespace Strawberry_TagLib {
namespace TagLib {

View File

@@ -462,7 +462,7 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
ByteVector ID3v2::Tag::render() const
{
return render(4);
return render(ID3v2::v4);
}
void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
@@ -568,17 +568,17 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
}
ByteVector ID3v2::Tag::render(int version) const
{
return render(version == 3 ? v3 : v4);
}
ByteVector ID3v2::Tag::render(Version version) const
{
// We need to render the "tag data" first so that we have to correct size to
// render in the tag's header. The "tag data" -- everything that is included
// in ID3v2::Header::tagSize() -- includes the extended header, frames and
// padding, but does not include the tag's header or footer.
if(version != 3 && version != 4) {
debug("Unknown ID3v2 version, using ID3v2.4");
version = 4;
}
// TODO: Render the extended header.
// Downgrade the frames that ID3v2.3 doesn't support.
@@ -587,7 +587,7 @@ ByteVector ID3v2::Tag::render(int version) const
newFrames.setAutoDelete(true);
FrameList frameList;
if(version == 4) {
if(version == v4) {
frameList = d->frameList;
}
else {
@@ -601,7 +601,7 @@ ByteVector ID3v2::Tag::render(int version) const
// Loop through the frames rendering them and adding them to the tagData.
for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) {
(*it)->header()->setVersion(version);
(*it)->header()->setVersion(version == v3 ? 3 : 4);
if((*it)->header()->frameID().size() != 4) {
debug("An ID3v2 frame of unsupported or unknown type \'"
+ String((*it)->header()->frameID()) + "\' has been discarded");

View File

@@ -33,6 +33,7 @@
#include "tmap.h"
#include "taglib_export.h"
#include "id3v2.h"
#include "id3v2framefactory.h"
namespace Strawberry_TagLib {
@@ -40,15 +41,6 @@ namespace TagLib {
class File;
//! An ID3v2 implementation
/*!
* This is a relatively complete and flexible framework for working with ID3v2
* tags.
*
* \see ID3v2::Tag
*/
namespace ID3v2 {
class Header;
@@ -126,7 +118,7 @@ namespace TagLib {
* heart and should not be done without much meditation on the spec. It's
* rather long, but if you're planning on messing with this class and others
* that deal with the details of ID3v2 (rather than the nice, safe, abstract
* Strawberry_TagLib::TagLib::Tag and friends), it's worth your time to familiarize yourself
* TagLib::Tag and friends), it's worth your time to familiarize yourself
* with said spec (which is distributed with the TagLib sources). TagLib
* tries to do most of the work, but with a little luck, you can still
* convince it to generate invalid ID3v2 tags. The APIs for ID3v2 assume a
@@ -202,7 +194,7 @@ namespace TagLib {
* prone to change my mind, so this gets to stay around until near a
* release.
*/
Footer *footer() const;
TAGLIB_DEPRECATED Footer *footer() const;
/*!
* Returns a reference to the frame list map. This is an FrameListMap of
@@ -217,7 +209,7 @@ namespace TagLib {
* beats per minute -- the TBPM frame.
*
* \code
* Strawberry_TagLib::TagLib::MPEG::File f("foo.mp3");
* TagLib::MPEG::File f("foo.mp3");
*
* // Check to make sure that it has an ID3v2 tag
*
@@ -225,7 +217,7 @@ namespace TagLib {
*
* // Get the list of frames for a specific frame type
*
* Strawberry_TagLib::TagLib::ID3v2::FrameList l = f.ID3v2Tag()->frameListMap()["TBPM"];
* TagLib::ID3v2::FrameList l = f.ID3v2Tag()->frameListMap()["TBPM"];
*
* if(!l.isEmpty())
* std::cout << l.front()->toString() << std::endl;
@@ -346,14 +338,18 @@ namespace TagLib {
*/
ByteVector render() const;
/*!
* \deprecated
*/
TAGLIB_DEPRECATED ByteVector render(int version) const;
/*!
* Render the tag back to binary data, suitable to be written to disk.
*
* The \a version parameter specifies the version of the rendered
* ID3v2 tag. It can be either 4 or 3.
* The \a version parameter specifies whether ID3v2.4 (default) or ID3v2.3
* should be used.
*/
// BIC: combine with the above method
ByteVector render(int version) const;
ByteVector render(Version version) const;
/*!
* Gets the current string handler that decides how the "Latin-1" data
@@ -397,6 +393,9 @@ namespace TagLib {
*/
void setTextFrame(const ByteVector &id, const String &value);
/*!
* Dowgrade frames from ID3v2.4 (used internally and by default) to ID3v2.3
*/
void downgradeFrames(FrameList *existingFrames, FrameList *newFrames) const;
private:

View File

@@ -182,7 +182,7 @@ PropertyMap MPEG::File::setProperties(const PropertyMap &properties)
{
// update ID3v1 tag if it exists, but ignore the return value
if(hasID3v1Tag())
if(ID3v1Tag())
ID3v1Tag()->setProperties(properties);
return ID3v2Tag(true)->setProperties(properties);
@@ -195,29 +195,35 @@ MPEG::Properties *MPEG::File::audioProperties() const
bool MPEG::File::save()
{
if (hasID3v1Tag() || !ID3v1Tag()->isEmpty()) {
return save(AllTags, true, 4, true);
} else {
return save(AllTags, true, 4, false);
}
return save(AllTags);
}
bool MPEG::File::save(int tags)
{
return save(tags, true);
return save(tags, StripOthers);
}
bool MPEG::File::save(int tags, bool stripOthers)
{
return save(tags, stripOthers, 4);
return save(tags, stripOthers ? StripOthers : StripNone, ID3v2::v4);
}
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version)
{
return save(tags, stripOthers, id3v2Version, true);
return save(tags,
stripOthers ? StripOthers : StripNone,
id3v2Version == 3 ? ID3v2::v3 : ID3v2::v4);
}
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags)
{
return save(tags,
stripOthers ? StripOthers : StripNone,
id3v2Version == 3 ? ID3v2::v3 : ID3v2::v4,
duplicateTags ? Duplicate : DoNotDuplicate);
}
bool MPEG::File::save(int tags, StripTags strip, ID3v2::Version version, DuplicateTags duplicate)
{
if(readOnly()) {
debug("MPEG::File::save() -- File is read only.");
@@ -226,22 +232,22 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// Create the tags if we've been asked to.
if(duplicateTags) {
if(duplicate == Duplicate) {
// Copy the values from the tag that does exist into the new tag,
// except if the existing tag is to be stripped.
if((tags & ID3v2) && ID3v1Tag() && !(stripOthers && !(tags & ID3v1)))
if((tags & ID3v2) && ID3v1Tag() && !(strip == StripOthers && !(tags & ID3v1)))
Tag::duplicate(ID3v1Tag(), ID3v2Tag(true), false);
if((tags & ID3v1) && d->tag[ID3v2Index] && !(stripOthers && !(tags & ID3v2)))
if((tags & ID3v1) && d->tag[ID3v2Index] && !(strip == StripOthers && !(tags & ID3v2)))
Tag::duplicate(ID3v2Tag(), ID3v1Tag(true), false);
}
// Remove all the tags not going to be saved.
if(stripOthers)
strip(~tags, false);
if(strip == StripOthers)
File::strip(~tags, false);
if(ID3v2 & tags) {
@@ -252,7 +258,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
if(d->ID3v2Location < 0)
d->ID3v2Location = 0;
const ByteVector data = ID3v2Tag()->render(id3v2Version);
const ByteVector data = ID3v2Tag()->render(version);
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
if(d->APELocation >= 0)
@@ -267,7 +273,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// ID3v2 tag is empty. Remove the old one.
strip(ID3v2, false);
File::strip(ID3v2, false);
}
}
@@ -291,7 +297,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// ID3v1 tag is empty. Remove the old one.
strip(ID3v1, false);
File::strip(ID3v1, false);
}
}
@@ -320,7 +326,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// APE tag is empty. Remove the old one.
strip(APE, false);
File::strip(APE, false);
}
}

View File

@@ -32,6 +32,8 @@
#include "mpegproperties.h"
#include "id3v2.h"
namespace Strawberry_TagLib {
namespace TagLib {
@@ -39,14 +41,14 @@ namespace TagLib {
namespace ID3v1 { class Tag; }
namespace APE { class Tag; }
//! An implementation of Strawberry_TagLib::TagLib::File with MPEG (MP3) specific methods
//! An implementation of TagLib::File with MPEG (MP3) specific methods
namespace MPEG {
//! An MPEG file class with some useful methods specific to MPEG
/*!
* This implements the generic Strawberry_TagLib::TagLib::File API and additionally provides
* This implements the generic TagLib::File API and additionally provides
* access to properties that are distinct to MPEG files, notably access
* to the different ID3 tags.
*/
@@ -164,15 +166,14 @@ namespace TagLib {
virtual Properties *audioProperties() const;
/*!
* Save the file. If an ID3v1 tag exists this will duplicate the tag
* content into the other tag. This returns true if saving was
* successful.
* Save the file. If at least one tag -- ID3v1 or ID3v2 -- exists this
* will duplicate its content into the other tag. This returns true
* if saving was successful.
*
* If neither exists or if both tags are empty, this will strip the tags
* from the file.
*
* This is the same as calling save(AllTags, true, 4, false); or if an
* ID3v1 tag exists, save(AllTags, true, 4, true).
* This is the same as calling save(AllTags);
*
* If you would like more granular control over the content of the tags,
* with the concession of generality, use parameterized save call below.
@@ -193,49 +194,39 @@ namespace TagLib {
bool save(int tags);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
* \deprecated
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers);
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers);
/*!
* \deprecated
*/
// BIC: combine with the above method
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers, int id3v2Version);
/*!
* \deprecated
*/
// BIC: combine with the above method
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
* specified by OR-ing together TagTypes values.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
* \a strip can be set to strip all tags except those in \a tags. Those
* tags will not be modified in memory, and thus remain valid.
*
* The \a id3v2Version parameter specifies the version of the saved
* ID3v2 tag. It can be either 4 or 3.
* \a version specifies the ID3v2 version to be used for writing tags. By
* default, the latest standard, ID3v2.4 is used.
*
* If \a duplicate is set to DuplicateTags and at least one tag -- ID3v1
* or ID3v2 -- exists this will duplicate its content into the other tag.
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers, int id3v2Version);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
*
* The \a id3v2Version parameter specifies the version of the saved
* ID3v2 tag. It can be either 4 or 3.
*
* If \a duplicateTags is true and at least one tag -- ID3v1 or ID3v2 --
* exists this will duplicate its content into the other tag.
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
bool save(int tags, StripTags strip,
ID3v2::Version version = ID3v2::v4,
DuplicateTags duplicate = Duplicate);
/*!
* Returns a pointer to the ID3v2 tag of the file.
@@ -327,7 +318,7 @@ namespace TagLib {
* \see ID3v2FrameFactory
* \deprecated This value should be passed in via the constructor
*/
void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
TAGLIB_DEPRECATED void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
/*!
* Returns the position in the file of the first MPEG frame.

View File

@@ -53,7 +53,7 @@ namespace TagLib {
*
* \deprecated
*/
Header(const ByteVector &data);
TAGLIB_DEPRECATED Header(const ByteVector &data);
/*!
* Parses an MPEG header based on \a file and \a offset.

View File

@@ -112,7 +112,7 @@ namespace TagLib {
*
* \deprecated Always returns 0.
*/
static int xingHeaderOffset(Strawberry_TagLib::TagLib::MPEG::Header::Version v,
TAGLIB_DEPRECATED static int xingHeaderOffset(Strawberry_TagLib::TagLib::MPEG::Header::Version v,
Strawberry_TagLib::TagLib::MPEG::Header::ChannelMode c);
private: