From 07d88e86a288ab11945099835e52e038ab495e57 Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Wed, 29 Jun 2022 23:27:44 +0300 Subject: [PATCH] Add support for `prefer album artist` option to ListenBrainz --- src/scrobbler/listenbrainzscrobbler.cpp | 12 +++++++++--- src/scrobbler/listenbrainzscrobbler.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/scrobbler/listenbrainzscrobbler.cpp b/src/scrobbler/listenbrainzscrobbler.cpp index 3e5d2532f..908d0ed24 100644 --- a/src/scrobbler/listenbrainzscrobbler.cpp +++ b/src/scrobbler/listenbrainzscrobbler.cpp @@ -46,6 +46,7 @@ #include "core/timeconstants.h" #include "core/logging.h" #include "internet/localredirectserver.h" +#include "settings/scrobblersettingspage.h" #include "audioscrobbler.h" #include "scrobblerservice.h" @@ -76,7 +77,8 @@ ListenBrainzScrobbler::ListenBrainzScrobbler(Application *app, QObject *parent) submitted_(false), scrobbled_(false), timestamp_(0), - submit_error_(false) { + submit_error_(false), + prefer_albumartist_(false) { refresh_login_timer_.setSingleShot(true); QObject::connect(&refresh_login_timer_, &QTimer::timeout, this, &ListenBrainzScrobbler::RequestNewAccessToken); @@ -114,6 +116,10 @@ void ListenBrainzScrobbler::ReloadSettings() { user_token_ = s.value("user_token").toString(); s.endGroup(); + s.beginGroup(ScrobblerSettingsPage::kSettingsGroup); + prefer_albumartist_ = s.value("albumartist", false).toBool(); + s.endGroup(); + } void ListenBrainzScrobbler::LoadSession() { @@ -429,7 +435,7 @@ void ListenBrainzScrobbler::UpdateNowPlaying(const Song &song) { title = title.remove(Song::kTitleRemoveMisc); QJsonObject object_track_metadata; - if (song.albumartist().isEmpty() || song.albumartist().compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { + if (!prefer_albumartist_ || song.albumartist().isEmpty() || song.albumartist().compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { object_track_metadata.insert("artist_name", QJsonValue::fromVariant(song.artist())); } else { @@ -552,7 +558,7 @@ void ListenBrainzScrobbler::Submit() { QJsonObject object_listen; object_listen.insert("listened_at", QJsonValue::fromVariant(item->timestamp_)); QJsonObject object_track_metadata; - if (item->albumartist_.isEmpty() || item->albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { + if (!prefer_albumartist_ || item->albumartist_.isEmpty() || item->albumartist_.compare(Song::kVariousArtists, Qt::CaseInsensitive) == 0) { object_track_metadata.insert("artist_name", QJsonValue::fromVariant(item->artist_)); } else { diff --git a/src/scrobbler/listenbrainzscrobbler.h b/src/scrobbler/listenbrainzscrobbler.h index 16a1a59d2..16771dc33 100644 --- a/src/scrobbler/listenbrainzscrobbler.h +++ b/src/scrobbler/listenbrainzscrobbler.h @@ -120,6 +120,8 @@ class ListenBrainzScrobbler : public ScrobblerService { QTimer timer_submit_; bool submit_error_; + bool prefer_albumartist_; + QList replies_; };