summarylogtreecommitdiffstats
path: root/fed57c8cf746812bdc93704af7d0ebcfa69a5156.patch
blob: 0a7b0fafacc36785430cec50b8cde9b9ce865916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
From fed57c8cf746812bdc93704af7d0ebcfa69a5156 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= <mumei6102@gmail.com>
Date: Mon, 29 Jan 2024 20:00:41 +0100
Subject: [PATCH] TagLib: Add support for 2.0, remove support for 1.9 and 1.10

Closes #680
---
 README.md             |  2 +-
 src/gui/TagEditor.cpp | 78 ++++++++-----------------------------------
 2 files changed, 15 insertions(+), 65 deletions(-)

diff --git a/README.md b/README.md
index 81b72f9e6..34025d084 100644
--- a/README.md
+++ b/README.md
@@ -198,7 +198,7 @@ For CMake build be sure that you have CMake 3.9 or higher.
     - libavdevice - for FFmpeg module only, optional (enabled on Linux as default),
 
 #### Important:
-- TagLib >= 1.9,
+- TagLib >= 1.11,
 - libass - for OSD and non-graphical subtitles.
 
 #### For modules (some of them can be automatically disabled if not found):
diff --git a/src/gui/TagEditor.cpp b/src/gui/TagEditor.cpp
index d1f101b7d..55756cd60 100644
--- a/src/gui/TagEditor.cpp
+++ b/src/gui/TagEditor.cpp
@@ -21,19 +21,12 @@
 #include <Functions.hpp>
 #include <Main.hpp>
 
-#define TAGLIB_VERSION ((TAGLIB_MAJOR_VERSION << 8) | TAGLIB_MINOR_VERSION)
-#define TAGLIB1B (TAGLIB_VERSION >= 0x10B)
-
 #ifdef TAGLIB_FULL_INCLUDE_PATH
     #include <taglib/taglib.h>
 #else
     #include <taglib.h>
 #endif
 
-#if TAGLIB_VERSION < 0x109
-    #error Taglib 1.9 or newer is needed!
-#endif
-
 #ifdef TAGLIB_FULL_INCLUDE_PATH
     #include <taglib/trueaudiofile.h>
     #include <taglib/oggflacfile.h>
@@ -54,6 +47,7 @@
     #include <taglib/itfile.h>
     #include <taglib/xmfile.h>
     #include <taglib/opusfile.h>
+    #include <taglib/attachedpictureframe.h>
 #else
     #include <trueaudiofile.h>
     #include <oggflacfile.h>
@@ -74,6 +68,7 @@
     #include <itfile.h>
     #include <xmfile.h>
     #include <opusfile.h>
+    #include <attachedpictureframe.h>
 #endif
 using namespace TagLib;
 
@@ -136,17 +131,9 @@ static void removeXiphComment(Ogg::XiphComment *xiphComment)
 {
     if (xiphComment)
     {
-#if TAGLIB1B
         xiphComment->removeAllPictures();
         xiphComment->removeAllFields();
-#else
-        const Ogg::FieldListMap &fieldListMap = xiphComment->fieldListMap();
-        for (Ogg::FieldListMap::ConstIterator it = fieldListMap.begin(); it != fieldListMap.end(); ++it)
-        {
-            if (xiphComment->contains(it->first))
-                xiphComment->removeField(it->first);
-        }
-#endif
+
     }
 }
 
