Skip to content

Commit

Permalink
Support both taglib-1 and taglib-2
Browse files Browse the repository at this point in the history
Patch from #7314

Fixes #7313
Close #7314
  • Loading branch information
PPN-SD authored and hatstand committed Jan 9, 2025
1 parent 9549e2b commit 658f34e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ext/libclementine-tagreader/cloudstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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";
}

Expand All @@ -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;
Expand All @@ -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";
}

Expand Down
14 changes: 14 additions & 0 deletions ext/libclementine-tagreader/cloudstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<char>::size_type cached_bytes() const {
return cache_.num_nonempty();
Expand Down
12 changes: 12 additions & 0 deletions ext/libclementine-tagreader/tagreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,15 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title,
std::unique_ptr<TagLib::File> 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))) {
Expand All @@ -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));
Expand Down

0 comments on commit 658f34e

Please sign in to comment.