Skip to content

Native Android client for Spotify, built with Jetpack Compose

SpotiFLAC verification the way SpotiFLAC Mobile does it; licence notices

kota-zo343cffd1d831
diff --git a/README.md b/README.md
index 3aa12099..59a8cb7e 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,9 @@ Details for developers: [`base/api-spotify/README.md`](base/api-spotify/README.m
- [SpotiFLAC](https://github.com/spotbye/SpotiFLAC) (MIT) — the lossless resolving idea, its community backend protocol and the gated-session flow.
- [Spotui](https://github.com/Spotui/Spotui) (GPL-3.0) — the Kotlin port of the resolver, the signed-session verification screen and the DASH-to-FLAC remux that Myspoti builds on.
+- [SpotiFLAC Mobile](https://github.com/zarzet/SpotiFLAC-Mobile) (MIT) and its [extensions](https://github.com/zarzet/SpotiFLAC-Extension) (Apache-2.0) — the signed download sessions and the Tidal / Qobuz download requests.
+
+Full notices: [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).
## Disclaimer
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
new file mode 100644
index 00000000..6849a837
--- /dev/null
+++ b/THIRD_PARTY_NOTICES.md
@@ -0,0 +1,44 @@
+# Third-party notices
+
+Myspoti is free software under the GNU General Public License v3.0 (see `LICENSE`).
+It builds on the projects below; their licences are compatible with the GPL-3.0.
+
+## Spotui — GPL-3.0
+https://github.com/Spotui/Spotui
+
+The Kotlin lossless resolver, the DASH-to-FLAC remux and the first verification
+screen (`base/app/src/main/java/com/music/spotui/lossless/`, `SpotiflacScreen.kt`)
+are ported from Spotui and stay under the GPL-3.0. Each file says so in its header.
+
+## SpotiFLAC — MIT
+https://github.com/spotbye/SpotiFLAC
+
+The lossless resolving approach and its community backend protocol.
+
+> MIT License — Copyright (c) 2026 afkarxyz.
+> Permission is hereby granted, free of charge, to any person obtaining a copy of this
+> software and associated documentation files (the "Software"), to deal in the Software
+> without restriction, including without limitation the rights to use, copy, modify,
+> merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+> permit persons to whom the Software is furnished to do so, subject to the following
+> conditions: The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS",
+> WITHOUT WARRANTY OF ANY KIND.
+
+## SpotiFLAC Mobile — MIT
+https://github.com/zarzet/SpotiFLAC-Mobile
+
+`ZarzSession.kt` implements the signed-session protocol of its extension runtime
+(bootstrap, challenge, grant exchange, ZARZ-HMAC-V1 signatures, download tickets),
+written in Kotlin from that runtime.
+
+> MIT License — Copyright (c) 2026 zarzet. Same permission notice as above.
+
+## SpotiFLAC Extensions — Apache-2.0
+https://github.com/zarzet/SpotiFLAC-Extension
+
+The request shapes of the `tidal-web` and `qobuz-web` extensions (download endpoints,
+quality names, the Tidal web token and Qobuz app id they use) are followed in
+`LosslessSource.kt`. No extension code is included.
+
+> Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
diff --git a/base/app/build.gradle.kts b/base/app/build.gradle.kts
index 741ef6c0..b5fb72cc 100644
--- a/base/app/build.gradle.kts
+++ b/base/app/build.gradle.kts
@@ -96,6 +96,8 @@ dependencies {
implementation(project(":host-android"))
// Jam: scan the invite QR code (Google code scanner, no camera permission).
implementation("com.google.android.gms:play-services-code-scanner:16.1.0")
+ // The SpotiFLAC verification opens in a browser tab, as SpotiFLAC Mobile does.
+ implementation("androidx.browser:browser:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test:runner:1.6.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
diff --git a/base/app/src/main/AndroidManifest.xml b/base/app/src/main/AndroidManifest.xml
index 4e72005d..cc8dcaa5 100644
--- a/base/app/src/main/AndroidManifest.xml
+++ b/base/app/src/main/AndroidManifest.xml
@@ -64,6 +64,13 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ <!-- The SpotiFLAC verification page hands its grant back here, as to SpotiFLAC Mobile. -->
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="spotiflac" android:host="session-grant" />
+ </intent-filter>
<intent-filter>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
diff --git a/base/app/src/main/java/app/myspoti/MainActivity.kt b/base/app/src/main/java/app/myspoti/MainActivity.kt
index eb9b9d61..ddd6bcc9 100644
--- a/base/app/src/main/java/app/myspoti/MainActivity.kt
+++ b/base/app/src/main/java/app/myspoti/MainActivity.kt
@@ -172,6 +172,11 @@ class MainActivity : AppCompatActivity() {
/** Spotify links (open.spotify.com/...) play their item; voice search plays its best match. */
private fun handle(intent: Intent?) {
intent ?: return
+ // The SpotiFLAC verification's return (spotiflac://session-grant?grant=…&state=…).
+ if (intent.data?.scheme == "spotiflac" && intent.data?.host == "session-grant") {
+ com.music.spotui.lossless.ZarzSession.grants.tryEmit(intent.data.toString())
+ return
+ }
when (intent.action) {
Intent.ACTION_VIEW -> {
val uri = spotifyUri(intent.data?.toString() ?: return) ?: return
diff --git a/base/app/src/main/java/com/music/spotui/lossless/ZarzSession.kt b/base/app/src/main/java/com/music/spotui/lossless/ZarzSession.kt
index e0df4b75..b379be7d 100644
--- a/base/app/src/main/java/com/music/spotui/lossless/ZarzSession.kt
+++ b/base/app/src/main/java/com/music/spotui/lossless/ZarzSession.kt
@@ -5,6 +5,8 @@ package com.music.spotui.lossless
* tidal-web…), written from its protocol: the extension manifest's `signedSession`
* block and the app's signed_session runtime (bootstrap → hosted challenge →
* grant → exchange; ZARZ-HMAC-V1 signatures; download tickets).
+ * SpotiFLAC Mobile is MIT (Copyright (c) 2026 zarzet), its extensions Apache-2.0:
+ * see THIRD_PARTY_NOTICES.md.
*/
import android.content.Context
@@ -35,6 +37,10 @@ internal object ZarzSession {
private const val SCHEME = "ZARZ-HMAC-V1"
private const val PREFIX = "X-Zarz-"
private const val WINDOW_SECONDS = 300L
+ private const val USER_AGENT = "SpotiFLAC-Mobile/5.1.1"
+
+ /** The grant redirects the verification page sends back to the app (spotiflac://session-grant…). */
+ val grants = kotlinx.coroutines.flow.MutableSharedFlow<String>(extraBufferCapacity = 4)
/** A challenge page to open (the user solves it), or null when a session came back directly. */
class Bootstrap(val challengeUrl: String?, val state: String)
@@ -47,7 +53,9 @@ internal object ZarzSession {
/** GET /bootstrap: a session right away, or the challenge to solve. */
fun bootstrap(context: Context, ext: Ext, installId: String): Bootstrap {
- val o = JSONObject(request("GET", "$BASE/bootstrap?app_version=${enc(ext.appVersion)}&install_id=${enc(installId)}", null, emptyMap()).second)
+ val (code, text) = request("GET", "$BASE/bootstrap?app_version=${enc(ext.appVersion)}&install_id=${enc(installId)}", null, emptyMap())
+ if (code !in 200..299) throw java.io.IOException("bootstrap HTTP $code: ${text.take(120)}")
+ val o = JSONObject(text)
if (store(context, ext, installId, o)) return Bootstrap(null, "")
val state = randomHex(16)
val given = o.optString("auth_url").ifBlank { o.optString("challenge_url") }
@@ -146,7 +154,8 @@ internal object ZarzSession {
connectTimeout = 15_000
readTimeout = 30_000
setRequestProperty("Accept", "application/json")
- setRequestProperty("User-Agent", "SpotiFLAC-Mobile")
+ // The app's own form, "SpotiFLAC-Mobile/<version>": the bare name is refused (403).
+ setRequestProperty("User-Agent", USER_AGENT)
headers.forEach { (k, v) -> setRequestProperty(k, v) }
if (body != null) doOutput = true
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/SpotiflacScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/SpotiflacScreen.kt
index 082eeeb0..0aed425f 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/SpotiflacScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/SpotiflacScreen.kt
@@ -5,12 +5,7 @@ package com.music.spotui.ui.screens
* and adapted to Myspoti (own theme, strings, navigation).
*/
-import android.annotation.SuppressLint
import android.content.Context
-import android.webkit.CookieManager
-import android.webkit.WebResourceRequest
-import android.webkit.WebView
-import android.webkit.WebViewClient
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -43,7 +38,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
-import androidx.compose.ui.viewinterop.AndroidView
import app.myspoti.engine.R
import com.music.spotui.ui.theme.AppBackground
import kotlinx.coroutines.Dispatchers
@@ -58,14 +52,12 @@ import kotlinx.coroutines.withContext
*
* The app only loads the page and catches the redirect. The session is what gives
* the lossless (FLAC) downloads their most reliable source. With a session the
- * screen shows the status; without it the WebView verification runs.
+ * screen shows the status; without it the verification opens in a browser tab.
*/
-@SuppressLint("SetJavaScriptEnabled")
@Composable
fun SpotiflacScreen(onClose: () -> Unit) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
- var webView by remember { mutableStateOf<WebView?>(null) }
var attempt by remember { mutableStateOf(0) }
// One session per download server (Tidal, then Qobuz); verified once none is missing.
fun missing() = com.music.spotui.lossless.ZarzSession.Ext.entries
@@ -121,51 +113,39 @@ fun SpotiflacScreen(onClose: () -> Unit) {
if (ext == null) { verified = true; done = true }
return@LaunchedEffect
}
- message = ""
+ message = res(R.string.spotiflac_verify_in_browser)
state = boot.state
- webView?.loadUrl(boot.challengeUrl)
+ // A browser tab, as SpotiFLAC Mobile opens it: Cloudflare's check runs in a real browser,
+ // and the page hands the grant back through spotiflac://session-grant (ZarzSession.grants).
+ runCatching {
+ androidx.browser.customtabs.CustomTabsIntent.Builder().setShowTitle(true).build()
+ .launchUrl(context, android.net.Uri.parse(boot.challengeUrl))
+ }.onFailure {
+ context.startActivity(android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(boot.challengeUrl))
+ .addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK))
+ }
// Never leave the user on a page that silently stalled.
delay(180_000)
if (!done && !verified) message = res(R.string.spotiflac_verify_timeout)
}
+ // The grant coming back from the browser tab.
+ LaunchedEffect(Unit) {
+ com.music.spotui.lossless.ZarzSession.grants.collect { link ->
+ val uri = android.net.Uri.parse(link)
+ val grant = uri.getQueryParameter("grant").orEmpty()
+ if (state.isBlank() || uri.getQueryParameter("state") != state || grant.isBlank()) {
+ message = res(R.string.spotiflac_verify_rejected)
+ } else finish(grant)
+ }
+ }
+
if (verified) {
SpotiflacStatusScreen(leave)
return
}
Box(modifier = Modifier.fillMaxSize().background(Color.Black)) {
- AndroidView(
- modifier = Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()
- .padding(top = 40.dp, bottom = 56.dp),
- factory = { ctx ->
- CookieManager.getInstance().setAcceptCookie(true)
- WebView(ctx).apply {
- webView = this
- layoutParams = android.view.ViewGroup.LayoutParams(
- android.view.ViewGroup.LayoutParams.MATCH_PARENT,
- android.view.ViewGroup.LayoutParams.MATCH_PARENT,
- )
- CookieManager.getInstance().setAcceptThirdPartyCookies(this, true)
- settings.javaScriptEnabled = true
- settings.domStorageEnabled = true
- webViewClient = object : WebViewClient() {
- override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
- val uri = request.url
- if (!uri.toString().startsWith(CALLBACK)) return false
- val grant = uri.getQueryParameter("grant").orEmpty()
- if (uri.getQueryParameter("state") != state || grant.isBlank()) {
- message = res(R.string.spotiflac_verify_rejected)
- } else {
- finish(grant)
- }
- return true
- }
- }
- }
- },
- )
-
if (message.isNotEmpty()) {
Text(
message,
diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xml
index 43c7c0da..5742ee71 100644
--- a/base/app/src/main/res/values-fr/myspoti_strings.xml
+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml
@@ -248,4 +248,5 @@
<string name="quality_sheet_title">Qualité du son</string>
<string name="quality_now">En cours : %1$s</string>
<string name="quality_now_unknown">Pas encore connue : lancez un titre</string>
+ <string name="spotiflac_verify_in_browser">Résolvez la vérification dans l\'onglet du navigateur qui s\'est ouvert, puis revenez ici.</string>
</resources>
diff --git a/base/app/src/main/res/values-it/myspoti_strings.xml b/base/app/src/main/res/values-it/myspoti_strings.xml
index 1a1af856..5aef3d18 100644
--- a/base/app/src/main/res/values-it/myspoti_strings.xml
+++ b/base/app/src/main/res/values-it/myspoti_strings.xml
@@ -248,4 +248,5 @@
<string name="quality_sheet_title">Qualità audio</string>
<string name="quality_now">In riproduzione: %1$s</string>
<string name="quality_now_unknown">Non ancora nota: avvia un brano</string>
+ <string name="spotiflac_verify_in_browser">Completa la verifica nella scheda del browser che si è aperta, poi torna qui.</string>
</resources>
diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xml
index 9c472c7e..6b7a5a76 100644
--- a/base/app/src/main/res/values/myspoti_strings.xml
+++ b/base/app/src/main/res/values/myspoti_strings.xml
@@ -248,4 +248,5 @@
<string name="quality_sheet_title">Sound quality</string>
<string name="quality_now">Playing now: %1$s</string>
<string name="quality_now_unknown">Not known yet: start a song</string>
+ <string name="spotiflac_verify_in_browser">Solve the check in the browser tab that opened, then come back here.</string>
</resources>