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;
}
// 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;
}

View File

@ -69,15 +69,21 @@ bool DeezerCoverProvider::StartSearch(const QString &artist, const QString &albu
typedef QPair<QString, QString> Param;
typedef QList<Param> 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")

View File

@ -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<DiscogsCoverSearchContext> search = std::make_shared<DiscogsCoverSearchContext>(id, artist, album);
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 QList<Param> 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)

View File

@ -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;

View File

@ -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(" ");

View File

@ -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)

View File

@ -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)