aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTsuda Kageyu <tsuda.kageyu@gmail.com>2015-11-21 09:30:04 +0900
committerTsuda Kageyu <tsuda.kageyu@gmail.com>2015-11-21 09:30:04 +0900
commitb592f78238830ea99030255c52aa9cc215666040 (patch)
tree8d4ffa31200e270b18fbf9837ca77521f26d6e69
parentce1c03faa38aa38a5719afe9ff135a3151d4b6d4 (diff)
Unify common functions for finding tags.
Several classes have exactly identical functions for finding tags. This also hides the functions from public headers.
-rw-r--r--taglib/CMakeLists.txt1
-rw-r--r--taglib/ape/apefile.cpp53
-rw-r--r--taglib/ape/apefile.h3
-rw-r--r--taglib/flac/flacfile.cpp32
-rw-r--r--taglib/flac/flacfile.h2
-rw-r--r--taglib/mpc/mpcfile.cpp52
-rw-r--r--taglib/mpc/mpcfile.h3
-rw-r--r--taglib/tagutils.cpp79
-rw-r--r--taglib/tagutils.h49
-rw-r--r--taglib/trueaudio/trueaudiofile.cpp32
-rw-r--r--taglib/trueaudio/trueaudiofile.h2
-rw-r--r--taglib/wavpack/wavpackfile.cpp37
-rw-r--r--taglib/wavpack/wavpackfile.h2
13 files changed, 146 insertions, 201 deletions
diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt
index 31e2c49b..5a047bf1 100644
--- a/taglib/CMakeLists.txt
+++ b/taglib/CMakeLists.txt
@@ -334,6 +334,7 @@ set(tag_LIB_SRCS
tagunion.cpp
fileref.cpp
audioproperties.cpp
+ tagutils.cpp
)
add_library(tag ${tag_LIB_SRCS} ${tag_HDRS})
diff --git a/taglib/ape/apefile.cpp b/taglib/ape/apefile.cpp
index 1349dfa3..caefe737 100644
--- a/taglib/ape/apefile.cpp
+++ b/taglib/ape/apefile.cpp
@@ -38,9 +38,9 @@
#include <id3v1tag.h>
#include <id3v2header.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "apefile.h"
-
#include "apetag.h"
#include "apefooter.h"
@@ -258,7 +258,7 @@ void APE::File::read(bool readProperties)
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location);
@@ -269,7 +269,7 @@ void APE::File::read(bool readProperties)
// 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));
@@ -278,7 +278,7 @@ void APE::File::read(bool readProperties)
// 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));
@@ -314,48 +314,3 @@ void APE::File::read(bool readProperties)
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;
-}
diff --git a/taglib/ape/apefile.h b/taglib/ape/apefile.h
index 1d2e5c67..e638d865 100644
--- a/taglib/ape/apefile.h
+++ b/taglib/ape/apefile.h
@@ -219,9 +219,6 @@ namespace TagLib {
File &operator=(const File &);
void read(bool readProperties);
- long findAPE();
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp
index dc8f4011..252907d0 100644
--- a/taglib/flac/flacfile.cpp
+++ b/taglib/flac/flacfile.cpp
@@ -29,6 +29,7 @@
#include <tdebug.h>
#include <tagunion.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include <id3v2header.h>
#include <id3v2tag.h>
@@ -362,7 +363,7 @@ void FLAC::File::read(bool readProperties)
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
@@ -378,7 +379,7 @@ void FLAC::File::read(bool readProperties)
// 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));
@@ -539,30 +540,3 @@ void FLAC::File::scan()
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;
-}
diff --git a/taglib/flac/flacfile.h b/taglib/flac/flacfile.h
index 1c055d33..6cbcb5a0 100644
--- a/taglib/flac/flacfile.h
+++ b/taglib/flac/flacfile.h
@@ -295,8 +295,6 @@ namespace TagLib {
void read(bool readProperties);
void scan();
- long findID3v2();
- long findID3v1();
class FilePrivate;
FilePrivate *d;
diff --git a/taglib/mpc/mpcfile.cpp b/taglib/mpc/mpcfile.cpp
index 6d8dae5a..1d798212 100644
--- a/taglib/mpc/mpcfile.cpp
+++ b/taglib/mpc/mpcfile.cpp
@@ -28,6 +28,7 @@
#include <tagunion.h>
#include <tdebug.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "mpcfile.h"
#include "id3v1tag.h"
@@ -266,7 +267,7 @@ void MPC::File::read(bool readProperties)
{
// 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));
@@ -275,7 +276,7 @@ void MPC::File::read(bool readProperties)
// 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));
@@ -290,7 +291,7 @@ void MPC::File::read(bool readProperties)
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location);
@@ -323,48 +324,3 @@ void MPC::File::read(bool readProperties)
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;
-}
diff --git a/taglib/mpc/mpcfile.h b/taglib/mpc/mpcfile.h
index 0980a5cd..98e7480f 100644
--- a/taglib/mpc/mpcfile.h
+++ b/taglib/mpc/mpcfile.h
@@ -222,9 +222,6 @@ namespace TagLib {
File &operator=(const File &);
void read(bool readProperties);
- long findAPE();
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
diff --git a/taglib/tagutils.cpp b/taglib/tagutils.cpp
new file mode 100644
index 00000000..dc047040
--- /dev/null
+++ b/taglib/tagutils.cpp
@@ -0,0 +1,79 @@
+/***************************************************************************
+ 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;
+}
diff --git a/taglib/tagutils.h b/taglib/tagutils.h
new file mode 100644
index 00000000..fb11d1e0
--- /dev/null
+++ b/taglib/tagutils.h
@@ -0,0 +1,49 @@
+/***************************************************************************
+ 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
diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp
index 4ca60915..0ff3fa5e 100644
--- a/taglib/trueaudio/trueaudiofile.cpp
+++ b/taglib/trueaudio/trueaudiofile.cpp
@@ -33,6 +33,7 @@
#include <tagunion.h>
#include <tstringlist.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "trueaudiofile.h"
#include "id3v1tag.h"
@@ -248,7 +249,7 @@ void TrueAudio::File::read(bool readProperties)
{
// Look for an ID3v2 tag
- d->ID3v2Location = findID3v2();
+ d->ID3v2Location = Utils::findID3v2(this);
if(d->ID3v2Location >= 0) {
@@ -264,7 +265,7 @@ void TrueAudio::File::read(bool readProperties)
// 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));
@@ -296,30 +297,3 @@ void TrueAudio::File::read(bool readProperties)
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;
-}
diff --git a/taglib/trueaudio/trueaudiofile.h b/taglib/trueaudio/trueaudiofile.h
index 3fc515f6..4bcb722a 100644
--- a/taglib/trueaudio/trueaudiofile.h
+++ b/taglib/trueaudio/trueaudiofile.h
@@ -240,8 +240,6 @@ namespace TagLib {
File &operator=(const File &);
void read(bool readProperties);
- long findID3v1();
- long findID3v2();
class FilePrivate;
FilePrivate *d;
diff --git a/taglib/wavpack/wavpackfile.cpp b/taglib/wavpack/wavpackfile.cpp
index 90f79d16..7273e103 100644
--- a/taglib/wavpack/wavpackfile.cpp
+++ b/taglib/wavpack/wavpackfile.cpp
@@ -32,6 +32,7 @@
#include <tdebug.h>
#include <tagunion.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "wavpackfile.h"
#include "id3v1tag.h"
@@ -243,7 +244,7 @@ void WavPack::File::read(bool readProperties)
{
// 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));
@@ -252,7 +253,7 @@ void WavPack::File::read(bool readProperties)
// 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));
@@ -280,35 +281,3 @@ void WavPack::File::read(bool readProperties)
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;
-}
diff --git a/taglib/wavpack/wavpackfile.h b/taglib/wavpack/wavpackfile.h
index 24511581..abcabd94 100644
--- a/taglib/wavpack/wavpackfile.h
+++ b/taglib/wavpack/wavpackfile.h
@@ -208,8 +208,6 @@ namespace TagLib {
File &operator=(const File &);
void read(bool readProperties);
- long findID3v1();
- long findAPE();
class FilePrivate;
FilePrivate *d;