From 1dae80a633f674df4f67d38d9baa08051f332cea Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Thu, 4 Apr 2024 21:17:07 +0200 Subject: [PATCH] Add scrobbler option for stripping "remastered" etc Fixes #1387 --- src/scrobbler/audioscrobbler.h | 1 + src/scrobbler/listenbrainzscrobbler.cpp | 3 +-- src/scrobbler/listenbrainzscrobbler.h | 1 - src/scrobbler/scrobblerservice.cpp | 15 ++++++++++++--- src/scrobbler/scrobblerservice.h | 7 +++++-- src/scrobbler/scrobblersettings.cpp | 4 +++- src/scrobbler/scrobblersettings.h | 2 ++ src/scrobbler/scrobblingapi20.cpp | 3 +-- src/scrobbler/scrobblingapi20.h | 1 - src/scrobbler/subsonicscrobbler.cpp | 3 +-- src/scrobbler/subsonicscrobbler.h | 1 - src/settings/scrobblersettingspage.cpp | 2 ++ src/settings/scrobblersettingspage.ui | 7 +++++++ 13 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/scrobbler/audioscrobbler.h b/src/scrobbler/audioscrobbler.h index 31a6bea3..4e853b3c 100644 --- a/src/scrobbler/audioscrobbler.h +++ b/src/scrobbler/audioscrobbler.h @@ -68,6 +68,7 @@ class AudioScrobbler : public QObject { int submit_delay() const { return settings_->submit_delay(); } bool prefer_albumartist() const { return settings_->prefer_albumartist(); } bool ShowErrorDialog() const { return settings_->show_error_dialog(); } + bool strip_remastered() const { return settings_->strip_remastered(); } QList sources() const { return settings_->sources(); } void ShowConfig(); diff --git a/src/scrobbler/listenbrainzscrobbler.cpp b/src/scrobbler/listenbrainzscrobbler.cpp index a648a649..c988c631 100644 --- a/src/scrobbler/listenbrainzscrobbler.cpp +++ b/src/scrobbler/listenbrainzscrobbler.cpp @@ -67,8 +67,7 @@ const char *ListenBrainzScrobbler::kCacheFile = "listenbrainzscrobbler.cache"; const int ListenBrainzScrobbler::kScrobblesPerRequest = 10; ListenBrainzScrobbler::ListenBrainzScrobbler(SharedPtr settings, SharedPtr network, QObject *parent) - : ScrobblerService(kName, parent), - settings_(settings), + : ScrobblerService(kName, settings, parent), network_(network), cache_(new ScrobblerCache(kCacheFile, this)), server_(nullptr), diff --git a/src/scrobbler/listenbrainzscrobbler.h b/src/scrobbler/listenbrainzscrobbler.h index 19265599..476e0175 100644 --- a/src/scrobbler/listenbrainzscrobbler.h +++ b/src/scrobbler/listenbrainzscrobbler.h @@ -110,7 +110,6 @@ class ListenBrainzScrobbler : public ScrobblerService { static const char *kCacheFile; static const int kScrobblesPerRequest; - SharedPtr settings_; SharedPtr network_; ScrobblerCache *cache_; LocalRedirectServer *server_; diff --git a/src/scrobbler/scrobblerservice.cpp b/src/scrobbler/scrobblerservice.cpp index 5fafde72..716a1d4f 100644 --- a/src/scrobbler/scrobblerservice.cpp +++ b/src/scrobbler/scrobblerservice.cpp @@ -27,10 +27,11 @@ #include #include "scrobblerservice.h" +#include "scrobblersettings.h" #include "core/song.h" -ScrobblerService::ScrobblerService(const QString &name, QObject *parent) : QObject(parent), name_(name) {} +ScrobblerService::ScrobblerService(const QString &name, SharedPtr settings, QObject *parent) : QObject(parent), name_(name), settings_(settings) {} bool ScrobblerService::ExtractJsonObj(const QByteArray &data, QJsonObject &json_obj, QString &error_description) { @@ -52,12 +53,20 @@ bool ScrobblerService::ExtractJsonObj(const QByteArray &data, QJsonObject &json_ QString ScrobblerService::StripAlbum(const QString &album) const { - return Song::AlbumRemoveDisc(album); + if (settings_->strip_remastered()) { + return Song::AlbumRemoveDiscMisc(album); + } + + return Song::AlbumRemoveDisc(album);; } QString ScrobblerService::StripTitle(const QString &title) const { - return Song::TitleRemoveMisc(title); + if (settings_->strip_remastered()) { + return Song::TitleRemoveMisc(title); + } + + return title; } diff --git a/src/scrobbler/scrobblerservice.h b/src/scrobbler/scrobblerservice.h index b7b4ccd8..bc840293 100644 --- a/src/scrobbler/scrobblerservice.h +++ b/src/scrobbler/scrobblerservice.h @@ -33,11 +33,13 @@ #include "core/shared_ptr.h" #include "core/song.h" +#include "scrobblersettings.h" + class ScrobblerService : public QObject { Q_OBJECT public: - explicit ScrobblerService(const QString &name, QObject *parent); + explicit ScrobblerService(const QString &name, SharedPtr settings, QObject *parent); QString name() const { return name_; } @@ -71,8 +73,9 @@ class ScrobblerService : public QObject { signals: void ErrorMessage(const QString &error); - private: + protected: QString name_; + SharedPtr settings_; }; using ScrobblerServicePtr = SharedPtr; diff --git a/src/scrobbler/scrobblersettings.cpp b/src/scrobbler/scrobblersettings.cpp index 8ed3168f..835fbf62 100644 --- a/src/scrobbler/scrobblersettings.cpp +++ b/src/scrobbler/scrobblersettings.cpp @@ -38,7 +38,8 @@ ScrobblerSettings::ScrobblerSettings(Application *app, QObject *parent) love_button_(false), submit_delay_(0), prefer_albumartist_(false), - show_error_dialog_(false) { + show_error_dialog_(false), + strip_remastered_(false) { ReloadSettings(); @@ -55,6 +56,7 @@ void ScrobblerSettings::ReloadSettings() { submit_delay_ = s.value("submit", 0).toInt(); prefer_albumartist_ = s.value("albumartist", false).toBool(); show_error_dialog_ = s.value("show_error_dialog", true).toBool(); + strip_remastered_ = s.value("strip_remastered", true).toBool(); QStringList sources = s.value("sources").toStringList(); s.endGroup(); diff --git a/src/scrobbler/scrobblersettings.h b/src/scrobbler/scrobblersettings.h index 08be56c9..7afc6377 100644 --- a/src/scrobbler/scrobblersettings.h +++ b/src/scrobbler/scrobblersettings.h @@ -47,6 +47,7 @@ class ScrobblerSettings : public QObject { int submit_delay() const { return submit_delay_; } bool prefer_albumartist() const { return prefer_albumartist_; } bool show_error_dialog() const { return show_error_dialog_; } + bool strip_remastered() const { return strip_remastered_; } QList sources() const { return sources_; } void ShowConfig(); @@ -73,6 +74,7 @@ class ScrobblerSettings : public QObject { int submit_delay_; bool prefer_albumartist_; bool show_error_dialog_; + bool strip_remastered_; QList sources_; Q_DISABLE_COPY(ScrobblerSettings) diff --git a/src/scrobbler/scrobblingapi20.cpp b/src/scrobbler/scrobblingapi20.cpp index 72a9565f..0688a1d2 100644 --- a/src/scrobbler/scrobblingapi20.cpp +++ b/src/scrobbler/scrobblingapi20.cpp @@ -64,13 +64,12 @@ const char *ScrobblingAPI20::kSecret = "80fd738f49596e9709b1bf9319c444a8"; const int ScrobblingAPI20::kScrobblesPerRequest = 50; ScrobblingAPI20::ScrobblingAPI20(const QString &name, const QString &settings_group, const QString &auth_url, const QString &api_url, const bool batch, const QString &cache_file, SharedPtr settings, SharedPtr network, QObject *parent) - : ScrobblerService(name, parent), + : ScrobblerService(name, settings, parent), name_(name), settings_group_(settings_group), auth_url_(auth_url), api_url_(api_url), batch_(batch), - settings_(settings), network_(network), cache_(new ScrobblerCache(cache_file, this)), server_(nullptr), diff --git a/src/scrobbler/scrobblingapi20.h b/src/scrobbler/scrobblingapi20.h index ea71b6ed..a09d85f7 100644 --- a/src/scrobbler/scrobblingapi20.h +++ b/src/scrobbler/scrobblingapi20.h @@ -141,7 +141,6 @@ class ScrobblingAPI20 : public ScrobblerService { QString api_url_; bool batch_; - SharedPtr settings_; SharedPtr network_; ScrobblerCache *cache_; LocalRedirectServer *server_; diff --git a/src/scrobbler/subsonicscrobbler.cpp b/src/scrobbler/subsonicscrobbler.cpp index 2b07f1ad..89b5218d 100644 --- a/src/scrobbler/subsonicscrobbler.cpp +++ b/src/scrobbler/subsonicscrobbler.cpp @@ -43,8 +43,7 @@ const char *SubsonicScrobbler::kName = "Subsonic"; SubsonicScrobbler::SubsonicScrobbler(SharedPtr settings, Application *app, QObject *parent) - : ScrobblerService(kName, parent), - settings_(settings), + : ScrobblerService(kName, settings, parent), app_(app), service_(nullptr), enabled_(false), diff --git a/src/scrobbler/subsonicscrobbler.h b/src/scrobbler/subsonicscrobbler.h index 0c61c9e2..dc5e5d87 100644 --- a/src/scrobbler/subsonicscrobbler.h +++ b/src/scrobbler/subsonicscrobbler.h @@ -65,7 +65,6 @@ class SubsonicScrobbler : public ScrobblerService { void Submit() override; private: - SharedPtr settings_; Application *app_; SharedPtr service_; bool enabled_; diff --git a/src/settings/scrobblersettingspage.cpp b/src/settings/scrobblersettingspage.cpp index 43268be1..3a4074eb 100644 --- a/src/settings/scrobblersettingspage.cpp +++ b/src/settings/scrobblersettingspage.cpp @@ -98,6 +98,7 @@ void ScrobblerSettingsPage::Load() { ui_->spinbox_submit->setValue(scrobbler_->submit_delay()); ui_->checkbox_albumartist->setChecked(scrobbler_->prefer_albumartist()); ui_->checkbox_show_error_dialog->setChecked(scrobbler_->ShowErrorDialog()); + ui_->checkbox_strip_remastered->setChecked(scrobbler_->strip_remastered()); ui_->checkbox_source_collection->setChecked(scrobbler_->sources().contains(Song::Source::Collection)); ui_->checkbox_source_local->setChecked(scrobbler_->sources().contains(Song::Source::LocalFile)); @@ -139,6 +140,7 @@ void ScrobblerSettingsPage::Save() { s.setValue("submit", ui_->spinbox_submit->value()); s.setValue("albumartist", ui_->checkbox_albumartist->isChecked()); s.setValue("show_error_dialog", ui_->checkbox_show_error_dialog->isChecked()); + s.setValue("strip_remastered", ui_->checkbox_strip_remastered->isChecked()); QStringList sources; if (ui_->checkbox_source_collection->isChecked()) sources << Song::TextForSource(Song::Source::Collection); diff --git a/src/settings/scrobblersettingspage.ui b/src/settings/scrobblersettingspage.ui index 81313a6d..0245dc94 100644 --- a/src/settings/scrobblersettingspage.ui +++ b/src/settings/scrobblersettingspage.ui @@ -119,6 +119,13 @@ + + + + Strip "remastered" and similar from album and title + + +