@@ -312,10 +299,10 @@ bool TagEditor::open(const QString &fileName)
         }
         else if (instanceOf(file, MP4::File))
         {
-            MP4::ItemListMap &itemListMap = ((MP4::File &)file).tag()->itemListMap();
-            MP4::ItemListMap::ConstIterator it = itemListMap.find("covr");
+            auto &&itemMap = ((MP4::File &)file).tag()->itemMap();
+            auto it = itemMap.find("covr");
             pictureB->setEnabled(true);
-            if (it != itemListMap.end())
+            if (it != itemMap.end())
             {
                 MP4::CoverArtList coverArtList = it->second.toCoverArtList();
                 if (!coverArtList.isEmpty())
@@ -355,25 +342,12 @@ bool TagEditor::open(const QString &fileName)
             {
                 FLAC::Picture *flacPicture = nullptr;
                 pictureB->setEnabled(true);
-#if TAGLIB1B
                 const List<FLAC::Picture *> pictures = xiphComment->pictureList();
                 if (!pictures.isEmpty())
                 {
                     flacPicture = pictures[0];
                     hasTags = true;
                 }
-#else
-                const Ogg::FieldListMap &fieldListMap = xiphComment->fieldListMap();
-                Ogg::FieldListMap::ConstIterator it = fieldListMap.find("METADATA_BLOCK_PICTURE");
-                FLAC::Picture tmpFlacPicture;
-                if (it != fieldListMap.end() && !it->second.isEmpty())
-                {
-                    /* OGG picture and FLAC picture are the same except OGG picture is encoded into Base64 */
-                    const QByteArray pict_frame_decoded = QByteArray::fromBase64(it->second.front().toCString());
-                    if (tmpFlacPicture.parse(ByteVector(pict_frame_decoded.data(), pict_frame_decoded.size())))
-                        flacPicture = &tmpFlacPicture;
-                }
-#endif
                 if (flacPicture)
                 {
                     pictureMimeType = flacPicture->mimeType().toCString();
@@ -489,12 +463,12 @@ bool TagEditor::save()
             }
             else if (instanceOf(file, MP4::File))
             {
-                MP4::ItemListMap &itemListMap = ((MP4::File &)file).tag()->itemListMap();
-                if (itemListMap.contains("covr"))
-                    itemListMap.erase("covr");
+                auto &itemMap = const_cast<MP4::ItemMap &>(((MP4::File &)file).tag()->itemMap());
+                if (itemMap.contains("covr"))
+                    itemMap.erase("covr");
                 if (hasPicture)
                 {
-                    MP4::CoverArt::Format format = (MP4::CoverArt::Format)0;
+                    auto format = MP4::CoverArt::Format::Unknown;
                     if (pictureMimeType == "image/jpeg")
                         format = MP4::CoverArt::JPEG;
                     else if (pictureMimeType == "image/png")
@@ -503,11 +477,11 @@ bool TagEditor::save()
                         format = MP4::CoverArt::BMP;
                     else if (pictureMimeType == "image/gif")
                         format = MP4::CoverArt::GIF;
-                    if (format)
+                    if (format != MP4::CoverArt::Format::Unknown)
                     {
                         MP4::CoverArtList coverArtList;
                         coverArtList.append(MP4::CoverArt(format, *picture));
-                        itemListMap.insert("covr", coverArtList);
+                        itemMap.insert("covr", coverArtList);
                     }
                 }
                 mustSave = true;
@@ -525,19 +499,9 @@ bool TagEditor::save()
                         flacPicture->setType(FLAC::Picture::FrontCover);
                         flacPicture->setData(*picture);
                     }
-#if TAGLIB1B
                     xiphComment->removeAllPictures();
                     if (flacPicture)
                         xiphComment->addPicture(flacPicture);
-#else
-                    xiphComment->removeField("METADATA_BLOCK_PICTURE");
-                    if (flacPicture)
-                    {
-                        const ByteVector pict_data = flacPicture->render();
-                        xiphComment->addField("METADATA_BLOCK_PICTURE", QByteArray::fromRawData(pict_data.data(), pict_data.size()).toBase64().data());
-                        delete flacPicture;
-                    }
-#endif
                     mustSave = true;
                 }
             }
@@ -557,7 +521,7 @@ bool TagEditor::save()
             else if (instanceOf(file, APE::File))
                 ((APE::File &)file).strip();
             else if (instanceOf(file, MP4::File))
-                ((MP4::File &)file).tag()->itemListMap().clear();
+                const_cast<MP4::ItemMap &>(((MP4::File &)file).tag()->itemMap()).clear();
             else if (instanceOf(file, ASF::File))
                 ((ASF::File &)file).tag()->attributeListMap().clear();
             else if (isOgg(file))
@@ -591,7 +555,7 @@ bool TagEditor::save()
                 else if (instanceOf(file, XM::File))
                     modTag = ((XM::File &)file).tag();
                 if (modTag)
-                    modTag->setTrackerName(String::null);
+                    modTag->setTrackerName(String());
             }
         }
 
@@ -601,21 +565,7 @@ bool TagEditor::save()
             FLAC::File &flacF = (FLAC::File &)file;
             if (flacF.hasID3v1Tag() || flacF.hasID3v2Tag())
             {
-#if TAGLIB1B
                 flacF.strip(FLAC::File::ID3v1 | FLAC::File::ID3v2);
-#else
-    #ifdef Q_OS_WIN
-                const FileName fName = file.name(); //Class with "std::string"
-    #else
-                const QByteArray fName = file.name(); //Raw pointer, so copy it
-    #endif
-                result = fRef->save();
-                delete fRef;
-                fRef = nullptr;
-                if (result)
-                    result = MPEG::File(fName, false).save(MPEG::File::NoTags);
-                mustSave = false;
-#endif
             }
         }