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
An account Spotify refuses every song is told so, not to wait
Lelonioe71a746cf7be
diff --git a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.ktindex 7e07747..9f7903d 100644--- a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt+++ b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt@@ -1312,7 +1312,7 @@ class LibrespotPlayer(// behind whatever the player is in the middle of.if (dev.lelonio.square.download.DownloadEvents.accept(type, uri, positionMs)) returnif (type == "key_refused") {- handler.post { onKeyRefused(positionMs == 1L) }+ handler.post { onKeyRefused(positionMs) }return}handler.post { applyEvent(type, uri, positionMs) }@@ -1322,22 +1322,46 @@ class LibrespotPlayer(private var refusalShown = false/**- * Spotify refusing the key a song needs to play, or giving them again.+ * Where it is remembered that Spotify refuses this account every song,+ * across restarts: a fresh start would otherwise tell them to try again in+ * a few minutes all over again. Forgotten when a song plays.+ */+ private val keyNotes by lazy {+ appContext.getSharedPreferences("square_keys", android.content.Context.MODE_PRIVATE)+ }++ /**+ * Spotify refusing the key a song needs to play, or giving them again: 0+ * over, 1 refused, 2 refused to this account whatever is tried; see+ * audio_key.rs.*- * Said once for a run of refusals, in words for the listener rather than- * the reason: otherwise the song sits at the start with no time on it, and- * what that looks like is the app broken.+ * Said in words for the listener rather than the reason: otherwise the+ * song sits at the start with no time on it, and what that looks like is+ * the app broken. Once for a run of refusals, and once more if the run+ * turns out to be the account's, since the advice is not the same.*/- private fun onKeyRefused(refused: Boolean) {- if (!refused) {+ private fun onKeyRefused(what: Long) {+ if (what == 0L) {refusalShown = false+ keyNotes.edit().remove(ACCOUNT_REFUSED).apply()+ return+ }+ val account = what == 2L || keyNotes.getBoolean(ACCOUNT_REFUSED, false)+ if (what == 2L) {+ keyNotes.edit().putBoolean(ACCOUNT_REFUSED, true).apply()+ } else if (refusalShown) {return}- if (refusalShown) returnrefusalShown = trueandroid.widget.Toast.makeText(appContext,- appContext.getString(dev.lelonio.square.R.string.playback_refused),+ appContext.getString(+ if (account) {+ dev.lelonio.square.R.string.playback_refused_account+ } else {+ dev.lelonio.square.R.string.playback_refused+ },+ ),android.widget.Toast.LENGTH_LONG,).show()}@@ -1407,6 +1431,11 @@ class LibrespotPlayer()}+ // A song playing is the account being given keys after all.+ if (type == "playing" && keyNotes.contains(ACCOUNT_REFUSED)) {+ keyNotes.edit().remove(ACCOUNT_REFUSED).apply()+ }+// Nothing is coming out of the speaker any more, so the next load is a// real move rather than a head start on what is coming.if (type == "stopped" || type == "end_of_track" || type == "unavailable") {@@ -1676,6 +1705,9 @@ class LibrespotPlayer(*/const val SKIP_SETTLE_MS = 220L+ /** Set while Spotify is refusing this account every song; see onKeyRefused. */+ const val ACCOUNT_REFUSED = "account_refused"+/*** How long a skip is given to land before its events count again.*diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xmlindex 4c673ad..5271e80 100644--- a/app/src/main/res/values-de/strings.xml+++ b/app/src/main/res/values-de/strings.xml@@ -353,6 +353,7 @@<string name="remove_download">Download entfernen</string><string name="cancel_download">Download abbrechen</string><string name="playback_refused">Spotify lässt gerade keine Songs abspielen. Versuch es in ein paar Minuten noch einmal. Wenn es weiter passiert, melde dich ab und wieder an.</string>+ <string name="playback_refused_account">Spotify lässt dieses Konto in Apps wie Square keine Songs abspielen. Das liegt nicht an der App; mit einem anderen Premium-Konto kann es funktionieren.</string><string name="downloaded">Heruntergeladen</string><string name="downloading">Wird heruntergeladen</string><string name="downloads">Downloads</string>diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xmlindex dc1847c..4e86b7e 100644--- a/app/src/main/res/values-es/strings.xml+++ b/app/src/main/res/values-es/strings.xml@@ -353,6 +353,7 @@<string name="remove_download">Quitar descarga</string><string name="cancel_download">Cancelar descarga</string><string name="playback_refused">Spotify no permite reproducir canciones en este momento. Vuelve a intentarlo en unos minutos. Si sigue pasando, cierra sesión y vuelve a entrar.</string>+ <string name="playback_refused_account">Spotify no permite que esta cuenta reproduzca canciones en apps como Square. No depende de la app; con otra cuenta Premium puede funcionar.</string><string name="downloaded">Descargado</string><string name="downloading">Descargando</string><string name="downloads">Descargas</string>diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xmlindex 08925b9..f79bce8 100644--- a/app/src/main/res/values-fr/strings.xml+++ b/app/src/main/res/values-fr/strings.xml@@ -353,6 +353,7 @@<string name="remove_download">Retirer le téléchargement</string><string name="cancel_download">Annuler le téléchargement</string><string name="playback_refused">Spotify ne permet pas de lire des titres pour le moment. Réessaie dans quelques minutes. Si ça continue, déconnecte-toi puis reconnecte-toi.</string>+ <string name="playback_refused_account">Spotify ne permet pas à ce compte de lire des titres dans des applis comme Square. Cela ne dépend pas de l\'appli ; un autre compte Premium peut fonctionner.</string><string name="downloaded">Téléchargé</string><string name="downloading">Téléchargement</string><string name="downloads">Téléchargements</string>diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xmlindex 566f4c9..6a4354b 100644--- a/app/src/main/res/values-hi/strings.xml+++ b/app/src/main/res/values-hi/strings.xml@@ -368,6 +368,7 @@<string name="remove_download">डाउनलोड हटाएँ</string><string name="cancel_download">डाउनलोड रद्द करें</string><string name="playback_refused">Spotify अभी गाने चलाने नहीं दे रहा है। कुछ मिनट बाद फिर कोशिश करें। अगर ऐसा होता रहे, तो साइन आउट करके फिर से साइन इन करें।</string>+ <string name="playback_refused_account">Spotify इस खाते को Square जैसे ऐप में गाने चलाने नहीं देता। यह ऐप की वजह से नहीं है; किसी दूसरे Premium खाते से चल सकता है।</string><string name="downloaded">डाउनलोड किया</string><string name="downloading">डाउनलोड हो रहा है</string><string name="downloads">डाउनलोड</string>diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xmlindex cd5aa79..c329cab 100644--- a/app/src/main/res/values-it/strings.xml+++ b/app/src/main/res/values-it/strings.xml@@ -354,6 +354,7 @@<string name="remove_download">Rimuovi download</string><string name="cancel_download">Annulla download</string><string name="playback_refused">Spotify al momento non permette di riprodurre i brani. Riprova tra qualche minuto. Se continua, esci e accedi di nuovo.</string>+ <string name="playback_refused_account">Spotify non permette a questo account di riprodurre brani in app come Square. Non dipende dall\'app: con un altro account Premium potrebbe funzionare.</string><string name="downloaded">Scaricato</string><string name="downloading">Download in corso</string><string name="downloads">Download</string>diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xmlindex 8d79e95..942ea81 100644--- a/app/src/main/res/values-pt/strings.xml+++ b/app/src/main/res/values-pt/strings.xml@@ -353,6 +353,7 @@<string name="remove_download">Remover download</string><string name="cancel_download">Cancelar download</string><string name="playback_refused">O Spotify não está deixando tocar músicas agora. Tente de novo em alguns minutos. Se continuar, saia e entre de novo na conta.</string>+ <string name="playback_refused_account">O Spotify não deixa esta conta tocar músicas em apps como o Square. Isso não depende do app; com outra conta Premium pode funcionar.</string><string name="downloaded">Baixado</string><string name="downloading">Baixando</string><string name="downloads">Downloads</string>diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xmlindex 6250a59..083f662 100644--- a/app/src/main/res/values-ru/strings.xml+++ b/app/src/main/res/values-ru/strings.xml@@ -370,6 +370,7 @@<string name="remove_download">Удалить загрузку</string><string name="cancel_download">Отменить загрузку</string><string name="playback_refused">Сейчас Spotify не даёт воспроизводить треки. Попробуйте ещё раз через несколько минут. Если не поможет, выйдите из аккаунта и войдите снова.</string>+ <string name="playback_refused_account">Spotify не разрешает этому аккаунту воспроизводить треки в приложениях вроде Square. Приложение тут ни при чём; с другим аккаунтом Premium может работать.</string><string name="downloaded">Скачано</string><string name="downloading">Загрузка</string><string name="downloads">Загрузки</string>diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xmlindex 143367e..270fcfa 100644--- a/app/src/main/res/values-tr/strings.xml+++ b/app/src/main/res/values-tr/strings.xml@@ -368,6 +368,7 @@<string name="remove_download">İndirmeyi kaldır</string><string name="cancel_download">İndirmeyi iptal et</string><string name="playback_refused">Spotify şu anda şarkı çalmaya izin vermiyor. Birkaç dakika sonra tekrar dene. Devam ederse çıkış yapıp yeniden giriş yap.</string>+ <string name="playback_refused_account">Spotify bu hesabın Square gibi uygulamalarda şarkı çalmasına izin vermiyor. Bu uygulamadan kaynaklanmıyor; başka bir Premium hesapla çalışabilir.</string><string name="downloaded">İndirildi</string><string name="downloading">İndiriliyor</string><string name="downloads">İndirilenler</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 8889c12..3eec816 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -374,6 +374,7 @@<string name="remove_download">Remove download</string><string name="cancel_download">Cancel download</string><string name="playback_refused">Spotify isn\'t letting songs play right now. Try again in a few minutes. If it keeps happening, sign out and sign in again.</string>+ <string name="playback_refused_account">Spotify doesn\'t let this account play songs in apps like Square. It isn\'t something the app can fix; another Premium account may work.</string><string name="downloaded">Downloaded</string><string name="downloading">Downloading</string><string name="downloads">Downloads</string>diff --git a/native/src/engine.rs b/native/src/engine.rsindex 6dec550..2d9b843 100644--- a/native/src/engine.rs+++ b/native/src/engine.rs@@ -500,9 +500,7 @@ pub fn start(let (events_tx, events_rx) = std::sync::mpsc::channel();// Spotify refusing the keys a song needs, told to the app so it can say so// rather than sit on a song that never starts. See the patch in audio_key.- librespot_core::audio_key::on_playback_refusal(|refused| {- emit_app("key_refused", "", refused as i64)- });+ librespot_core::audio_key::on_playback_refusal(|what| emit_app("key_refused", "", what));spawn_event_pump(events_rx,listener,diff --git a/native/vendor/README.md b/native/vendor/README.mdindex ad3bbd2..7a75513 100644--- a/native/vendor/README.md+++ b/native/vendor/README.md@@ -113,7 +113,11 @@ A refusal is also reported, through `on_playback_refusal`, so the app can saywhy a song is not starting instead of leaving it at the start with no time onit. Only refusals that land within a minute of the player asking for a key arereported, once for a run of them, and the next key that comes back is reported-as the end of it. Downloads refused while nothing is playing say nothing.+as the end of it. Downloads refused while nothing is playing say nothing. When+no key at all has come back since the app started and the refusals have gone on+for two minutes, the refusal is reported as the account's instead: Spotify+refuses every key to some accounts (librespot#1649), and for those waiting a few+minutes is the wrong advice.And a reply of the wrong size is refused rather than trusted. Upstream copiesthe key with `copy_from_slice` and reads the error code by index, both of whichdiff --git a/native/vendor/librespot-core/src/audio_key.rs b/native/vendor/librespot-core/src/audio_key.rsindex f8c21e6..bc7fc8c 100644--- a/native/vendor/librespot-core/src/audio_key.rs+++ b/native/vendor/librespot-core/src/audio_key.rs@@ -106,37 +106,83 @@ pub fn since_playback_request() -> Option<Duration> {.map(|at| Instant::now().saturating_duration_since(at))}-/// LOCAL PATCH: told when a key playback asked for is refused, with `true`,-/// and with `false` when a key comes back after that.+/// LOCAL PATCH: told when a key playback asked for is refused, and when one+/// comes back after that.////// So the app can say why nothing is starting. Without it a refused song sits/// at the start with no time on it and nothing else happens, which to the/// listener is the app broken rather than Spotify saying no. Downloads refused/// on their own, with playback quiet, are not reported: nobody is waiting on a/// song then, and the download queue shows its own wait.-static ON_PLAYBACK_REFUSAL: OnceLock<fn(bool)> = OnceLock::new();+///+/// The hook is given a [Refusal] as a number: 0 over, 1 refused, 2 refused to+/// the account.+static ON_PLAYBACK_REFUSAL: OnceLock<fn(i64)> = OnceLock::new();static PLAYBACK_REFUSED: AtomicBool = AtomicBool::new(false);+static ACCOUNT_REPORTED: AtomicBool = AtomicBool::new(false);+static EVER_GRANTED: AtomicBool = AtomicBool::new(false);+static FIRST_REFUSED: Mutex<Option<Instant>> = Mutex::new(None);++/// What a refusal is reported as.+///+/// Spotify refuses these keys for two reasons that look the same on the wire.+/// A burst of requests is refused for a minute or so, and waiting fixes it.+/// Some accounts, mostly newer ones, are refused every key, all the time,+/// whatever device they are on (librespot#1649), and waiting fixes nothing:+/// telling them to try again in a few minutes sends them round in circles. An+/// account that has not had a single key since the app started, over a few+/// minutes of asking, is taken to be the second.+#[repr(i64)]+enum Refusal {+ Over = 0,+ Refused = 1,+ Account = 2,+}/// How recent a playback request has to be for a refusal to be its.const PLAYBACK_WAITING: Duration = Duration::from_secs(60);+/// How long refusals with no key in between make it the account's.+const ACCOUNT_AFTER: Duration = Duration::from_secs(120);+/// Sets where refusals are reported; see [ON_PLAYBACK_REFUSAL]. Only the first/// call counts.-pub fn on_playback_refusal(hook: fn(bool)) {+pub fn on_playback_refusal(hook: fn(i64)) {let _ = ON_PLAYBACK_REFUSAL.set(hook);}fn report_refusal(refused: bool) {- if refused {- let waiting = since_playback_request().is_some_and(|ago| ago < PLAYBACK_WAITING);- if !waiting || PLAYBACK_REFUSED.swap(true, Ordering::SeqCst) {- return;+ let report = |what: Refusal| {+ if let Some(hook) = ON_PLAYBACK_REFUSAL.get() {+ hook(what as i64);+ }+ };+ if !refused {+ EVER_GRANTED.store(true, Ordering::SeqCst);+ ACCOUNT_REPORTED.store(false, Ordering::SeqCst);+ if let Ok(mut first) = FIRST_REFUSED.lock() {+ *first = None;+ }+ if PLAYBACK_REFUSED.swap(false, Ordering::SeqCst) {+ report(Refusal::Over);}- } else if !PLAYBACK_REFUSED.swap(false, Ordering::SeqCst) {return;}- if let Some(hook) = ON_PLAYBACK_REFUSAL.get() {- hook(refused);+ if !since_playback_request().is_some_and(|ago| ago < PLAYBACK_WAITING) {+ return;+ }+ let refused_for = FIRST_REFUSED+ .lock()+ .map(|mut first| first.get_or_insert_with(Instant::now).elapsed())+ .unwrap_or_default();+ if !EVER_GRANTED.load(Ordering::SeqCst)+ && refused_for >= ACCOUNT_AFTER+ && !ACCOUNT_REPORTED.swap(true, Ordering::SeqCst)+ {+ PLAYBACK_REFUSED.store(true, Ordering::SeqCst);+ report(Refusal::Account);+ } else if !PLAYBACK_REFUSED.swap(true, Ordering::SeqCst) {+ report(Refusal::Refused);}}