Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Tell the user Premium is needed instead of dying
Lelonioa2b8635a4d81
diff --git a/README.md b/README.mdindex 371c4cd..1a67dd5 100644--- a/README.md+++ b/README.md@@ -132,10 +132,11 @@ keyPassword=…## Notes for anyone reading the code**`librespot-core` is patched.** A local copy under `native/vendor/`, wired in-with `[patch.crates-io]`. Three changes: the advertised OS is pinned to+with `[patch.crates-io]`. Four changes: the advertised OS is pinned to`"linux"` so it agrees with the desktop client id, Mercury gained POST and-header fields so listening events can be posted, and the session carries a-language so artwork comes back in it. All three are explained in+header fields so listening events can be posted, the session carries a language+so artwork comes back in it, and a non-premium account no longer exits the+process. All four are explained in[native/vendor/README.md](native/vendor/README.md).**OAuth uses the keymaster client id on a fixed port.** The redirect has to bediff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.ktindex df87730..1f99815 100644--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt@@ -208,7 +208,16 @@ class PlaybackService : MediaLibraryService() {// longer usable, so send the user back through OAuth rather than// retrying with the same credentials. A revoked refresh token is// already cleared by TokenStore before it gets here.- if (error.message?.contains("login failed") == true) {+ if (error.message?.contains(PREMIUM_REQUIRED) == true) {+ // Back to the login screen, with a reason. Staying signed in+ // would leave an app that looks connected and plays nothing.+ tokens.clear()+ android.widget.Toast.makeText(+ this@PlaybackService,+ getString(dev.lelonio.square.R.string.premium_required),+ android.widget.Toast.LENGTH_LONG,+ ).show()+ } else if (error.message?.contains("login failed") == true) {tokens.clear()}}.onSuccess {@@ -356,6 +365,9 @@ class PlaybackService : MediaLibraryService() {/** How often the position is written back while playing. */private const val SAVE_INTERVAL_MS = 10_000L+ /** What the engine reports for an account it cannot stream to. */+ private const val PREMIUM_REQUIRED = "premium account required"+/** Tells the service a Spotify session now exists. */const val ACTION_CONNECT = "dev.lelonio.square.action.CONNECT"diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xmlindex f702424..5d2e66c 100644--- a/app/src/main/res/values-de/strings.xml+++ b/app/src/main/res/values-de/strings.xml@@ -183,4 +183,5 @@<string name="quality_low">Niedrig</string><string name="quality_auto_note">Volle Qualität im WLAN, eine Stufe darunter bei getakteten Verbindungen.</string><string name="quality_restarts">Beim Ändern wird der laufende Titel neu geladen.</string>+ <string name="premium_required">Square braucht Spotify Premium. Ein kostenloses Konto kann sich anmelden, aber Spotify streamt nicht an einen Client wie diesen.</string></resources>diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xmlindex 1811c83..3b1ed64 100644--- a/app/src/main/res/values-es/strings.xml+++ b/app/src/main/res/values-es/strings.xml@@ -183,4 +183,5 @@<string name="quality_low">Baja</string><string name="quality_auto_note">Calidad plena con wi-fi, un paso menos con datos medidos.</string><string name="quality_restarts">Al cambiarla, la canción en curso se vuelve a cargar.</string>+ <string name="premium_required">Square necesita Spotify Premium. Una cuenta gratuita puede entrar, pero Spotify no transmite a un cliente como este.</string></resources>diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xmlindex a9a5316..410cf03 100644--- a/app/src/main/res/values-fr/strings.xml+++ b/app/src/main/res/values-fr/strings.xml@@ -183,4 +183,5 @@<string name="quality_low">Basse</string><string name="quality_auto_note">Qualité maximale en wi-fi, un cran en dessous sur une connexion facturée.</string><string name="quality_restarts">La changer recharge le titre en cours.</string>+ <string name="premium_required">Square demande Spotify Premium. Un compte gratuit peut se connecter, mais Spotify ne diffuse pas vers un client comme celui-ci.</string></resources>diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xmlindex cd371d9..42f8031 100644--- a/app/src/main/res/values-it/strings.xml+++ b/app/src/main/res/values-it/strings.xml@@ -184,4 +184,5 @@<string name="quality_low">Bassa</string><string name="quality_auto_note">Qualità piena sul wi-fi, un gradino sotto con la rete a consumo.</string><string name="quality_restarts">Cambiandola, la canzone in corso viene ricaricata.</string>+ <string name="premium_required">Square richiede Spotify Premium. Un account free riesce ad accedere, ma Spotify non trasmette a un client come questo.</string></resources>diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xmlindex 0a3a9e6..ced5bfe 100644--- a/app/src/main/res/values-pt/strings.xml+++ b/app/src/main/res/values-pt/strings.xml@@ -183,4 +183,5 @@<string name="quality_low">Baixa</string><string name="quality_auto_note">Qualidade máxima no wi-fi, um degrau abaixo em ligação tarifada.</string><string name="quality_restarts">Ao mudá-la, a faixa em curso é recarregada.</string>+ <string name="premium_required">O Square precisa de Spotify Premium. Uma conta gratuita consegue entrar, mas o Spotify não transmite para um cliente como este.</string></resources>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 246e5e1..d404016 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -204,4 +204,5 @@<string name="quality_low">Low</string><string name="quality_auto_note">Full quality on wi-fi, one step down on a metered connection.</string><string name="quality_restarts">Changing this reloads what is playing.</string>+ <string name="premium_required">Square needs Spotify Premium. A free account can sign in, but Spotify does not stream to a client like this one.</string></resources>diff --git a/native/src/engine.rs b/native/src/engine.rsindex 66c4299..5832bc3 100644--- a/native/src/engine.rs+++ b/native/src/engine.rs@@ -283,6 +283,18 @@ pub fn start(cache.save_credentials(&credentials);}+ // Checked here rather than left to the library. The vendored+ // librespot-core used to call exit(1) on a non-premium account, which+ // took the app's process down and left Android restarting the service+ // in a loop; it now only logs, so the refusal has to be made an error+ // the caller can show.+ if let Some(account_type) = session.get_user_attribute("type") {+ if account_type != "premium" {+ session.shutdown();+ return Err(PREMIUM_REQUIRED.to_string());+ }+ }+Ok::<_, String>((session, player, spirc, spirc_task))})?;@@ -771,6 +783,11 @@ fn sweep_stale_downloads(dir: &str) {}}+/// What `start` returns for an account Spotify does not stream to this client.+///+/// Matched by the Kotlin side, so it stays a stable string.+pub const PREMIUM_REQUIRED: &str = "premium account required";+/// How far into a track its successor is fetched, in milliseconds.const PRELOAD_AFTER_MS: u32 = 5_000;diff --git a/native/vendor/README.md b/native/vendor/README.mdindex c5dde34..4f5a575 100644--- a/native/vendor/README.md+++ b/native/vendor/README.md@@ -72,6 +72,27 @@ sends it as `Accept-Language`. The app fills it from the device locale.Not everything follows it: the charts, daylist, blend and seed-mix covers arepicked by the server from the account's own language and stay English.+#### 4. `src/session.rs` — a non-premium account is not a reason to exit++Upstream refuses to run on a free account, and does it by calling+`std::process::exit(1)` from inside `check_catalogue`, with a TODO of its own+saying it should log out instead:++```rust+- // TODO: logout instead of exiting+- exit(1);+```++That ends a command-line daemon tidily. Inside an Android app it takes the whole+process down: the service dies mid-login, Android restarts it, the same account+authenticates again, and the loop repeats with a growing backoff and no message+anywhere. From the outside the app simply vanishes.++The check now only logs, and `engine::start` reads the `type` attribute itself+and returns `premium account required`, which the service turns into a message+and a return to the login screen. The refusal is unchanged; what changed is that+it is an error the caller can handle rather than a process exit.+### MaintenanceRe-apply this patch when bumping `librespot-core`. If the whole file is replaced,diff --git a/native/vendor/librespot-core/src/session.rs b/native/vendor/librespot-core/src/session.rsindex 333678f..c146dec 100644--- a/native/vendor/librespot-core/src/session.rs+++ b/native/vendor/librespot-core/src/session.rs@@ -3,7 +3,6 @@ use std::{future::Future,io,pin::Pin,- process::exit,sync::{Arc, OnceLock, RwLock, Weak},task::{Context, Poll},time::{Duration, SystemTime, UNIX_EPOCH},@@ -361,14 +360,17 @@ impl Session {);}+ /// Local patch: reports the account type instead of killing the process.+ ///+ /// Upstream calls `exit(1)` here, with a TODO of its own saying it should+ /// log out instead. That ends a command-line daemon; inside an Android app+ /// it takes the whole process down, and the system then restarts the+ /// service in a loop with no message anywhere. The caller reads the `type`+ /// attribute and decides.fn check_catalogue(attributes: &UserAttributes) {if let Some(account_type) = attributes.get("type") {if account_type != "premium" {- error!("librespot does not support {account_type:?} accounts.");- info!("Please support Spotify and your artists and sign up for a premium account.");-- // TODO: logout instead of exiting- exit(1);+ error!("account type is {account_type:?}, not premium.");}}}