Replace Spotify username/password with access token

This commit is contained in:
Jonas Kvinge 2024-09-28 00:09:23 +02:00
parent ca8aa40034
commit dae4943593
8 changed files with 11 additions and 82 deletions

View File

@ -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

View File

@ -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_;

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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.

View File

@ -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());

View File

@ -40,52 +40,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="group_device_credentials">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Device credentials</string>
</property>
<layout class="QFormLayout" name="layout_credential_group">
<item row="1" column="0">
<widget class="QLabel" name="label_username">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_password">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="password">
<property name="text">
<string notr="true"/>
</property>
<property name="echoMode">
<enum>QLineEdit::EchoMode::Password</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="username">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_warning" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -312,7 +266,6 @@
</customwidgets>
<tabstops>
<tabstop>enable</tabstop>
<tabstop>password</tabstop>
<tabstop>searchdelay</tabstop>
<tabstop>artistssearchlimit</tabstop>
<tabstop>albumssearchlimit</tabstop>

View File

@ -4410,9 +4410,6 @@ msgstr ""
msgid "Authenticate"
msgstr ""
msgid "Device credentials"
msgstr ""
msgid ""
"<html><head/><body><p>The GStreamer Spotify plugin is not detected, you will "
"not be able to stream songs from Spotify without it. See <a href=\"https://"