From 604ef7daaca048766fdebff7c9f3e832d41bc923 Mon Sep 17 00:00:00 2001 From: Marius Lindvall Date: Wed, 31 Jan 2024 17:33:28 +0100 Subject: [PATCH 1/2] Fix usage of deprecated TagLib functions --- ext/libclementine-tagreader/cloudstream.cpp | 14 +++++------ ext/libclementine-tagreader/cloudstream.h | 14 +++++------ ext/libclementine-tagreader/tagreader.cpp | 28 ++++++++++----------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ext/libclementine-tagreader/cloudstream.cpp b/ext/libclementine-tagreader/cloudstream.cpp index 60786fab2f..d5db8416fe 100644 --- a/ext/libclementine-tagreader/cloudstream.cpp +++ b/ext/libclementine-tagreader/cloudstream.cpp @@ -91,7 +91,7 @@ void CloudStream::Precache() { clear(); } -TagLib::ByteVector CloudStream::readBlock(ulong length) { +TagLib::ByteVector CloudStream::readBlock(size_t length) { const uint start = cursor_; const uint end = qMin(cursor_ + length - 1, length_ - 1); @@ -144,11 +144,11 @@ void CloudStream::writeBlock(const TagLib::ByteVector&) { qLog(Debug) << Q_FUNC_INFO << "not implemented"; } -void CloudStream::insert(const TagLib::ByteVector&, ulong, ulong) { +void CloudStream::insert(const TagLib::ByteVector&, TagLib::offset_t, size_t) { qLog(Debug) << Q_FUNC_INFO << "not implemented"; } -void CloudStream::removeBlock(ulong, ulong) { +void CloudStream::removeBlock(TagLib::offset_t, size_t) { qLog(Debug) << Q_FUNC_INFO << "not implemented"; } @@ -159,7 +159,7 @@ bool CloudStream::readOnly() const { bool CloudStream::isOpen() const { return true; } -void CloudStream::seek(long offset, TagLib::IOStream::Position p) { +void CloudStream::seek(TagLib::offset_t offset, TagLib::IOStream::Position p) { switch (p) { case TagLib::IOStream::Beginning: cursor_ = offset; @@ -178,11 +178,11 @@ void CloudStream::seek(long offset, TagLib::IOStream::Position p) { void CloudStream::clear() { cursor_ = 0; } -long CloudStream::tell() const { return cursor_; } +TagLib::offset_t CloudStream::tell() const { return cursor_; } -long CloudStream::length() { return length_; } +TagLib::offset_t CloudStream::length() { return length_; } -void CloudStream::truncate(long) { +void CloudStream::truncate(TagLib::offset_t) { qLog(Debug) << Q_FUNC_INFO << "not implemented"; } diff --git a/ext/libclementine-tagreader/cloudstream.h b/ext/libclementine-tagreader/cloudstream.h index 7002b3ad92..9ed6de6f78 100644 --- a/ext/libclementine-tagreader/cloudstream.h +++ b/ext/libclementine-tagreader/cloudstream.h @@ -35,17 +35,17 @@ class CloudStream : public QObject, public TagLib::IOStream { // Taglib::IOStream virtual TagLib::FileName name() const; - virtual TagLib::ByteVector readBlock(ulong length); + virtual TagLib::ByteVector readBlock(size_t length); virtual void writeBlock(const TagLib::ByteVector&); - virtual void insert(const TagLib::ByteVector&, ulong, ulong); - virtual void removeBlock(ulong, ulong); + virtual void insert(const TagLib::ByteVector&, TagLib::offset_t, size_t); + virtual void removeBlock(TagLib::offset_t, size_t); virtual bool readOnly() const; virtual bool isOpen() const; - virtual void seek(long offset, TagLib::IOStream::Position p); + virtual void seek(TagLib::offset_t offset, TagLib::IOStream::Position p); virtual void clear(); - virtual long tell() const; - virtual long length(); - virtual void truncate(long); + virtual TagLib::offset_t tell() const; + virtual TagLib::offset_t length(); + virtual void truncate(TagLib::offset_t); google::sparsetable::size_type cached_bytes() const { return cache_.num_nonempty(); diff --git a/ext/libclementine-tagreader/tagreader.cpp b/ext/libclementine-tagreader/tagreader.cpp index e6fc5592dd..644825554e 100644 --- a/ext/libclementine-tagreader/tagreader.cpp +++ b/ext/libclementine-tagreader/tagreader.cpp @@ -198,7 +198,7 @@ void TagReader::ReadFile(const QString& filename, // Find album artists TagLib::APE::ItemListMap::ConstIterator it = items.find("ALBUM ARTIST"); if (it != items.end()) { - TagLib::StringList album_artists = it->second.toStringList(); + TagLib::StringList album_artists = it->second.values(); if (!album_artists.isEmpty()) { Decode(album_artists.front(), nullptr, song->mutable_albumartist()); } @@ -243,22 +243,22 @@ void TagReader::ReadFile(const QString& filename, } if (items.contains("BPM")) { - Decode(items["BPM"].toStringList().toString(", "), nullptr, + Decode(items["BPM"].values().toString(", "), nullptr, song->mutable_performer()); } if (items.contains("PERFORMER")) { - Decode(items["PERFORMER"].toStringList().toString(", "), nullptr, + Decode(items["PERFORMER"].values().toString(", "), nullptr, song->mutable_performer()); } if (items.contains("COMPOSER")) { - Decode(items["COMPOSER"].toStringList().toString(", "), nullptr, + Decode(items["COMPOSER"].values().toString(", "), nullptr, song->mutable_composer()); } if (items.contains("GROUPING")) { - Decode(items["GROUPING"].toStringList().toString(" "), nullptr, + Decode(items["GROUPING"].values().toString(" "), nullptr, song->mutable_grouping()); } @@ -565,8 +565,8 @@ void TagReader::ReadFile(const QString& filename, if (fileref->audioProperties()) { song->set_bitrate(fileref->audioProperties()->bitrate()); song->set_samplerate(fileref->audioProperties()->sampleRate()); - song->set_length_nanosec(fileref->audioProperties()->length() * - kNsecPerSec); + song->set_length_nanosec(fileref->audioProperties()->lengthInMilliseconds() * + kNsecPerMsec); } // Get the filetype if we can @@ -1376,9 +1376,9 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title, std::unique_ptr tag; if (mime_type == "audio/mpeg" && title.endsWith(".mp3", Qt::CaseInsensitive)) { - tag.reset(new TagLib::MPEG::File(stream.get(), - TagLib::ID3v2::FrameFactory::instance(), - TagLib::AudioProperties::Accurate)); + tag.reset(new TagLib::MPEG::File(stream.get(), true, + TagLib::AudioProperties::Accurate, + TagLib::ID3v2::FrameFactory::instance())); } else if (mime_type == "audio/mp4" || (mime_type == "audio/mpeg" && title.endsWith(".m4a", Qt::CaseInsensitive))) { @@ -1398,9 +1398,9 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title, TagLib::AudioProperties::Accurate)); } else if (mime_type == "application/x-flac" || mime_type == "audio/flac" || mime_type == "audio/x-flac") { - tag.reset(new TagLib::FLAC::File(stream.get(), - TagLib::ID3v2::FrameFactory::instance(), - true, TagLib::AudioProperties::Accurate)); + tag.reset(new TagLib::FLAC::File(stream.get(), true, + TagLib::AudioProperties::Accurate, + TagLib::ID3v2::FrameFactory::instance())); } else if (mime_type == "audio/x-ms-wma") { tag.reset(new TagLib::ASF::File(stream.get(), true, TagLib::AudioProperties::Accurate)); @@ -1431,7 +1431,7 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title, song->set_type(cpb::tagreader::SongMetadata_Type_STREAM); if (tag->audioProperties()) { - song->set_length_nanosec(tag->audioProperties()->length() * kNsecPerSec); + song->set_length_nanosec(tag->audioProperties()->lengthInMilliseconds() * kNsecPerMsec); } return true; } From edaf5eac7f0d5eeb9f77ef29d235d31c14aed7c2 Mon Sep 17 00:00:00 2001 From: Nicolas PARLANT Date: Thu, 9 Jan 2025 00:48:08 +0000 Subject: [PATCH 2/2] Support both taglib-1 and taglib-2 Patch from #7314 Fixes #7313 Close #7314 --- ext/libclementine-tagreader/cloudstream.cpp | 24 +++++++++++++++++++++ ext/libclementine-tagreader/cloudstream.h | 14 ++++++++++++ ext/libclementine-tagreader/tagreader.cpp | 12 +++++++++++ 3 files changed, 50 insertions(+) diff --git a/ext/libclementine-tagreader/cloudstream.cpp b/ext/libclementine-tagreader/cloudstream.cpp index d5db8416fe..95dc69ccaa 100644 --- a/ext/libclementine-tagreader/cloudstream.cpp +++ b/ext/libclementine-tagreader/cloudstream.cpp @@ -91,7 +91,11 @@ void CloudStream::Precache() { clear(); } +#if (TAGLIB_MAJOR_VERSION == 2) TagLib::ByteVector CloudStream::readBlock(size_t length) { +#else +TagLib::ByteVector CloudStream::readBlock(ulong length) { +#endif const uint start = cursor_; const uint end = qMin(cursor_ + length - 1, length_ - 1); @@ -144,11 +148,19 @@ void CloudStream::writeBlock(const TagLib::ByteVector&) { qLog(Debug) << Q_FUNC_INFO << "not implemented"; } +#if (TAGLIB_MAJOR_VERSION == 2) void CloudStream::insert(const TagLib::ByteVector&, TagLib::offset_t, size_t) { +#else +void CloudStream::insert(const TagLib::ByteVector&, ulong, ulong) { +#endif qLog(Debug) << Q_FUNC_INFO << "not implemented"; } +#if (TAGLIB_MAJOR_VERSION == 2) void CloudStream::removeBlock(TagLib::offset_t, size_t) { +#else +void CloudStream::removeBlock(ulong, ulong) { +#endif qLog(Debug) << Q_FUNC_INFO << "not implemented"; } @@ -159,7 +171,11 @@ bool CloudStream::readOnly() const { bool CloudStream::isOpen() const { return true; } +#if (TAGLIB_MAJOR_VERSION == 2) void CloudStream::seek(TagLib::offset_t offset, TagLib::IOStream::Position p) { +#else +void CloudStream::seek(long offset, TagLib::IOStream::Position p) { +#endif switch (p) { case TagLib::IOStream::Beginning: cursor_ = offset; @@ -178,11 +194,19 @@ void CloudStream::seek(TagLib::offset_t offset, TagLib::IOStream::Position p) { void CloudStream::clear() { cursor_ = 0; } +#if (TAGLIB_MAJOR_VERSION == 2) TagLib::offset_t CloudStream::tell() const { return cursor_; } TagLib::offset_t CloudStream::length() { return length_; } void CloudStream::truncate(TagLib::offset_t) { +#else +long CloudStream::tell() const { return cursor_; } + +long CloudStream::length() { return length_; } + +void CloudStream::truncate(long) { +#endif qLog(Debug) << Q_FUNC_INFO << "not implemented"; } diff --git a/ext/libclementine-tagreader/cloudstream.h b/ext/libclementine-tagreader/cloudstream.h index 9ed6de6f78..deb9ecd611 100644 --- a/ext/libclementine-tagreader/cloudstream.h +++ b/ext/libclementine-tagreader/cloudstream.h @@ -35,6 +35,7 @@ class CloudStream : public QObject, public TagLib::IOStream { // Taglib::IOStream virtual TagLib::FileName name() const; +#if (TAGLIB_MAJOR_VERSION == 2) virtual TagLib::ByteVector readBlock(size_t length); virtual void writeBlock(const TagLib::ByteVector&); virtual void insert(const TagLib::ByteVector&, TagLib::offset_t, size_t); @@ -46,6 +47,19 @@ class CloudStream : public QObject, public TagLib::IOStream { virtual TagLib::offset_t tell() const; virtual TagLib::offset_t length(); virtual void truncate(TagLib::offset_t); +#else + virtual TagLib::ByteVector readBlock(ulong length); + virtual void writeBlock(const TagLib::ByteVector&); + virtual void insert(const TagLib::ByteVector&, ulong, ulong); + virtual void removeBlock(ulong, ulong); + virtual bool readOnly() const; + virtual bool isOpen() const; + virtual void seek(long offset, TagLib::IOStream::Position p); + virtual void clear(); + virtual long tell() const; + virtual long length(); + virtual void truncate(long); +#endif google::sparsetable::size_type cached_bytes() const { return cache_.num_nonempty(); diff --git a/ext/libclementine-tagreader/tagreader.cpp b/ext/libclementine-tagreader/tagreader.cpp index 644825554e..6986b20849 100644 --- a/ext/libclementine-tagreader/tagreader.cpp +++ b/ext/libclementine-tagreader/tagreader.cpp @@ -1376,9 +1376,15 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title, std::unique_ptr tag; if (mime_type == "audio/mpeg" && title.endsWith(".mp3", Qt::CaseInsensitive)) { +#if (TAGLIB_MAJOR_VERSION == 2) tag.reset(new TagLib::MPEG::File(stream.get(), true, TagLib::AudioProperties::Accurate, TagLib::ID3v2::FrameFactory::instance())); +#else + tag.reset(new TagLib::MPEG::File(stream.get(), + TagLib::ID3v2::FrameFactory::instance(), + TagLib::AudioProperties::Accurate)); +#endif } else if (mime_type == "audio/mp4" || (mime_type == "audio/mpeg" && title.endsWith(".m4a", Qt::CaseInsensitive))) { @@ -1398,9 +1404,15 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title, TagLib::AudioProperties::Accurate)); } else if (mime_type == "application/x-flac" || mime_type == "audio/flac" || mime_type == "audio/x-flac") { +#if (TAGLIB_MAJOR_VERSION == 2) tag.reset(new TagLib::FLAC::File(stream.get(), true, TagLib::AudioProperties::Accurate, TagLib::ID3v2::FrameFactory::instance())); +#else + tag.reset(new TagLib::FLAC::File(stream.get(), + TagLib::ID3v2::FrameFactory::instance(), + true, TagLib::AudioProperties::Accurate)); +#endif } else if (mime_type == "audio/x-ms-wma") { tag.reset(new TagLib::ASF::File(stream.get(), true, TagLib::AudioProperties::Accurate));