Several classes have exactly identical functions for finding tags.
This also hides the functions from public headers.
tagunion.cpp
fileref.cpp
audioproperties.cpp
+ tagutils.cpp
)
add_library(tag ${tag_LIB_SRCS} ${tag_HDRS})
#include <id3v1tag.h>
#include <id3v2header.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "apefile.h"
-
#include "apetag.h"
#include "apefooter.h"
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location);
// Look for an ID3v1 tag
- d->ID3v1Location = findID3v1();
+ d->ID3v1Location = Utils::findID3v1(this);
if(d->ID3v1Location >= 0) {
d->tag.set(ApeID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
// Look for an APE tag
- d->APELocation = findAPE();
+ d->APELocation = Utils::findAPE(this, d->ID3v1Location);
if(d->APELocation >= 0) {
d->tag.set(ApeAPEIndex, new APE::Tag(this, d->APELocation));
d->properties = new Properties(this, streamLength);
}
}
-
-long APE::File::findAPE()
-{
- if(!isValid())
- return -1;
-
- if(d->hasID3v1)
- seek(-160, End);
- else
- seek(-32, End);
-
- long p = tell();
-
- if(readBlock(8) == APE::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long APE::File::findID3v1()
-{
- if(!isValid())
- return -1;
-
- seek(-128, End);
- long p = tell();
-
- if(readBlock(3) == ID3v1::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long APE::File::findID3v2()
-{
- if(!isValid())
- return -1;
-
- seek(0);
-
- if(readBlock(3) == ID3v2::Header::fileIdentifier())
- return 0;
-
- return -1;
-}
File &operator=(const File &);
void read(bool readProperties);
- long findAPE();
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
#include <tdebug.h>
#include <tagunion.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include <id3v2header.h>
#include <id3v2tag.h>
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
// Look for an ID3v1 tag
- d->ID3v1Location = findID3v1();
+ d->ID3v1Location = Utils::findID3v1(this);
if(d->ID3v1Location >= 0) {
d->tag.set(FlacID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
d->scanned = true;
}
-
-long FLAC::File::findID3v1()
-{
- if(!isValid())
- return -1;
-
- seek(-128, End);
- long p = tell();
-
- if(readBlock(3) == ID3v1::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long FLAC::File::findID3v2()
-{
- if(!isValid())
- return -1;
-
- seek(0);
-
- if(readBlock(3) == ID3v2::Header::fileIdentifier())
- return 0;
-
- return -1;
-}
void read(bool readProperties);
void scan();
- long findID3v2();
- long findID3v1();
class FilePrivate;
FilePrivate *d;
#include <tagunion.h>
#include <tdebug.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "mpcfile.h"
#include "id3v1tag.h"
{
// Look for an ID3v1 tag
- d->ID3v1Location = findID3v1();
+ d->ID3v1Location = Utils::findID3v1(this);
if(d->ID3v1Location >= 0) {
d->tag.set(MPCID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
// Look for an APE tag
- d->APELocation = findAPE();
+ d->APELocation = Utils::findAPE(this, d->ID3v1Location);
if(d->APELocation >= 0) {
d->tag.set(MPCAPEIndex, new APE::Tag(this, d->APELocation));
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location);
d->properties = new Properties(this, streamLength);
}
}
-
-long MPC::File::findAPE()
-{
- if(!isValid())
- return -1;
-
- if(d->hasID3v1)
- seek(-160, End);
- else
- seek(-32, End);
-
- long p = tell();
-
- if(readBlock(8) == APE::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long MPC::File::findID3v1()
-{
- if(!isValid())
- return -1;
-
- seek(-128, End);
- long p = tell();
-
- if(readBlock(3) == ID3v1::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long MPC::File::findID3v2()
-{
- if(!isValid())
- return -1;
-
- seek(0);
-
- if(readBlock(3) == ID3v2::Header::fileIdentifier())
- return 0;
-
- return -1;
-}
File &operator=(const File &);
void read(bool readProperties);
- long findAPE();
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
--- /dev/null
+/***************************************************************************
+ copyright : (C) 2015 by Tsuda Kageyu
+ email : tsuda.kageyu@gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#include <tfile.h>
+
+#include "id3v1tag.h"
+#include "id3v2header.h"
+#include "apetag.h"
+
+#include "tagutils.h"
+
+using namespace TagLib;
+
+long Utils::findID3v1(File *file)
+{
+ if(!file->isValid())
+ return -1;
+
+ file->seek(-128, File::End);
+ const long p = file->tell();
+
+ if(file->readBlock(3) == ID3v1::Tag::fileIdentifier())
+ return p;
+
+ return -1;
+}
+
+long Utils::findID3v2(File *file)
+{
+ if(!file->isValid())
+ return -1;
+
+ file->seek(0);
+
+ if(file->readBlock(3) == ID3v2::Header::fileIdentifier())
+ return 0;
+
+ return -1;
+}
+
+long Utils::findAPE(File *file, long id3v1Location)
+{
+ if(!file->isValid())
+ return -1;
+
+ if(id3v1Location >= 0)
+ file->seek(id3v1Location - 32, File::Beginning);
+ else
+ file->seek(-32, File::End);
+
+ const long p = file->tell();
+
+ if(file->readBlock(8) == APE::Tag::fileIdentifier())
+ return p;
+
+ return -1;
+}
--- /dev/null
+/***************************************************************************
+ copyright : (C) 2015 by Tsuda Kageyu
+ email : tsuda.kageyu@gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#ifndef TAGLIB_TAGUTILS_H
+#define TAGLIB_TAGUTILS_H
+
+// THIS FILE IS NOT A PART OF THE TAGLIB API
+
+#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header
+
+namespace TagLib {
+
+ class File;
+
+ namespace Utils {
+
+ long findID3v1(File *file);
+
+ long findID3v2(File *file);
+
+ long findAPE(File *file, long id3v1Location);
+ }
+}
+
+#endif
+
+#endif
#include <tagunion.h>
#include <tstringlist.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "trueaudiofile.h"
#include "id3v1tag.h"
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
// Look for an ID3v1 tag
- d->ID3v1Location = findID3v1();
+ d->ID3v1Location = Utils::findID3v1(this);
if(d->ID3v1Location >= 0) {
d->tag.set(TrueAudioID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
d->properties = new Properties(readBlock(TrueAudio::HeaderSize), streamLength);
}
}
-
-long TrueAudio::File::findID3v1()
-{
- if(!isValid())
- return -1;
-
- seek(-128, End);
- long p = tell();
-
- if(readBlock(3) == ID3v1::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long TrueAudio::File::findID3v2()
-{
- if(!isValid())
- return -1;
-
- seek(0);
-
- if(readBlock(3) == ID3v2::Header::fileIdentifier())
- return 0;
-
- return -1;
-}
File &operator=(const File &);
void read(bool readProperties);
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
#include <tdebug.h>
#include <tagunion.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "wavpackfile.h"
#include "id3v1tag.h"
{
// Look for an ID3v1 tag
- d->ID3v1Location = findID3v1();
+ d->ID3v1Location = Utils::findID3v1(this);
if(d->ID3v1Location >= 0) {
d->tag.set(WavID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
// Look for an APE tag
- d->APELocation = findAPE();
+ d->APELocation = Utils::findAPE(this, d->ID3v1Location);
if(d->APELocation >= 0) {
d->tag.set(WavAPEIndex, new APE::Tag(this, d->APELocation));
d->properties = new Properties(this, streamLength);
}
}
-
-long WavPack::File::findAPE()
-{
- if(!isValid())
- return -1;
-
- if(d->hasID3v1)
- seek(-160, End);
- else
- seek(-32, End);
-
- long p = tell();
-
- if(readBlock(8) == APE::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
-
-long WavPack::File::findID3v1()
-{
- if(!isValid())
- return -1;
-
- seek(-128, End);
- long p = tell();
-
- if(readBlock(3) == ID3v1::Tag::fileIdentifier())
- return p;
-
- return -1;
-}
File &operator=(const File &);
void read(bool readProperties);
- long findID3v1();
- long findAPE();
class FilePrivate;
FilePrivate *d;