From 80d127c277e0d8e3a180d340a38dc80f62cba02e Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 8 Jun 2021 20:58:46 +0200 Subject: [PATCH] Use fingerprints from database if available when fetching tags from MusicBrainz --- src/musicbrainz/tagfetcher.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/musicbrainz/tagfetcher.cpp b/src/musicbrainz/tagfetcher.cpp index f3eb626f0..cfa796933 100644 --- a/src/musicbrainz/tagfetcher.cpp +++ b/src/musicbrainz/tagfetcher.cpp @@ -55,13 +55,30 @@ void TagFetcher::StartFetch(const SongList &songs) { songs_ = songs; - QFuture future = QtConcurrent::mapped(songs_, GetFingerprint); - fingerprint_watcher_ = new QFutureWatcher(this); - fingerprint_watcher_->setFuture(future); - QObject::connect(fingerprint_watcher_, &QFutureWatcher::resultReadyAt, this, &TagFetcher::FingerprintFound); + bool have_fingerprints = true; - for (const Song &song : songs) { - emit Progress(song, tr("Fingerprinting song")); + for (const Song &song : songs_) { + if (song.fingerprint().isEmpty()) { + have_fingerprints = false; + break; + } + } + + if (have_fingerprints) { + for (int i = 0 ; i < songs_.count() ; ++i) { + const Song &song = songs_[i]; + emit Progress(song, tr("Identifying song")); + acoustid_client_->Start(i, song.fingerprint(), static_cast(song.length_nanosec() / kNsecPerMsec)); + } + } + else { + QFuture future = QtConcurrent::mapped(songs_, GetFingerprint); + fingerprint_watcher_ = new QFutureWatcher(this); + fingerprint_watcher_->setFuture(future); + QObject::connect(fingerprint_watcher_, &QFutureWatcher::resultReadyAt, this, &TagFetcher::FingerprintFound); + for (const Song &song : songs_) { + emit Progress(song, tr("Fingerprinting song")); + } } } @@ -83,7 +100,7 @@ void TagFetcher::Cancel() { void TagFetcher::FingerprintFound(const int index) { - QFutureWatcher* watcher = reinterpret_cast*>(sender()); + QFutureWatcher *watcher = reinterpret_cast*>(sender()); if (!watcher || index >= songs_.count()) return; const QString fingerprint = watcher->resultAt(index);