Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
2.0.1: a play Spotify refuses once relayed is sent again from the page itself, and kept that way while the music plays
kota-zo496dde4f2076
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d63341d6..186ae304 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,10 @@Each release on GitHub shows its section below. The app shows it too when it offers the update. Every detail: [docs/CHANGELOG-full.md](docs/CHANGELOG-full.md).+## 2.0.1++- 🎵 **"Spotify refused to play this"**: on the accounts where Spotify refused every play (free accounts on some phones and in some countries), a refused command is now sent again the way other web-player apps send it, and playback keeps going that way when it works. If it still refuses, please send a new diagnostic report: it now says which way was tried.+## 2.0.0Myspoti 2.0 is a new app, rebuilt from the ground up: Spotify with no ads and with lossless downloads, on a free account.diff --git a/base/app/build.gradle.kts b/base/app/build.gradle.ktsindex 77e06d7a..03437408 100644--- a/base/app/build.gradle.kts+++ b/base/app/build.gradle.kts@@ -22,7 +22,7 @@ android {// signed with the first key, as "Myspoti Beta"; releases are "app.myspoti.stable",// signed with their own key, as "Myspoti".// Local builds (no version given) are on the beta side, like the phone test builds.- val version = (findProperty("appVersionName") as String?) ?: "2.0.0"+ val version = (findProperty("appVersionName") as String?) ?: "2.0.1"val beta = findProperty("appVersionName") == null || version.contains("-")defaultConfig {applicationId = if (beta) "app.myspoti" else "app.myspoti.stable"diff --git a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.ktindex 94050941..9ececa51 100644--- a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt+++ b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt@@ -120,6 +120,11 @@ internal class ControlRelay(private val view: WebView, private val fingerprint:Logbook.log("page identity: ${identity.toString().take(320)}")return}+ if (m.optString("type") == "direct") {+ if (m.has("kept")) Logbook.log("commands from the page: ${if (m.optBoolean("kept")) "kept, the music plays" else "dropped, nothing played in 10 s"}")+ else Logbook.log("refused command sent again from the page -> ${m.optInt("status")}")+ return+ }val id = m.optInt("id", -1).takeIf { it >= 0 } ?: returnval body = if (m.isNull("body")) null else m.optString("body")send(id, m.optString("url"), m.optString("method", "GET"), m.optJSONObject("headers") ?: JSONObject(), body)@@ -322,29 +327,62 @@ internal class ControlRelay(private val view: WebView, private val fingerprint:const notRelayed = /^https:\/\/(accounts|challenge|www)\.spotify\.com\//;const pending = new Map();let seq = 0;+ const original = window.fetch;+ const command = /player\/command|connect\/transfer/;+ // A refused play or transfer (free accounts in some countries): the app tries another way.+ const tell = (status, url) => {+ if ((status === 402 || status === 403) && command.test(url) && window.MyspotiHost) {+ try { window.MyspotiHost.postMessage(JSON.stringify({ type: 'refused', status, path: url.split('?')[0].replace(/^.*\/v1\//, '').replace(/\/from\/.*$/, '') })); } catch (e) { /* host gone */ }+ }+ };+ const note = (value) => { try { window.MyspotiNet.postMessage(JSON.stringify(Object.assign({ type: 'direct' }, value))); } catch (e) { /* host gone */ } };+ // Some free accounts get every relayed command refused (402 COMMAND_FAILED) while the+ // same account plays in apps that send them from the page itself (Spotui): a refused+ // command is sent once more that way, and the page's commands keep going that way if+ // it took. Kept only if something plays within 10 s: a command sent from the page can+ // be acknowledged and never delivered (X-Requested-With, see above).+ const plays = () => [...media].some(m => !m.paused && !m.ended && m.readyState > 2);+ const trust = () => {+ if (window.__mspDirect) return;+ window.__mspDirect = true;+ setTimeout(() => {+ const kept = plays();+ if (!kept) window.__mspDirect = false;+ note({ kept });+ }, 10000);+ };+ const direct = (url, init) => original.call(window, url, init).then(r => { tell(r.status, url); return r; });window.__mspNetDone = (id, status, headers, body) => {const p = pending.get(id);if (!p) return;pending.delete(id);if (!status) return p.reject(new TypeError('Failed to fetch'));- // A refused play or transfer (free accounts in some countries): the app tries another way.- if ((status === 402 || status === 403) && /player\/command|connect\/transfer/.test(p.url) && window.MyspotiHost) {- try { window.MyspotiHost.postMessage(JSON.stringify({ type: 'refused', status, path: p.url.split('?')[0].replace(/^.*\/v1\//, '').replace(/\/from\/.*$/, '') })); } catch (e) { /* host gone */ }+ const relayedAnswer = () => {+ const noBody = status === 204 || status === 205 || status === 304;+ return new Response(noBody ? null : body, { status, headers: JSON.parse(headers) });+ };+ if (status === 402 && command.test(p.url) && !window.__mspDirect) {+ original.call(window, p.url, p.init).then(r => {+ note({ status: r.status });+ if (r.ok) trust(); else tell(r.status, p.url);+ p.resolve(r);+ }, () => { tell(status, p.url); p.resolve(relayedAnswer()); });+ return;}- const noBody = status === 204 || status === 205 || status === 304;- p.resolve(new Response(noBody ? null : body, { status, headers: JSON.parse(headers) }));+ tell(status, p.url);+ p.resolve(relayedAnswer());};- const original = window.fetch;window.fetch = function (input, init) {const url = typeof input === 'string' ? input : (input instanceof URL ? input.href : null);const body = init && init.body;if (!url || !relayed.test(url) || notRelayed.test(url) || (body != null && typeof body !== 'string')) return original.apply(this, arguments);+ if (window.__mspDirect && command.test(url)) return direct(url, init);const headers = {};new Headers((init && init.headers) || {}).forEach((v, k) => { headers[k] = v; });const method = ((init && init.method) || 'GET').toUpperCase();return new Promise((resolve, reject) => {const id = ++seq;- pending.set(id, { resolve, reject, url });+ pending.set(id, { resolve, reject, url, init });window.MyspotiNet.postMessage(JSON.stringify({ id, url, method, headers, body: body == null ? null : body }));});};diff --git a/docs/CHANGELOG-full.md b/docs/CHANGELOG-full.mdindex 52cf9b03..d8f61970 100644--- a/docs/CHANGELOG-full.md+++ b/docs/CHANGELOG-full.md@@ -2,6 +2,10 @@Every change, release by release. The short version is in [CHANGELOG.md](../CHANGELOG.md), which the app and the GitHub releases show.+## 2.0.1++- **402 `COMMAND_FAILED` on every play** (free accounts: Xiaomi Redmi 13 / Indonesia, Samsung A32 / Belarus, issue #55): the same accounts play in Spotui, which sends the Connect commands from the page itself, while Myspoti relays them through OkHttp. A relayed play or transfer answered 402 is now sent once more with the page's own `fetch`; if that one is accepted, the page's commands keep going that way, and only while something plays (checked 10 s later: a command sent from the page can be acknowledged and never delivered). Both refused: the refusal steps run as before. The diagnostic logs the retry's status and whether the page's way was kept.+## Unreleased- **Skip intent**: next / previous / "skip to" made while the page cannot take them (an ad is current: "The operation is not allowed"; a reload: "local player is disabled", "not ready") move an intent instead of reaching the page; the screen shows that song, waiting. Whatever recovers playback (the ad recovery, any reload, the end of the ad) plays the intent, not the song after the last state seen; skips made meanwhile move it and the newest wins. A plain next is remembered too: if the page goes into an ad break instead, that song is asked for again after it. "Previous" refused during an ad is held, never turned into a seek (which restarted the ad).