1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-28 09:10:58 +01:00

Add setting for enabling scrobbling based on song source

Fixes #416
This commit is contained in:
Jonas Kvinge 2020-08-25 23:44:27 +02:00
parent ae48008803
commit 1431916183
6 changed files with 193 additions and 1 deletions

View File

@ -480,6 +480,21 @@ QString Song::TextForSource(Source source) {
}
Song::Source Song::SourceFromText(const QString &source) {
if (source == "file") return Source_LocalFile;
if (source == "collection") return Source_Collection;
if (source == "cd") return Source_CDDA;
if (source == "device") return Source_Device;
if (source == "stream") return Source_Stream;
if (source == "tidal") return Source_Tidal;
if (source == "subsonic") return Source_Subsonic;
if (source == "qobuz") return Source_Qobuz;
return Source_Unknown;
}
QIcon Song::IconForSource(Source source) {
switch (source) {

View File

@ -132,6 +132,7 @@ class Song {
static Source SourceFromURL(const QUrl &url);
static QString TextForSource(Source source);
static Song::Source SourceFromText(const QString &source);
static QIcon IconForSource(Source source);
static QString TextForFiletype(FileType filetype);
static QString ExtensionForFiletype(FileType filetype);

View File

@ -74,8 +74,28 @@ void AudioScrobbler::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();
QStringList sources = s.value("sources").toStringList();
s.endGroup();
sources_.clear();
if (sources.isEmpty()) {
sources_ << Song::Source_Unknown
<< Song::Source_LocalFile
<< Song::Source_Collection
<< Song::Source_CDDA
<< Song::Source_Device
<< Song::Source_Stream
<< Song::Source_Tidal
<< Song::Source_Subsonic
<< Song::Source_Qobuz;
}
else {
for (const QString &source : sources) {
sources_ << Song::SourceFromText(source);
}
}
emit ScrobblingEnabledChanged(enabled_);
emit ScrobbleButtonVisibilityChanged(scrobble_button_);
emit LoveButtonVisibilityChanged(love_button_);
@ -122,6 +142,8 @@ void AudioScrobbler::ShowConfig() {
void AudioScrobbler::UpdateNowPlaying(const Song &song) {
if (!sources_.contains(song.source())) return;
qLog(Debug) << "Sending now playing for song" << song.artist() << song.album() << song.title();
for (ScrobblerService *service : scrobbler_services_->List()) {
@ -142,6 +164,8 @@ void AudioScrobbler::ClearPlaying() {
void AudioScrobbler::Scrobble(const Song &song, const int scrobble_point) {
if (!sources_.contains(song.source())) return;
qLog(Debug) << "Scrobbling song" << song.artist() << song.album() << song.title() << "at" << scrobble_point;
for (ScrobblerService *service : scrobbler_services_->List()) {

View File

@ -23,8 +23,10 @@
#include "config.h"
#include <QObject>
#include <QList>
#include <QString>
#include "core/song.h"
#include "scrobblerservices.h"
class Application;
@ -46,6 +48,7 @@ class AudioScrobbler : public QObject {
int SubmitDelay() const { return submit_delay_; }
bool PreferAlbumArtist() const { return prefer_albumartist_; }
bool ShowErrorDialog() const { return show_error_dialog_; }
QList<Song::Source> sources() const { return sources_; }
void UpdateNowPlaying(const Song &song);
void ClearPlaying();
@ -86,6 +89,7 @@ class AudioScrobbler : public QObject {
int submit_delay_;
bool prefer_albumartist_;
bool show_error_dialog_;
QList<Song::Source> sources_;
};

View File

@ -33,6 +33,7 @@
#include "settingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "core/song.h"
#include "widgets/loginstatewidget.h"
#include "scrobbler/audioscrobbler.h"
@ -96,6 +97,15 @@ void ScrobblerSettingsPage::Load() {
ui_->checkbox_albumartist->setChecked(scrobbler_->PreferAlbumArtist());
ui_->checkbox_show_error_dialog->setChecked(scrobbler_->ShowErrorDialog());
ui_->checkbox_source_collection->setChecked(scrobbler_->sources().contains(Song::Source_Collection));
ui_->checkbox_source_local->setChecked(scrobbler_->sources().contains(Song::Source_LocalFile));
ui_->checkbox_source_cdda->setChecked(scrobbler_->sources().contains(Song::Source_CDDA));
ui_->checkbox_source_device->setChecked(scrobbler_->sources().contains(Song::Source_Device));
ui_->checkbox_source_tidal->setChecked(scrobbler_->sources().contains(Song::Source_Tidal));
ui_->checkbox_source_subsonic->setChecked(scrobbler_->sources().contains(Song::Source_Subsonic));
ui_->checkbox_source_stream->setChecked(scrobbler_->sources().contains(Song::Source_Stream));
ui_->checkbox_source_unknown->setChecked(scrobbler_->sources().contains(Song::Source_Unknown));
ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->IsEnabled());
ui_->checkbox_lastfm_https->setChecked(lastfmscrobbler_->IsUseHTTPS());
LastFM_RefreshControls(lastfmscrobbler_->IsAuthenticated());
@ -123,6 +133,19 @@ 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());
QStringList sources;
if (ui_->checkbox_source_collection->isChecked()) sources << Song::TextForSource(Song::Source_Collection);
if (ui_->checkbox_source_local->isChecked()) sources << Song::TextForSource(Song::Source_LocalFile);
if (ui_->checkbox_source_cdda->isChecked()) sources << Song::TextForSource(Song::Source_CDDA);
if (ui_->checkbox_source_device->isChecked()) sources << Song::TextForSource(Song::Source_Device);
if (ui_->checkbox_source_tidal->isChecked()) sources << Song::TextForSource(Song::Source_Tidal);
if (ui_->checkbox_source_subsonic->isChecked()) sources << Song::TextForSource(Song::Source_Subsonic);
if (ui_->checkbox_source_stream->isChecked()) sources << Song::TextForSource(Song::Source_Stream);
if (ui_->checkbox_source_unknown->isChecked()) sources << Song::TextForSource(Song::Source_Unknown);
s.setValue("sources", sources);
s.endGroup();
s.beginGroup(LastFMScrobbler::kSettingsGroup);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>460</width>
<height>960</height>
<height>1009</height>
</rect>
</property>
<property name="windowTitle">
@ -116,6 +116,131 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Enable scrobbling for the following sources:</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="checkbox_source_collection">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Collection</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkbox_source_tidal">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Tidal</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkbox_source_cdda">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>CDDA</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkbox_source_stream">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Stream</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="checkbox_source_unknown">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Unknown</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkbox_source_subsonic">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Subsonic</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkbox_source_local">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Local file</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkbox_source_device">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Device</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_lastfm">
<property name="title">