Merge pull request #4959 from M-Bab/master

Cache and restore further mp3-file metadata-frames instead of cruel deletion
This commit is contained in:
John Maguire 2015-07-28 11:04:45 +01:00
commit 563104f016

View File

@ -25,6 +25,7 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QTextCodec> #include <QTextCodec>
#include <QUrl> #include <QUrl>
#include <QVector>
#include <aifffile.h> #include <aifffile.h>
#include <asffile.h> #include <asffile.h>
@ -893,36 +894,67 @@ void TagReader::SetTextFrame(const char* id, const QString& value,
void TagReader::SetTextFrame(const char* id, const std::string& value, void TagReader::SetTextFrame(const char* id, const std::string& value,
TagLib::ID3v2::Tag* tag) const { TagLib::ID3v2::Tag* tag) const {
TagLib::ByteVector id_vector(id); TagLib::ByteVector id_vector(id);
QVector<TagLib::ByteVector> frames_buffer;
// Remove the frame if it already exists // Store and clear existing frames
while (tag->frameListMap().contains(id_vector) && while (tag->frameListMap().contains(id_vector) &&
tag->frameListMap()[id_vector].size() != 0) { tag->frameListMap()[id_vector].size() != 0) {
frames_buffer.push_back(tag->frameListMap()[id_vector].front()->render());
tag->removeFrame(tag->frameListMap()[id_vector].front()); tag->removeFrame(tag->frameListMap()[id_vector].front());
} }
// Create and add a new frame // If no frames stored create empty frame
TagLib::ID3v2::TextIdentificationFrame* frame = if (frames_buffer.isEmpty()) {
new TagLib::ID3v2::TextIdentificationFrame(id_vector, TagLib::ID3v2::TextIdentificationFrame frame(id_vector,
TagLib::String::UTF8); TagLib::String::UTF8);
frame->setText(StdStringToTaglibString(value)); frames_buffer.push_back(frame.render());
tag->addFrame(frame); }
// Update and add the frames
for (int lyrics_index = 0; lyrics_index < frames_buffer.size();
lyrics_index++) {
TagLib::ID3v2::TextIdentificationFrame* frame =
new TagLib::ID3v2::TextIdentificationFrame(
frames_buffer.at(lyrics_index));
if (lyrics_index == 0) {
frame->setText(StdStringToTaglibString(value));
}
// add frame takes ownership and clears the memory
tag->addFrame(frame);
}
} }
void TagReader::SetUnsyncLyricsFrame(const std::string& value, void TagReader::SetUnsyncLyricsFrame(const std::string& value,
TagLib::ID3v2::Tag* tag) const { TagLib::ID3v2::Tag* tag) const {
TagLib::ByteVector id_vector("USLT"); TagLib::ByteVector id_vector("USLT");
QVector<TagLib::ByteVector> frames_buffer;
// Remove the frame if it already exists // Store and clear existing frames
while (tag->frameListMap().contains(id_vector) && while (tag->frameListMap().contains(id_vector) &&
tag->frameListMap()[id_vector].size() != 0) { tag->frameListMap()[id_vector].size() != 0) {
frames_buffer.push_back(tag->frameListMap()[id_vector].front()->render());
tag->removeFrame(tag->frameListMap()[id_vector].front()); tag->removeFrame(tag->frameListMap()[id_vector].front());
} }
// Create and add a new frame // If no frames stored create empty frame
TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = if (frames_buffer.isEmpty()) {
new TagLib::ID3v2::UnsynchronizedLyricsFrame(TagLib::String::UTF8); TagLib::ID3v2::UnsynchronizedLyricsFrame frame(TagLib::String::UTF8);
frame->setText(StdStringToTaglibString(value)); frame.setDescription("Clementine editor");
tag->addFrame(frame); frames_buffer.push_back(frame.render());
}
// Update and add the frames
for (int lyrics_index = 0; lyrics_index < frames_buffer.size();
lyrics_index++) {
TagLib::ID3v2::UnsynchronizedLyricsFrame* frame =
new TagLib::ID3v2::UnsynchronizedLyricsFrame(
frames_buffer.at(lyrics_index));
if (lyrics_index == 0) {
frame->setText(StdStringToTaglibString(value));
}
// add frame takes ownership and clears the memory
tag->addFrame(frame);
}
} }
bool TagReader::IsMediaFile(const QString& filename) const { bool TagReader::IsMediaFile(const QString& filename) const {