Allow cover search only using either artist, album or title

This commit is contained in:
Jonas Kvinge 2020-08-07 00:18:31 +02:00
parent 01481da773
commit 19f69e9e6c
8 changed files with 47 additions and 23 deletions

View File

@ -98,8 +98,8 @@ void AlbumCoverFetcherSearch::Start(CoverProviders *cover_providers) {
continue; continue;
} }
// If album is missing, check if we can still use this provider by searching using artist + title. // If artist and album is missing, check if we can still use this provider by searching using title.
if (!provider->allow_missing_album() && request_.album.isEmpty()) { if (!provider->allow_missing_album() && request_.artist.isEmpty() && request_.album.isEmpty()) {
continue; continue;
} }

View File

@ -69,15 +69,21 @@ bool DeezerCoverProvider::StartSearch(const QString &artist, const QString &albu
typedef QPair<QString, QString> Param; typedef QPair<QString, QString> Param;
typedef QList<Param> Params; typedef QList<Param> Params;
if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false;
QString resource; QString resource;
QString query; QString query = artist;
if (album.isEmpty()) { if (album.isEmpty() && !title.isEmpty()) {
resource = "search/track"; resource = "search/track";
query = artist + " " + title; if (!query.isEmpty()) query.append(" ");
query.append(title);
} }
else { else {
resource = "search/album"; resource = "search/album";
query = artist + " " + album; if (!album.isEmpty()) {
if (!query.isEmpty()) query.append(" ");
query.append(album);
}
} }
const Params params = Params() << Param("output", "json") const Params params = Params() << Param("output", "json")

View File

@ -91,6 +91,8 @@ bool DiscogsCoverProvider::StartSearch(const QString &artist, const QString &alb
Q_UNUSED(title); Q_UNUSED(title);
if (artist.isEmpty() || album.isEmpty()) return false;
std::shared_ptr<DiscogsCoverSearchContext> search = std::make_shared<DiscogsCoverSearchContext>(id, artist, album); std::shared_ptr<DiscogsCoverSearchContext> search = std::make_shared<DiscogsCoverSearchContext>(id, artist, album);
requests_search_.insert(search->id, search); requests_search_.insert(search->id, search);

View File

@ -71,18 +71,24 @@ bool LastFmCoverProvider::StartSearch(const QString &artist, const QString &albu
typedef QPair<QString, QString> Param; typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList; typedef QList<Param> ParamList;
if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false;
QString method; QString method;
QString type; QString type;
QString query; QString query = artist;
if (album.isEmpty()) { if (album.isEmpty() && !title.isEmpty()) {
method = "track.search"; method = "track.search";
type = "track"; type = "track";
query = artist + " " + title; if (!query.isEmpty()) query.append(" ");
query.append(title);
} }
else { else {
method = "album.search"; method = "album.search";
type = "album"; type = "album";
query = artist + " " + album; if (!album.isEmpty()) {
if (!query.isEmpty()) query.append(" ");
query.append(album);
}
} }
ParamList params = ParamList() << Param("api_key", kApiKey) ParamList params = ParamList() << Param("api_key", kApiKey)

View File

@ -74,6 +74,8 @@ bool MusicbrainzCoverProvider::StartSearch(const QString &artist, const QString
Q_UNUSED(title); Q_UNUSED(title);
if (artist.isEmpty() || album.isEmpty()) return false;
SearchRequest request(id, artist, album); SearchRequest request(id, artist, album);
queue_search_requests_ << request; queue_search_requests_ << request;

View File

@ -297,12 +297,8 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false; if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false;
QString query;
if (!artist.isEmpty()) {
query.append(artist);
}
QString resource; QString resource;
QString query = artist;
if (album.isEmpty() && !title.isEmpty()) { if (album.isEmpty() && !title.isEmpty()) {
resource = "track/search"; resource = "track/search";
if (!query.isEmpty()) query.append(" "); if (!query.isEmpty()) query.append(" ");

View File

@ -356,18 +356,24 @@ bool SpotifyCoverProvider::StartSearch(const QString &artist, const QString &alb
if (access_token_.isEmpty()) return false; if (access_token_.isEmpty()) return false;
if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false;
QString type; QString type;
QString query;
QString extract; QString extract;
if (album.isEmpty()) { QString query = artist;
if (album.isEmpty() && !title.isEmpty()) {
type = "track"; type = "track";
query = artist + " " + title;
extract = "tracks"; extract = "tracks";
if (!query.isEmpty()) query.append(" ");
query.append(title);
} }
else { else {
type = "album"; type = "album";
query = artist + " " + album;
extract = "albums"; extract = "albums";
if (!album.isEmpty()) {
if (!query.isEmpty()) query.append(" ");
query.append(album);
}
} }
ParamList params = ParamList() << Param("q", query) ParamList params = ParamList() << Param("q", query)

View File

@ -77,15 +77,21 @@ bool TidalCoverProvider::StartSearch(const QString &artist, const QString &album
if (!service_ || !service_->authenticated()) return false; if (!service_ || !service_->authenticated()) return false;
if (artist.isEmpty() && album.isEmpty() && title.isEmpty()) return false;
QString resource; QString resource;
QString query; QString query = artist;
if (album.isEmpty()) { if (album.isEmpty() && !title.isEmpty()) {
resource = "search/tracks"; resource = "search/tracks";
query = artist + " " + title; if (!query.isEmpty()) query.append(" ");
query.append(title);
} }
else { else {
resource = "search/albums"; resource = "search/albums";
query = artist + " " + album; if (!album.isEmpty()) {
if (!query.isEmpty()) query.append(" ");
query.append(album);
}
} }
ParamList params = ParamList() << Param("query", query) ParamList params = ParamList() << Param("query", query)