From dae4943593fd779030cb122c035ecfffc7f7ae34 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 28 Sep 2024 00:09:23 +0200 Subject: [PATCH] Replace Spotify username/password with access token --- src/engine/enginebase.cpp | 5 +-- src/engine/enginebase.h | 3 +- src/engine/gstengine.cpp | 2 +- src/engine/gstenginepipeline.cpp | 19 ++++------- src/engine/gstenginepipeline.h | 5 ++- src/settings/spotifysettingspage.cpp | 9 ------ src/settings/spotifysettingspage.ui | 47 ---------------------------- src/translations/translations.pot | 3 -- 8 files changed, 11 insertions(+), 82 deletions(-) diff --git a/src/engine/enginebase.cpp b/src/engine/enginebase.cpp index c78da34c4..ce15614e5 100644 --- a/src/engine/enginebase.cpp +++ b/src/engine/enginebase.cpp @@ -246,10 +246,7 @@ void EngineBase::ReloadSettings() { #ifdef HAVE_SPOTIFY s.beginGroup(SpotifySettingsPage::kSettingsGroup); - spotify_username_ = s.value("username").toString(); - QByteArray password = s.value("password").toByteArray(); - if (password.isEmpty()) spotify_password_.clear(); - else spotify_password_ = QString::fromUtf8(QByteArray::fromBase64(password)); + spotify_access_token_ = s.value("access_token").toString(); s.endGroup(); #endif diff --git a/src/engine/enginebase.h b/src/engine/enginebase.h index 2fab9e9c5..0dc877398 100644 --- a/src/engine/enginebase.h +++ b/src/engine/enginebase.h @@ -249,8 +249,7 @@ class EngineBase : public QObject { // Spotify #ifdef HAVE_SPOTIFY - QString spotify_username_; - QString spotify_password_; + QString spotify_access_token_; #endif bool about_to_end_emitted_; diff --git a/src/engine/gstengine.cpp b/src/engine/gstengine.cpp index 1805668fd..ca77cff2a 100644 --- a/src/engine/gstengine.cpp +++ b/src/engine/gstengine.cpp @@ -915,7 +915,7 @@ GstEnginePipelinePtr GstEngine::CreatePipeline() { pipeline->set_fading_enabled(fadeout_enabled_ || autocrossfade_enabled_ || fadeout_pause_enabled_); #ifdef HAVE_SPOTIFY - pipeline->set_spotify_login(spotify_username_, spotify_password_); + pipeline->set_spotify_access_token(spotify_access_token_); #endif pipeline->AddBufferConsumer(this); diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 1cd72ad36..244e8bb44 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -277,13 +277,9 @@ void GstEnginePipeline::set_fading_enabled(const bool enabled) { } #ifdef HAVE_SPOTIFY -void GstEnginePipeline::set_spotify_login(const QString &spotify_username, const QString &spotify_password) { - - spotify_username_ = spotify_username; - spotify_password_ = spotify_password; - +void GstEnginePipeline::set_spotify_access_token(const QString &spotify_access_token) { + spotify_access_token_ = spotify_access_token; } - #endif // HAVE_SPOTIFY QString GstEnginePipeline::GstStateText(const GstState state) { @@ -1052,16 +1048,13 @@ void GstEnginePipeline::SourceSetupCallback(GstElement *playbin, GstElement *sou #ifdef HAVE_SPOTIFY { QMutexLocker l(&instance->mutex_url_); - if (instance->media_url_.scheme() == QStringLiteral("spotify")) { + if (instance->media_url_.scheme() == u"spotify"_s) { if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "bitrate")) { g_object_set(source, "bitrate", 2, nullptr); } - if (!instance->spotify_username_.isEmpty() && - !instance->spotify_password_.isEmpty() && - g_object_class_find_property(G_OBJECT_GET_CLASS(source), "username") && - g_object_class_find_property(G_OBJECT_GET_CLASS(source), "password")) { - g_object_set(source, "username", instance->spotify_username_.toUtf8().constData(), nullptr); - g_object_set(source, "password", instance->spotify_password_.toUtf8().constData(), nullptr); + if (!instance->spotify_access_token_.isEmpty() && g_object_class_find_property(G_OBJECT_GET_CLASS(source), "access-token")) { + const QByteArray access_token = instance->spotify_access_token_.toUtf8(); + g_object_set(source, "access-token", access_token.constData(), nullptr); } } } diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index afe1cf774..b3161d125 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -79,7 +79,7 @@ class GstEnginePipeline : public QObject { void set_strict_ssl_enabled(const bool enabled); void set_fading_enabled(const bool enabled); #ifdef HAVE_SPOTIFY - void set_spotify_login(const QString &spotify_username, const QString &spotify_password); + void set_spotify_access_token(const QString &spotify_access_token); #endif bool Finish(); @@ -259,8 +259,7 @@ class GstEnginePipeline : public QObject { // Spotify #ifdef HAVE_SPOTIFY - QString spotify_username_; - QString spotify_password_; + QString spotify_access_token_; #endif // The URL that is currently playing, and the URL that is to be preloaded when the current track is close to finishing. diff --git a/src/settings/spotifysettingspage.cpp b/src/settings/spotifysettingspage.cpp index 67d8cd4d3..bbc156cd8 100644 --- a/src/settings/spotifysettingspage.cpp +++ b/src/settings/spotifysettingspage.cpp @@ -87,11 +87,6 @@ void SpotifySettingsPage::Load() { s.beginGroup(kSettingsGroup); ui_->enable->setChecked(s.value("enabled", false).toBool()); - ui_->username->setText(s.value("username").toString()); - QByteArray password = s.value("password").toByteArray(); - if (password.isEmpty()) ui_->password->clear(); - else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password))); - ui_->searchdelay->setValue(s.value("searchdelay", 1500).toInt()); ui_->artistssearchlimit->setValue(s.value("artistssearchlimit", 4).toInt()); ui_->albumssearchlimit->setValue(s.value("albumssearchlimit", 10).toInt()); @@ -114,10 +109,6 @@ void SpotifySettingsPage::Save() { Settings s; s.beginGroup(kSettingsGroup); s.setValue("enabled", ui_->enable->isChecked()); - - s.setValue("username", ui_->username->text()); - s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64())); - s.setValue("searchdelay", ui_->searchdelay->value()); s.setValue("artistssearchlimit", ui_->artistssearchlimit->value()); s.setValue("albumssearchlimit", ui_->albumssearchlimit->value()); diff --git a/src/settings/spotifysettingspage.ui b/src/settings/spotifysettingspage.ui index 8e3df1f30..d047fea8d 100644 --- a/src/settings/spotifysettingspage.ui +++ b/src/settings/spotifysettingspage.ui @@ -40,52 +40,6 @@ - - - - - 0 - 0 - - - - Device credentials - - - - - - Username - - - - - - - Password - - - - - - - - - - QLineEdit::EchoMode::Password - - - - - - - - - - - - - @@ -312,7 +266,6 @@ enable - password searchdelay artistssearchlimit albumssearchlimit diff --git a/src/translations/translations.pot b/src/translations/translations.pot index d016d666f..0ff05a39e 100644 --- a/src/translations/translations.pot +++ b/src/translations/translations.pot @@ -4410,9 +4410,6 @@ msgstr "" msgid "Authenticate" msgstr "" -msgid "Device credentials" -msgstr "" - msgid "" "

The GStreamer Spotify plugin is not detected, you will " "not be able to stream songs from Spotify without it. See