mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2024-12-17 19:18:36 +01:00
Remove Disc / CD from albumname when searching for covers. Dont use url if it's empty in LastFM.
This commit is contained in:
parent
b7466b7fb1
commit
7501e8b14d
@ -250,7 +250,7 @@ void CollectionModel::SongsDiscovered(const SongList &songs) {
|
||||
// Does it exist already?
|
||||
if (!container_nodes_[i].contains(key)) {
|
||||
// Create the container
|
||||
qLog(Debug) << "Adding song:" << song.album();
|
||||
//qLog(Debug) << "Adding song:" << song.album();
|
||||
container_nodes_[i][key] = ItemFromSong(type, true, i == 0, container, song, i);
|
||||
}
|
||||
container = container_nodes_[i][key];
|
||||
|
@ -171,9 +171,9 @@ QString AlbumCoverChoiceController::LoadCoverFromURL(Song *song) {
|
||||
}
|
||||
|
||||
QString AlbumCoverChoiceController::SearchForCover(Song *song) {
|
||||
|
||||
//qLog(Debug) << __PRETTY_FUNCTION__;
|
||||
|
||||
|
||||
qLog(Debug) << __PRETTY_FUNCTION__;
|
||||
|
||||
QString album = song->effective_album();
|
||||
album = album.remove(QRegExp(" ?-? ?(\\(|\\[)(Disc|CD)? ?[0-9](\\)|\\])$"));
|
||||
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "albumcoverfetcher.h"
|
||||
#include "albumcoverfetchersearch.h"
|
||||
#include "core/network.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
const int AlbumCoverFetcher::kMaxConcurrentRequests = 5;
|
||||
|
||||
@ -40,9 +42,12 @@ AlbumCoverFetcher::AlbumCoverFetcher(CoverProviders *cover_providers, QObject *p
|
||||
|
||||
quint64 AlbumCoverFetcher::FetchAlbumCover(const QString &artist, const QString &album) {
|
||||
|
||||
QString album2(album);
|
||||
album2 = album2.remove(QRegExp(" ?-? ?(\\(|\\[)(Disc|CD)? ?[0-9](\\)|\\])$"));
|
||||
|
||||
CoverSearchRequest request;
|
||||
request.artist = artist;
|
||||
request.album = album;
|
||||
request.album = album2;
|
||||
request.search = false;
|
||||
request.id = next_id_++;
|
||||
|
||||
@ -52,10 +57,13 @@ quint64 AlbumCoverFetcher::FetchAlbumCover(const QString &artist, const QString
|
||||
}
|
||||
|
||||
quint64 AlbumCoverFetcher::SearchForCovers(const QString &artist, const QString &album) {
|
||||
|
||||
QString album2(album);
|
||||
album2 = album2.remove(QRegExp(" ?-? ?(\\(|\\[)(Disc|CD)? ?[0-9](\\)|\\])$"));
|
||||
|
||||
CoverSearchRequest request;
|
||||
request.artist = artist;
|
||||
request.album = album;
|
||||
request.album = album2;
|
||||
request.search = true;
|
||||
request.id = next_id_++;
|
||||
|
||||
|
@ -351,6 +351,7 @@ void AlbumCoverManager::CoverImageLoaded(quint64 id, const QImage &image) {
|
||||
|
||||
item->setIcon(QPixmap::fromImage(image));
|
||||
UpdateFilter();
|
||||
|
||||
}
|
||||
|
||||
void AlbumCoverManager::UpdateFilter() {
|
||||
|
@ -122,7 +122,7 @@ AlbumCoverSearcher::~AlbumCoverSearcher() {
|
||||
void AlbumCoverSearcher::Init(AlbumCoverFetcher *fetcher) {
|
||||
|
||||
fetcher_ = fetcher;
|
||||
connect(fetcher_, SIGNAL(SearchFinished(quint64,CoverSearchResults,CoverSearchStatistics)), SLOT(SearchFinished(quint64,CoverSearchResults)));
|
||||
connect(fetcher_, SIGNAL(SearchFinished(quint64,CoverSearchResults,CoverSearchStatistics)), SLOT(SearchFinished(quint64, CoverSearchResults)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ void DiscogsCoverProvider::HandleReleaseReply(QNetworkReply *reply, int s_id, in
|
||||
|
||||
DiscogsCoverReleaseContext *r_ctx;
|
||||
if (!requests_release_.contains(r_id)) {
|
||||
qLog(Error) << "Discogs: Got reply for cancelled request: " << r_id;
|
||||
//qLog(Error) << "Discogs: Got reply for cancelled request: " << r_id;
|
||||
return;
|
||||
}
|
||||
r_ctx = requests_release_.value(r_id);
|
||||
@ -337,10 +337,11 @@ void DiscogsCoverProvider::HandleReleaseReply(QNetworkReply *reply, int s_id, in
|
||||
}
|
||||
|
||||
void DiscogsCoverProvider::CancelSearch(int id) {
|
||||
|
||||
|
||||
//qLog(Debug) << __PRETTY_FUNCTION__ << id;
|
||||
|
||||
delete requests_search_.take(id);
|
||||
|
||||
}
|
||||
|
||||
void DiscogsCoverProvider::SearchRequestError(QNetworkReply::NetworkError error, QNetworkReply *reply, int s_id) {
|
||||
@ -365,7 +366,7 @@ void DiscogsCoverProvider::ReleaseRequestError(QNetworkReply::NetworkError error
|
||||
|
||||
DiscogsCoverSearchContext *s_ctx;
|
||||
if (!requests_search_.contains(s_id)) {
|
||||
qLog(Error) << "Discogs: got reply for cancelled request: " << s_id << " " << r_id;
|
||||
qLog(Error) << "Discogs: got reply for cancelled request: " << s_id << r_id;
|
||||
return;
|
||||
}
|
||||
s_ctx = requests_search_.value(s_id);
|
||||
@ -402,7 +403,7 @@ void DiscogsCoverProvider::EndSearch(DiscogsCoverSearchContext *s_ctx, DiscogsCo
|
||||
|
||||
void DiscogsCoverProvider::EndSearch(DiscogsCoverSearchContext *s_ctx) {
|
||||
|
||||
//qLog(Debug) << __PRETTY_FUNCTION__;
|
||||
//qLog(Debug) << "Discogs: Finished." << s_ctx->id;
|
||||
|
||||
(void)requests_search_.remove(s_ctx->id);
|
||||
emit SearchFinished(s_ctx->id, s_ctx->results);
|
||||
|
@ -53,13 +53,11 @@ LastFmCoverProvider::LastFmCoverProvider(QObject *parent) : CoverProvider("last.
|
||||
|
||||
bool LastFmCoverProvider::StartSearch(const QString &artist, const QString &album, int id) {
|
||||
|
||||
//qLog(Debug) << "LastFmCoverProvider artist:" << artist << "album:" << album;
|
||||
|
||||
QMap<QString, QString> params;
|
||||
params["method"] = "album.search";
|
||||
params["album"] = album + " " + artist;
|
||||
|
||||
QNetworkReply* reply = lastfm::ws::post(params);
|
||||
QNetworkReply *reply = lastfm::ws::post(params);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(QueryFinished(QNetworkReply*, int)), reply, id);
|
||||
|
||||
return true;
|
||||
@ -76,10 +74,11 @@ void LastFmCoverProvider::QueryFinished(QNetworkReply *reply, int id) {
|
||||
// parse the list of search results
|
||||
QList<lastfm::XmlQuery> elements = query["results"]["albummatches"].children("album");
|
||||
|
||||
for (const lastfm::XmlQuery& element : elements) {
|
||||
for (const lastfm::XmlQuery &element : elements) {
|
||||
CoverSearchResult result;
|
||||
result.description = element["artist"].text() + " - " + element["name"].text();
|
||||
result.image_url = QUrl(element["image size=extralarge"].text());
|
||||
if (result.image_url.isEmpty()) continue;
|
||||
results << result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user