From 19f69e9e6c58f3ae3b442a395051d307288726db Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 7 Aug 2020 00:18:31 +0200 Subject: [PATCH] Allow cover search only using either artist, album or title --- src/covermanager/albumcoverfetchersearch.cpp | 4 ++-- src/covermanager/deezercoverprovider.cpp | 14 ++++++++++---- src/covermanager/discogscoverprovider.cpp | 2 ++ src/covermanager/lastfmcoverprovider.cpp | 14 ++++++++++---- src/covermanager/musicbrainzcoverprovider.cpp | 2 ++ src/covermanager/qobuzcoverprovider.cpp | 6 +----- src/covermanager/spotifycoverprovider.cpp | 14 ++++++++++---- src/covermanager/tidalcoverprovider.cpp | 14 ++++++++++---- 8 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/covermanager/albumcoverfetchersearch.cpp b/src/covermanager/albumcoverfetchersearch.cpp index 601431cb2..06ac9446e 100644 --- a/src/covermanager/albumcoverfetchersearch.cpp +++ b/src/covermanager/albumcoverfetchersearch.cpp @@ -98,8 +98,8 @@ void AlbumCoverFetcherSearch::Start(CoverProviders *cover_providers) { continue; } - // If album is missing, check if we can still use this provider by searching using artist + title. - if (!provider->allow_missing_album() && request_.album.isEmpty()) { + // If artist and album is missing, check if we can still use this provider by searching using title. + if (!provider->allow_missing_album() && request_.artist.isEmpty() && request_.album.isEmpty()) { continue; } diff --git a/src/covermanager/deezercoverprovider.cpp b/src/covermanager/deezercoverprovider.cpp index fe2d1ad15..663a24bd5 100644 --- a/src/covermanager/deezercoverprovider.cpp +++ b/src/covermanager/deezercoverprovider.cpp @@ -69,15 +69,21 @@ bool DeezerCoverProvider::StartSearch(const QString &artist, const QString &albu typedef QPair Param; typedef QList Params; + if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; + QString resource; - QString query; - if (album.isEmpty()) { + QString query = artist; + if (album.isEmpty() && !title.isEmpty()) { resource = "search/track"; - query = artist + " " + title; + if (!query.isEmpty()) query.append(" "); + query.append(title); } else { resource = "search/album"; - query = artist + " " + album; + if (!album.isEmpty()) { + if (!query.isEmpty()) query.append(" "); + query.append(album); + } } const Params params = Params() << Param("output", "json") diff --git a/src/covermanager/discogscoverprovider.cpp b/src/covermanager/discogscoverprovider.cpp index 53792886a..b16dd5d56 100644 --- a/src/covermanager/discogscoverprovider.cpp +++ b/src/covermanager/discogscoverprovider.cpp @@ -91,6 +91,8 @@ bool DiscogsCoverProvider::StartSearch(const QString &artist, const QString &alb Q_UNUSED(title); + if (artist.isEmpty() || album.isEmpty()) return false; + std::shared_ptr search = std::make_shared(id, artist, album); requests_search_.insert(search->id, search); diff --git a/src/covermanager/lastfmcoverprovider.cpp b/src/covermanager/lastfmcoverprovider.cpp index 9492a47f7..d55926766 100644 --- a/src/covermanager/lastfmcoverprovider.cpp +++ b/src/covermanager/lastfmcoverprovider.cpp @@ -71,18 +71,24 @@ bool LastFmCoverProvider::StartSearch(const QString &artist, const QString &albu typedef QPair Param; typedef QList ParamList; + if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; + QString method; QString type; - QString query; - if (album.isEmpty()) { + QString query = artist; + if (album.isEmpty() && !title.isEmpty()) { method = "track.search"; type = "track"; - query = artist + " " + title; + if (!query.isEmpty()) query.append(" "); + query.append(title); } else { method = "album.search"; type = "album"; - query = artist + " " + album; + if (!album.isEmpty()) { + if (!query.isEmpty()) query.append(" "); + query.append(album); + } } ParamList params = ParamList() << Param("api_key", kApiKey) diff --git a/src/covermanager/musicbrainzcoverprovider.cpp b/src/covermanager/musicbrainzcoverprovider.cpp index 887692688..61d9ebbc4 100644 --- a/src/covermanager/musicbrainzcoverprovider.cpp +++ b/src/covermanager/musicbrainzcoverprovider.cpp @@ -74,6 +74,8 @@ bool MusicbrainzCoverProvider::StartSearch(const QString &artist, const QString Q_UNUSED(title); + if (artist.isEmpty() || album.isEmpty()) return false; + SearchRequest request(id, artist, album); queue_search_requests_ << request; diff --git a/src/covermanager/qobuzcoverprovider.cpp b/src/covermanager/qobuzcoverprovider.cpp index 9f7f8969a..c50f39634 100644 --- a/src/covermanager/qobuzcoverprovider.cpp +++ b/src/covermanager/qobuzcoverprovider.cpp @@ -297,12 +297,8 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; - QString query; - if (!artist.isEmpty()) { - query.append(artist); - } - QString resource; + QString query = artist; if (album.isEmpty() && !title.isEmpty()) { resource = "track/search"; if (!query.isEmpty()) query.append(" "); diff --git a/src/covermanager/spotifycoverprovider.cpp b/src/covermanager/spotifycoverprovider.cpp index e3bb924c9..16d974d86 100644 --- a/src/covermanager/spotifycoverprovider.cpp +++ b/src/covermanager/spotifycoverprovider.cpp @@ -356,18 +356,24 @@ bool SpotifyCoverProvider::StartSearch(const QString &artist, const QString &alb if (access_token_.isEmpty()) return false; + if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; + QString type; - QString query; QString extract; - if (album.isEmpty()) { + QString query = artist; + if (album.isEmpty() && !title.isEmpty()) { type = "track"; - query = artist + " " + title; extract = "tracks"; + if (!query.isEmpty()) query.append(" "); + query.append(title); } else { type = "album"; - query = artist + " " + album; extract = "albums"; + if (!album.isEmpty()) { + if (!query.isEmpty()) query.append(" "); + query.append(album); + } } ParamList params = ParamList() << Param("q", query) diff --git a/src/covermanager/tidalcoverprovider.cpp b/src/covermanager/tidalcoverprovider.cpp index 278f21029..9821de01a 100644 --- a/src/covermanager/tidalcoverprovider.cpp +++ b/src/covermanager/tidalcoverprovider.cpp @@ -77,15 +77,21 @@ bool TidalCoverProvider::StartSearch(const QString &artist, const QString &album if (!service_ || !service_->authenticated()) return false; + if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; + QString resource; - QString query; - if (album.isEmpty()) { + QString query = artist; + if (album.isEmpty() && !title.isEmpty()) { resource = "search/tracks"; - query = artist + " " + title; + if (!query.isEmpty()) query.append(" "); + query.append(title); } else { resource = "search/albums"; - query = artist + " " + album; + if (!album.isEmpty()) { + if (!query.isEmpty()) query.append(" "); + query.append(album); + } } ParamList params = ParamList() << Param("query", query)