mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-02 10:36:45 +01:00
Use timers for submitting scrobbles
This commit is contained in:
parent
cc6c7430d4
commit
be051a4bb1
@ -27,6 +27,7 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QNetworkRequest>
|
||||
@ -35,7 +36,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QTimer>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/application.h"
|
||||
@ -43,7 +43,6 @@
|
||||
#include "core/song.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/closure.h"
|
||||
#include "internet/localredirectserver.h"
|
||||
|
||||
#include "audioscrobbler.h"
|
||||
@ -78,6 +77,9 @@ ListenBrainzScrobbler::ListenBrainzScrobbler(Application *app, QObject *parent)
|
||||
refresh_login_timer_.setSingleShot(true);
|
||||
QObject::connect(&refresh_login_timer_, &QTimer::timeout, this, &ListenBrainzScrobbler::RequestNewAccessToken);
|
||||
|
||||
timer_submit_.setSingleShot(true);
|
||||
QObject::connect(&timer_submit_, &QTimer::timeout, this, &ListenBrainzScrobbler::Submit);
|
||||
|
||||
ReloadSettings();
|
||||
LoadSession();
|
||||
|
||||
@ -519,9 +521,9 @@ void ListenBrainzScrobbler::Scrobble(const Song &song) {
|
||||
if (app_->scrobbler()->SubmitDelay() <= 0) {
|
||||
Submit();
|
||||
}
|
||||
else {
|
||||
qint64 msec = (app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
DoAfter(this, SLOT(Submit()), msec);
|
||||
else if (!timer_submit_.isActive()) {
|
||||
timer_submit_.setInterval(app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
timer_submit_.start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,9 +533,10 @@ void ListenBrainzScrobbler::DoSubmit() {
|
||||
|
||||
if (!submitted_ && cache_->Count() > 0) {
|
||||
submitted_ = true;
|
||||
qint64 msec = 30000ll;
|
||||
if (app_->scrobbler()->SubmitDelay() != 0) msec = (app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
DoAfter(this, SLOT(Submit()), msec);
|
||||
if (!timer_submit_.isActive()) {
|
||||
timer_submit_.setInterval(app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
timer_submit_.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ class ListenBrainzScrobbler : public ScrobblerService {
|
||||
bool scrobbled_;
|
||||
quint64 timestamp_;
|
||||
QTimer refresh_login_timer_;
|
||||
QTimer timer_submit_;
|
||||
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QCryptographicHash>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
@ -50,7 +51,6 @@
|
||||
#include "core/song.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/closure.h"
|
||||
#include "internet/localredirectserver.h"
|
||||
#include "settings/scrobblersettingspage.h"
|
||||
|
||||
@ -78,7 +78,12 @@ ScrobblingAPI20::ScrobblingAPI20(const QString &name, const QString &settings_gr
|
||||
subscriber_(false),
|
||||
submitted_(false),
|
||||
scrobbled_(false),
|
||||
timestamp_(0) {}
|
||||
timestamp_(0) {
|
||||
|
||||
timer_submit_.setSingleShot(true);
|
||||
QObject::connect(&timer_submit_, &QTimer::timeout, this, &ScrobblingAPI20::Submit);
|
||||
|
||||
}
|
||||
|
||||
ScrobblingAPI20::~ScrobblingAPI20() {
|
||||
|
||||
@ -545,9 +550,9 @@ void ScrobblingAPI20::Scrobble(const Song &song) {
|
||||
if (!batch_ || app_->scrobbler()->SubmitDelay() <= 0) {
|
||||
Submit();
|
||||
}
|
||||
else {
|
||||
qint64 msec = (app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
DoAfter(this, SLOT(Submit()), msec);
|
||||
else if (!timer_submit_.isActive()) {
|
||||
timer_submit_.setInterval(app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
timer_submit_.start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,9 +562,10 @@ void ScrobblingAPI20::DoSubmit() {
|
||||
|
||||
if (!submitted_ && cache()->Count() > 0) {
|
||||
submitted_ = true;
|
||||
qint64 msec = 30000ll;
|
||||
if (app_->scrobbler()->SubmitDelay() != 0) msec = (app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
DoAfter(this, SLOT(Submit()), msec);
|
||||
if (!timer_submit_.isActive()) {
|
||||
timer_submit_.setInterval(app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
timer_submit_.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "scrobblerservice.h"
|
||||
@ -155,6 +156,8 @@ class ScrobblingAPI20 : public ScrobblerService {
|
||||
bool scrobbled_;
|
||||
quint64 timestamp_;
|
||||
|
||||
QTimer timer_submit_;
|
||||
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "core/song.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/closure.h"
|
||||
#include "internet/internetservices.h"
|
||||
#include "settings/subsonicsettingspage.h"
|
||||
#include "subsonic/subsonicservice.h"
|
||||
@ -48,7 +47,8 @@ SubsonicScrobbler::SubsonicScrobbler(Application *app, QObject *parent) : Scrobb
|
||||
enabled_(false),
|
||||
submitted_(false) {
|
||||
|
||||
ReloadSettings();
|
||||
timer_submit_.setSingleShot(true);
|
||||
QObject::connect(&timer_submit_, &QTimer::timeout, this, &SubsonicScrobbler::Submit);
|
||||
|
||||
}
|
||||
|
||||
@ -83,9 +83,7 @@ void SubsonicScrobbler::ClearPlaying() {
|
||||
|
||||
void SubsonicScrobbler::Scrobble(const Song &song) {
|
||||
|
||||
if (song.source() != Song::Source::Source_Subsonic) return;
|
||||
|
||||
if (song.id() != song_playing_.id() || song.url() != song_playing_.url() || !song.is_metadata_good()) return;
|
||||
if (song.source() != Song::Source::Source_Subsonic || song.id() != song_playing_.id() || song.url() != song_playing_.url() || !song.is_metadata_good()) return;
|
||||
|
||||
if (app_->scrobbler()->IsOffline()) return;
|
||||
|
||||
@ -94,9 +92,9 @@ void SubsonicScrobbler::Scrobble(const Song &song) {
|
||||
if (app_->scrobbler()->SubmitDelay() <= 0) {
|
||||
Submit();
|
||||
}
|
||||
else {
|
||||
qint64 msec = (app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
DoAfter(this, SLOT(Submit()), msec);
|
||||
else if (!timer_submit_.isActive()) {
|
||||
timer_submit_.setInterval(app_->scrobbler()->SubmitDelay() * 60 * kMsecPerSec);
|
||||
timer_submit_.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "scrobblerservice.h"
|
||||
@ -68,6 +69,7 @@ class SubsonicScrobbler : public ScrobblerService {
|
||||
bool submitted_;
|
||||
Song song_playing_;
|
||||
QDateTime time_;
|
||||
QTimer timer_submit_;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user