tagreader: remove use of deprecated taglib functions

This commit is contained in:
Jonas Kvinge
2019-09-20 18:07:43 +02:00
parent e7b5e02657
commit b0a2edf5fa
2 changed files with 23 additions and 33 deletions

View File

@@ -83,7 +83,6 @@
#include <QUrl> #include <QUrl>
#include <QTextCodec> #include <QTextCodec>
#include <QVector> #include <QVector>
#include <QNetworkAccessManager>
#include <QtDebug> #include <QtDebug>
#include "core/logging.h" #include "core/logging.h"
@@ -135,12 +134,10 @@ const char *kASF_OriginalYear_ID = "WM/OriginalReleaseYear";
TagReader::TagReader() : TagReader::TagReader() :
factory_(new TagLibFileRefFactory), factory_(new TagLibFileRefFactory),
network_(new QNetworkAccessManager),
kEmbeddedCover("(embedded)") { kEmbeddedCover("(embedded)") {
} }
TagReader::~TagReader() { TagReader::~TagReader() {
delete network_;
delete factory_; delete factory_;
} }
@@ -320,37 +317,33 @@ void TagReader::ReadFile(const QString &filename, pb::tagreader::SongMetadata *s
if (file->tag()) { if (file->tag()) {
TagLib::MP4::Tag *mp4_tag = file->tag(); TagLib::MP4::Tag *mp4_tag = file->tag();
const TagLib::MP4::ItemListMap& items = mp4_tag->itemListMap();
// Find album artists // Find album artists
TagLib::MP4::ItemListMap::ConstIterator it = items.find("aART"); if (mp4_tag->item("aART").isValid()) {
if (it != items.end()) { TagLib::StringList album_artists = mp4_tag->item("aART").toStringList();
TagLib::StringList album_artists = it->second.toStringList();
if (!album_artists.isEmpty()) { if (!album_artists.isEmpty()) {
Decode(album_artists.front(), nullptr, song->mutable_albumartist()); Decode(album_artists.front(), nullptr, song->mutable_albumartist());
} }
} }
// Find album cover art // Find album cover art
if (items.find("covr") != items.end()) { if (mp4_tag->item("covr").isValid()) {
song->set_art_automatic(kEmbeddedCover); song->set_art_automatic(kEmbeddedCover);
} }
if (items.contains("disk")) { if (mp4_tag->item("disk").isValid()) {
disc = TStringToQString(TagLib::String::number(items["disk"].toIntPair().first)); disc = TStringToQString(TagLib::String::number(mp4_tag->item("disk").toIntPair().first));
} }
if (mp4_tag->item("\251wrt").isValid()) {
if(items.contains("\251wrt")) { Decode(mp4_tag->item("\251wrt").toStringList().toString(", "), nullptr, song->mutable_composer());
Decode(items["\251wrt"].toStringList().toString(", "), nullptr, song->mutable_composer());
} }
if(items.contains("\251grp")) { if (mp4_tag->item("\251grp").isValid()) {
Decode(items["\251grp"].toStringList().toString(" "), nullptr, song->mutable_grouping()); Decode(mp4_tag->item("\251grp").toStringList().toString(" "), nullptr, song->mutable_grouping());
} }
if (items.contains(kMP4_OriginalYear_ID)) { if (mp4_tag->item(kMP4_OriginalYear_ID).isValid()) {
song->set_originalyear( song->set_originalyear(TStringToQString(mp4_tag->item(kMP4_OriginalYear_ID).toStringList().toString('\n')).left(4).toInt());
TStringToQString(items[kMP4_OriginalYear_ID].toStringList().toString('\n')).left(4).toInt());
} }
Decode(mp4_tag->comment(), nullptr, song->mutable_comment()); Decode(mp4_tag->comment(), nullptr, song->mutable_comment());
@@ -560,10 +553,10 @@ void TagReader::SetVorbisComments(TagLib::Ogg::XiphComment *vorbis_comments, con
// Try to be coherent, the two forms are used but the first one is preferred // Try to be coherent, the two forms are used but the first one is preferred
vorbis_comments->addField("ALBUMARTIST", StdStringToTaglibString(song.albumartist()), true); vorbis_comments->addField("ALBUMARTIST", StdStringToTaglibString(song.albumartist()), true);
vorbis_comments->removeField("ALBUM ARTIST"); vorbis_comments->removeFields("ALBUM ARTIST");
vorbis_comments->addField("LYRICS", StdStringToTaglibString(song.lyrics()), true); vorbis_comments->addField("LYRICS", StdStringToTaglibString(song.lyrics()), true);
vorbis_comments->removeField("UNSYNCEDLYRICS"); vorbis_comments->removeFields("UNSYNCEDLYRICS");
} }
@@ -620,11 +613,11 @@ bool TagReader::SaveFile(const QString &filename, const pb::tagreader::SongMetad
else if (TagLib::MP4::File *file = dynamic_cast<TagLib::MP4::File*>(fileref->file())) { else if (TagLib::MP4::File *file = dynamic_cast<TagLib::MP4::File*>(fileref->file())) {
TagLib::MP4::Tag *tag = file->tag(); TagLib::MP4::Tag *tag = file->tag();
tag->itemListMap()["disk"] = TagLib::MP4::Item(song.disc() <= 0 -1 ? 0 : song.disc(), 0); tag->setItem("disk", TagLib::MP4::Item(song.disc() <= 0 -1 ? 0 : song.disc(), 0));
tag->itemListMap()["\251wrt"] = TagLib::StringList(song.composer().c_str()); tag->setItem("\251wrt", TagLib::StringList(song.composer().c_str()));
tag->itemListMap()["\251grp"] = TagLib::StringList(song.grouping().c_str()); tag->setItem("\251grp", TagLib::StringList(song.grouping().c_str()));
tag->itemListMap()["aART"] = TagLib::StringList(song.albumartist().c_str()); tag->setItem("aART", TagLib::StringList(song.albumartist().c_str()));
tag->itemListMap()["cpil"] = TagLib::StringList(song.compilation() ? "1" : "0"); tag->setItem("cpil", TagLib::StringList(song.compilation() ? "1" : "0"));
} }
// Handle all the files which have VorbisComments (Ogg, OPUS, ...) in the same way; // Handle all the files which have VorbisComments (Ogg, OPUS, ...) in the same way;
@@ -797,9 +790,10 @@ QByteArray TagReader::LoadEmbeddedArt(const QString &filename) const {
// Ogg lacks a definitive standard for embedding cover art, but it seems // Ogg lacks a definitive standard for embedding cover art, but it seems
// b64 encoding a field called COVERART is the general convention // b64 encoding a field called COVERART is the general convention
if (!map.contains("COVERART")) return QByteArray(); if (map.contains("COVERART"))
return QByteArray::fromBase64(map["COVERART"].toString().toCString());
return QByteArray::fromBase64(map["COVERART"].toString().toCString()); return QByteArray();
} }
// MP3 // MP3
@@ -818,10 +812,8 @@ QByteArray TagReader::LoadEmbeddedArt(const QString &filename) const {
TagLib::MP4::File *aac_file = dynamic_cast<TagLib::MP4::File*>(ref.file()); TagLib::MP4::File *aac_file = dynamic_cast<TagLib::MP4::File*>(ref.file());
if (aac_file) { if (aac_file) {
TagLib::MP4::Tag *tag = aac_file->tag(); TagLib::MP4::Tag *tag = aac_file->tag();
const TagLib::MP4::ItemListMap &items = tag->itemListMap(); if (tag->item("covr").isValid()) {
TagLib::MP4::ItemListMap::ConstIterator it = items.find("covr"); const TagLib::MP4::CoverArtList &art_list = tag->item("covr").toCoverArtList();
if (it != items.end()) {
const TagLib::MP4::CoverArtList &art_list = it->second.toCoverArtList();
if (!art_list.isEmpty()) { if (!art_list.isEmpty()) {
// Just take the first one for now // Just take the first one for now

View File

@@ -25,7 +25,6 @@
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
#include <QNetworkAccessManager>
#include <QTextCodec> #include <QTextCodec>
#include <taglib/xiphcomment.h> #include <taglib/xiphcomment.h>
@@ -91,7 +90,6 @@ class TagReader {
private: private:
FileRefFactory *factory_; FileRefFactory *factory_;
QNetworkAccessManager *network_;
const std::string kEmbeddedCover; const std::string kEmbeddedCover;
}; };