From 772bc9f7c4f3d0024bd7bc3b8f4ae4afcbd94337 Mon Sep 17 00:00:00 2001 From: Michael Helmling Date: Mon, 12 Sep 2011 21:52:11 +0200 Subject: [PATCH] Further cleanup and simplification in id3v2dicttools --- taglib/mpeg/id3v2/id3v2dicttools.cpp | 81 +++++++++++----------------- taglib/mpeg/id3v2/id3v2dicttools.h | 23 ++++++-- taglib/mpeg/id3v2/id3v2tag.cpp | 7 +-- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/taglib/mpeg/id3v2/id3v2dicttools.cpp b/taglib/mpeg/id3v2/id3v2dicttools.cpp index 172b4afb..498f92ed 100644 --- a/taglib/mpeg/id3v2/id3v2dicttools.cpp +++ b/taglib/mpeg/id3v2/id3v2dicttools.cpp @@ -33,30 +33,27 @@ #include "frames/unsynchronizedlyricsframe.h" #include "id3v1genres.h" -using namespace TagLib; -using namespace ID3v2; - -// list of deprecated frames and their successors -static const uint deprecatedFramesSize = 4; -static const char *deprecatedFrames[][2] = { - {"TRDA", "TDRC"}, // 2.3 -> 2.4 (http://en.wikipedia.org/wiki/ID3) - {"TDAT", "TDRC"}, // 2.3 -> 2.4 - {"TYER", "TDRC"}, // 2.3 -> 2.4 - {"TIME", "TDRC"}, // 2.3 -> 2.4 -}; - -FrameIDMap deprecationMap() -{ - static FrameIDMap depMap; - if (depMap.isEmpty()) - for(uint i = 0; i < deprecatedFramesSize; ++i) - depMap[deprecatedFrames[i][0]] = deprecatedFrames[i][1]; - return depMap; -} - namespace TagLib { namespace ID3v2 { + // list of deprecated frames and their successors + static const uint deprecatedFramesSize = 4; + static const char *deprecatedFrames[][2] = { + {"TRDA", "TDRC"}, // 2.3 -> 2.4 (http://en.wikipedia.org/wiki/ID3) + {"TDAT", "TDRC"}, // 2.3 -> 2.4 + {"TYER", "TDRC"}, // 2.3 -> 2.4 + {"TIME", "TDRC"}, // 2.3 -> 2.4 + }; + + FrameIDMap &deprecationMap() + { + static FrameIDMap depMap; + if (depMap.isEmpty()) + for(uint i = 0; i < deprecatedFramesSize; ++i) + depMap[deprecatedFrames[i][0]] = deprecatedFrames[i][1]; + return depMap; + } + /*! * A map of translations frameID <-> tag used by the unified dictionary interface. */ @@ -127,32 +124,24 @@ namespace TagLib { { "USLT", "LYRICS" }, }; - // list of frameIDs that are ignored by the unified dictionary interface - static const uint ignoredFramesSize = 7; - static const char *ignoredFrames[] = { - "TCMP", // illegal 'Part of Compilation' frame set by iTunes (see http://www.id3.org/Compliance_Issues) - "GEOB", // no way to handle a general encapsulated object by the dict interface - "PRIV", // private frames - "APIC", // attached picture -- TODO how could we do this? - "POPM", // popularimeter - "RVA2", // relative volume - "UFID", // unique file identifier - }; - + Map &idMap() + { + static Map m; + if (m.isEmpty()) + for (size_t i = 0; i < numid3frames; ++i) + m[id3frames[i][0]] = id3frames[i][1]; + return m; + } String frameIDToTagName(const ByteVector &id) { - static Map m; - if (m.isEmpty()) - for (size_t i = 0; i < numid3frames; ++i) - m[id3frames[i][0]] = id3frames[i][1]; - + Map &m = idMap(); if (m.contains(id)) return m[id]; if (deprecationMap().contains(id)) return m[deprecationMap()[id]]; - debug("unknown frame ID: " + id); - return "UNKNOWNID3TAG"; //TODO: implement this nicer + debug("unknown frame ID in frameIDToTagName(): " + id); + return "UNKNOWNID3TAG#" + String(id) + "#"; //TODO: implement this nicer } ByteVector tagNameToFrameID(const String &s) @@ -166,18 +155,12 @@ namespace TagLib { return "TXXX"; } - bool isIgnored(const ByteVector& id) + bool ignored(const ByteVector& id) { - List ignoredList; - if (ignoredList.isEmpty()) - for (uint i = 0; i < ignoredFramesSize; ++i) - ignoredList.append(ignoredFrames[i]); - return ignoredList.contains(id); + return !(id == "TXXX") && !idMap().contains(id) && !deprecated(id); } - - - bool isDeprecated(const ByteVector& id) + bool deprecated(const ByteVector& id) { return deprecationMap().contains(id); } diff --git a/taglib/mpeg/id3v2/id3v2dicttools.h b/taglib/mpeg/id3v2/id3v2dicttools.h index 5963618a..1f831c63 100644 --- a/taglib/mpeg/id3v2/id3v2dicttools.h +++ b/taglib/mpeg/id3v2/id3v2dicttools.h @@ -41,7 +41,6 @@ namespace TagLib { typedef Map FrameIDMap; typedef std::pair KeyValuePair; - // forward declaration class Frame; /*! * Returns an appropriate ID3 frame ID for the given free-form tag name. This method @@ -58,11 +57,27 @@ namespace TagLib { /*! * Tell if the given frame ID is ignored by the unified dictionary subsystem. This is true * for frames that don't admit a textual representation, such as pictures or other binary - * information. + * information, as well as invalid frames that violate the ID3 specification. + * + * These include: + * - illegal frames violating the specification but seem to be used by some applications, e.g. + * "TCMP", illegal 'Part of Compilation' frame set by iTunes (see http://www.id3.org/Compliance_Issues) + * "NCON", illegal MusicMatch frame (see http://www.id3.org/Compliance_Issues) + * + * - frames without a meaningful textual representation -- might be implemented in some future release + * "GEOB", no way to handle a general encapsulated object by the dict interface + * "PRIV", private frames + * "APIC", attached picture + * "POPM", popularimeter + * "RVA2", relative volume + * "UFID", unique file identifier */ - bool TAGLIB_EXPORT isIgnored(const ByteVector &); + bool TAGLIB_EXPORT ignored(const ByteVector &); - bool TAGLIB_EXPORT isDeprecated(const ByteVector&); + /*! + * Returns true if the given frame ID is deprecated according to the most recent ID3v2 standard. + */ + bool TAGLIB_EXPORT deprecated(const ByteVector&); /*! * Parse the ID3v2::Frame *Frame* to a pair of a human-readable key (e.g. ARTIST) and diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 84c89a47..9c5e50f4 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -40,6 +40,7 @@ #include "frames/urllinkframe.h" #include "frames/uniquefileidentifierframe.h" #include "frames/unsynchronizedlyricsframe.h" +#include "frames/unknownframe.h" using namespace TagLib; using namespace ID3v2; @@ -340,9 +341,9 @@ TagDict ID3v2::Tag::toDict() const for (; frameIt != frameList().end(); ++frameIt) { ByteVector id = (*frameIt)->frameID(); - if (isIgnored(id)) + if (ignored(id)) debug("toDict() found ignored id3 frame: " + id); - else if (isDeprecated(id)) + else if (deprecated(id)) debug("toDict() found deprecated id3 frame: " + id); else { // in the future, something like dict[frame->tagName()].append(frame->values()) @@ -362,7 +363,7 @@ void ID3v2::Tag::fromDict(const TagDict &dict) // for (FrameListMap::ConstIterator it = frameListMap().begin(); it != frameListMap().end(); ++it) // Remove all frames which are not ignored - if (it->second.size() == 0 || !isIgnored(it->first)) + if (it->second.size() == 0 || !ignored(it->first) ) toRemove.append(it->second); for (FrameList::ConstIterator it = toRemove.begin(); it != toRemove.end(); it++)