From bab01291b1ecdaaf955f958a27dd51b420d04138 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 25 Dec 2018 22:58:34 +0100 Subject: [PATCH] Make scrobble submit delay configurable --- src/scrobbler/audioscrobbler.cpp | 8 ++-- src/scrobbler/audioscrobbler.h | 2 + src/scrobbler/lastfmscrobbler.cpp | 1 - src/scrobbler/librefmscrobbler.cpp | 1 - src/scrobbler/listenbrainzscrobbler.cpp | 9 +++- src/scrobbler/scrobblingapi20.cpp | 9 +++- src/settings/scrobblersettingspage.cpp | 2 + src/settings/scrobblersettingspage.ui | 56 ++++++++++++++++++++++++- 8 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/scrobbler/audioscrobbler.cpp b/src/scrobbler/audioscrobbler.cpp index 7352e03b8..2dfa8a611 100644 --- a/src/scrobbler/audioscrobbler.cpp +++ b/src/scrobbler/audioscrobbler.cpp @@ -39,11 +39,8 @@ #include "core/application.h" #include "core/closure.h" #include "core/logging.h" -#include "core/network.h" -#include "core/player.h" #include "core/song.h" -#include "core/taskmanager.h" -#include "core/iconloader.h" +#include "core/timeconstants.h" #include "settings/settingsdialog.h" #include "settings/scrobblersettingspage.h" @@ -150,6 +147,9 @@ void AudioScrobbler::Love(const Song &song) { void AudioScrobbler::Submit() { for (ScrobblerService *service : scrobbler_services_->List()) { if (!service->IsEnabled() || !service->IsAuthenticated() || service->IsSubmitted()) continue; + int msec = 300; + if (submit_delay_ > 0) msec = (submit_delay_ * kMsecPerSec); + DoAfter(this, SLOT(Submit()), msec); service->Submitted(); DoInAMinuteOrSo(service, SLOT(Submit())); } diff --git a/src/scrobbler/audioscrobbler.h b/src/scrobbler/audioscrobbler.h index fc87aaa02..3b243972d 100644 --- a/src/scrobbler/audioscrobbler.h +++ b/src/scrobbler/audioscrobbler.h @@ -47,6 +47,7 @@ class AudioScrobbler : public QObject { bool IsEnabled() const { return enabled_; } bool IsOffline() const { return offline_; } bool ScrobbleButton() const { return scrobble_button_; } + int SubmitDelay() const { return submit_delay_; } void UpdateNowPlaying(const Song &song); void Scrobble(const Song &song, const int scrobble_point); @@ -82,6 +83,7 @@ class AudioScrobbler : public QObject { bool enabled_; bool offline_; bool scrobble_button_; + int submit_delay_; }; diff --git a/src/scrobbler/lastfmscrobbler.cpp b/src/scrobbler/lastfmscrobbler.cpp index afa34eb0b..7b3405b87 100644 --- a/src/scrobbler/lastfmscrobbler.cpp +++ b/src/scrobbler/lastfmscrobbler.cpp @@ -42,7 +42,6 @@ #include #include "core/application.h" -#include "core/player.h" #include "core/closure.h" #include "core/network.h" #include "core/song.h" diff --git a/src/scrobbler/librefmscrobbler.cpp b/src/scrobbler/librefmscrobbler.cpp index 8dddfaa40..744c7ed31 100644 --- a/src/scrobbler/librefmscrobbler.cpp +++ b/src/scrobbler/librefmscrobbler.cpp @@ -42,7 +42,6 @@ #include #include "core/application.h" -#include "core/player.h" #include "core/closure.h" #include "core/network.h" #include "core/song.h" diff --git a/src/scrobbler/listenbrainzscrobbler.cpp b/src/scrobbler/listenbrainzscrobbler.cpp index aa1770c3f..234dda62a 100644 --- a/src/scrobbler/listenbrainzscrobbler.cpp +++ b/src/scrobbler/listenbrainzscrobbler.cpp @@ -42,7 +42,6 @@ #include #include "core/application.h" -#include "core/player.h" #include "core/closure.h" #include "core/network.h" #include "core/song.h" @@ -387,8 +386,14 @@ void ListenBrainzScrobbler::Scrobble(const Song &song) { } if (!submitted_) { - DoInAMinuteOrSo(this, SLOT(Submit())); submitted_ = true; + if (app_->scrobbler()->SubmitDelay() <= 0) { + Submit(); + } + else { + int msec = (app_->scrobbler()->SubmitDelay() * kMsecPerSec); + DoAfter(this, SLOT(Submit()), msec); + } } } diff --git a/src/scrobbler/scrobblingapi20.cpp b/src/scrobbler/scrobblingapi20.cpp index 967508b18..37b13062c 100644 --- a/src/scrobbler/scrobblingapi20.cpp +++ b/src/scrobbler/scrobblingapi20.cpp @@ -44,7 +44,6 @@ #include #include "core/application.h" -#include "core/player.h" #include "core/closure.h" #include "core/network.h" #include "core/song.h" @@ -420,8 +419,14 @@ void ScrobblingAPI20::Scrobble(const Song &song) { } if (!submitted_) { - DoInAMinuteOrSo(this, SLOT(Submit())); submitted_ = true; + if (!batch_ || app_->scrobbler()->SubmitDelay() <= 0) { + Submit(); + } + else { + int msec = (app_->scrobbler()->SubmitDelay() * kMsecPerSec); + DoAfter(this, SLOT(Submit()), msec); + } } } diff --git a/src/settings/scrobblersettingspage.cpp b/src/settings/scrobblersettingspage.cpp index 1470b1c8a..d5c8a89d5 100644 --- a/src/settings/scrobblersettingspage.cpp +++ b/src/settings/scrobblersettingspage.cpp @@ -82,6 +82,7 @@ void ScrobblerSettingsPage::Load() { ui_->checkbox_enable->setChecked(scrobbler_->IsEnabled()); ui_->checkbox_scrobble_button->setChecked(scrobbler_->ScrobbleButton()); ui_->checkbox_offline->setChecked(scrobbler_->IsOffline()); + ui_->spinbox_submit->setValue(scrobbler_->SubmitDelay()); ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->IsEnabled()); LastFM_RefreshControls(lastfmscrobbler_->IsAuthenticated()); @@ -103,6 +104,7 @@ void ScrobblerSettingsPage::Save() { s.setValue("enabled", ui_->checkbox_enable->isChecked()); s.setValue("scrobble_button", ui_->checkbox_scrobble_button->isChecked()); s.setValue("offline", ui_->checkbox_offline->isChecked()); + s.setValue("submit", ui_->spinbox_submit->value()); s.endGroup(); s.beginGroup(LastFMScrobbler::kSettingsGroup); diff --git a/src/settings/scrobblersettingspage.ui b/src/settings/scrobblersettingspage.ui index 5abdfe194..205ca5de8 100644 --- a/src/settings/scrobblersettingspage.ui +++ b/src/settings/scrobblersettingspage.ui @@ -7,7 +7,7 @@ 0 0 769 - 611 + 726 @@ -27,6 +27,16 @@ + + + + Songs are scrobbled if they have valid metadata and are longer than 30 seconds, have been playing for at least half its duration or for 4 minutes (whichever occurs earlier). + + + true + + + @@ -41,6 +51,50 @@ + + + + + + Submit scrobbles every + + + + + + + minutes + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + (This is the delay between when a song is scrobbled and when scrobbles are submitted to the server. Settings the time to 0 minutes will submit scrobbles immediately). + + + true + + +