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
Read Liked Songs from Spotify's own gateway
Lelonioa6600c34e9e1
diff --git a/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt b/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.ktindex 2339555..50837b3 100644--- a/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt+++ b/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt@@ -10,6 +10,7 @@ import dev.lelonio.square.data.PlaylistDetailsDtoimport dev.lelonio.square.data.SearchResultsimport dev.lelonio.square.data.toCatalogTrackimport dev.lelonio.square.data.toResults+import dev.lelonio.square.data.SavedTracksimport dev.lelonio.square.nativecore.NativeBridgeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.withContext@@ -135,12 +136,13 @@ class SpotifyBackend(private val container: SquareApplication) : MusicBackend {container.webApi.isReady && uri.startsWith("spotify:playlist:") ->webApiPlaylistTracks(uri.substringAfterLast(':'))- // Liked Songs is not a context the access point will resolve: asked for- // it answers 503, so this is the one list that has to come from the Web- // API and therefore needs the user's own application.- uri.endsWith(":collection") -> {+ // Liked Songs is not a context the access point will resolve: asked+ // for it answers 503. Spotify's own gateway answers it for anyone+ // logged in, and the Web API — which needs the listener's registered+ // application — is what is left when a query hash has been retired.+ uri.endsWith(":collection") -> gatewaySavedTracks() ?: run {check(container.webApi.isReady) {- "i brani che ti piacciono richiedono la tua applicazione Spotify"+ container.getString(dev.lelonio.square.R.string.liked_songs_failed)}savedTracks()}@@ -148,6 +150,42 @@ class SpotifyBackend(private val container: SquareApplication) : MusicBackend {else -> Catalog.tracks(Catalog.contextTrackUris(uri))}+ /**+ * Everything the account has saved, from the gateway; see SavedTracks.+ *+ * Null when the gateway will not answer, which is the caller's cue to ask+ * the Web API the same question.+ */+ private suspend fun gatewaySavedTracks(): List<CatalogTrack>? {+ val keys = container.pathfinderKeys+ keys.refresh()+ val language = java.util.Locale.getDefault().language++ val loaded = mutableListOf<CatalogTrack>()+ var offset = 0+ while (true) {+ val page = runCatching {+ val raw = withContext(Dispatchers.IO) {+ NativeBridge.likedSongs(+ """{"offset":$offset,"limit":$GATEWAY_LIBRARY_PAGE}""",+ language,+ keys.likedSongs,+ keys.appVersion,+ )+ }+ SavedTracks.parse(raw)+ // A page that will not come back gives up the whole read, part+ // way through as much as at the start: half a list handed to+ // the queue is a queue that ends where the page did.+ }.getOrNull() ?: return null++ loaded += page.tracks+ val next = page.nextOffset+ if (next == null || next <= offset || loaded.size >= page.total) return loaded+ offset = next+ }+ }+/** Everything the account has saved, newest first, a page at a time. */private suspend fun savedTracks(): List<CatalogTrack> {val loaded = mutableListOf<CatalogTrack>()@@ -256,6 +294,9 @@ class SpotifyBackend(private val container: SquareApplication) : MusicBackend {*/const val WEB_API_LIBRARY_PAGE = 50+ /** What the gateway takes at a time; see MainViewModel. */+ const val GATEWAY_LIBRARY_PAGE = 200+/*** The purple heart Spotify's own clients draw for Liked Songs.*diff --git a/app/src/main/java/dev/lelonio/square/data/PathfinderKeys.kt b/app/src/main/java/dev/lelonio/square/data/PathfinderKeys.ktindex 17697ef..1e5e4b5 100644--- a/app/src/main/java/dev/lelonio/square/data/PathfinderKeys.kt+++ b/app/src/main/java/dev/lelonio/square/data/PathfinderKeys.kt@@ -21,8 +21,9 @@ import org.json.JSONObject* The same goes for the client version the gateway is told about, which ages* for the same reason and is fixed the same way.*- * Nothing here is a secret and nothing here is trusted: the file names queries,- * and a wrong value costs the home page and nothing else.+ * Nothing here is a secret and nothing here is trusted: the file names+ * queries, and a wrong value costs the pages those queries serve — the+ * personalised home, and Liked Songs, which has the Web API to fall back on.*/class PathfinderKeys(context: Context) {@@ -33,6 +34,9 @@ class PathfinderKeys(context: Context) {/** The hash for the `home` query, freshest first. */val home: String get() = prefs.getString(KEY_HOME, null) ?: DEFAULT_HOME+ /** The same for `getLikedSongs`; see SavedTracks. */+ val likedSongs: String get() = prefs.getString(KEY_LIKED, null) ?: DEFAULT_LIKED+/** The web client version the gateway is told about. */val appVersion: String get() = prefs.getString(KEY_VERSION, null) ?: DEFAULT_VERSION@@ -55,6 +59,8 @@ class PathfinderKeys(context: Context) {val edit = prefs.edit().putLong(KEY_CHECKED, System.currentTimeMillis())body.optString("home").takeIf { it.length == HASH_LENGTH }?.let { edit.putString(KEY_HOME, it) }+ body.optString("likedSongs").takeIf { it.length == HASH_LENGTH }+ ?.let { edit.putString(KEY_LIKED, it) }body.optString("appVersion").takeIf { it.isNotEmpty() }?.let { edit.putString(KEY_VERSION, it) }edit.apply()@@ -66,6 +72,7 @@ class PathfinderKeys(context: Context) {const val TAG = "PathfinderKeys"const val FILE_NAME = "square_pathfinder"const val KEY_HOME = "home"+ const val KEY_LIKED = "liked_songs"const val KEY_VERSION = "app_version"const val KEY_CHECKED = "checked_at"@@ -82,6 +89,8 @@ class PathfinderKeys(context: Context) {/** What was true when this version was built; see the note above. */const val DEFAULT_HOME ="76243c78b0e20ecdbe41b794dec8cbe73f75e585b0a7201b8d2e84578412847a"+ const val DEFAULT_LIKED =+ "c2c53c28f71da143c0753c22dc84d98b315cb4275472ea5a597c29338ae20b23"const val DEFAULT_VERSION = "1.2.97.155.g5dd0dcaf-development"}}diff --git a/app/src/main/java/dev/lelonio/square/data/SavedTracks.kt b/app/src/main/java/dev/lelonio/square/data/SavedTracks.ktnew file mode 100644index 0000000..cf0dbea--- /dev/null+++ b/app/src/main/java/dev/lelonio/square/data/SavedTracks.kt@@ -0,0 +1,118 @@+package dev.lelonio.square.data++import org.json.JSONObject++/**+ * The account's saved tracks, read from Spotify's own gateway.+ *+ * Liked Songs is the one list with nowhere ordinary to come from. The access+ * point refuses it as a context, and the Web API will only answer for a+ * listener who has registered an application of their own — and then fifty at+ * a time, against a quota. The gateway the personalised home already comes+ * from answers the same question with the whole track in it, two hundred at a+ * time, for anyone who is logged in.+ *+ * Forgiving in the same way [SpotifyHome] is, and for the same reason: this+ * reads a private interface that changes without notice, so an item nobody+ * recognises is skipped rather than treated as a failure. What it cannot do is+ * pretend to have read a page it did not, hence the null.+ */+object SavedTracks {++ /**+ * @param nextOffset where the next page starts, or null at the end.+ * @param total how many the account has, which is what says whether the+ * list on screen is all of them.+ */+ data class Page(+ val tracks: List<CatalogTrack>,+ val nextOffset: Int?,+ val total: Int,+ )++ /** Null when the answer was not one of these — a retired query hash, a 401. */+ fun parse(json: String): Page? = runCatching {+ val tracks = JSONObject(json)+ .getJSONObject("data")+ .getJSONObject("me")+ .getJSONObject("library")+ .getJSONObject("tracks")++ val items = tracks.getJSONArray("items")+ val read = (0 until items.length()).mapNotNull { index ->+ track(items.optJSONObject(index) ?: return@mapNotNull null)+ }++ Page(+ tracks = read,+ // Null on the last page, and null is how the caller knows it is+ // the last. Present-but-null, at that: the key is always there, so+ // asking whether it exists says nothing.+ nextOffset = tracks.optJSONObject("pagingInfo")+ ?.takeIf { !it.isNull("nextOffset") }+ ?.optInt("nextOffset"),+ total = tracks.optInt("totalCount", read.size),+ )+ }.getOrNull()++ private fun track(item: JSONObject): CatalogTrack? {+ val data = item.optJSONObject("track")?.optJSONObject("data") ?: return null+ val uri = data.optString("uri").takeIf { it.startsWith("spotify:track:") } ?: return null++ // Same rule as every other list: something the engine could only skip+ // has no business being in the queue.+ val playable = data.optJSONObject("playability")?.optBoolean("playable", true) ?: true+ if (!playable) return null++ val artists = data.optJSONObject("artists")?.optJSONArray("items")+ val credited = buildList {+ for (index in 0 until (artists?.length() ?: 0)) {+ val artist = artists?.optJSONObject(index) ?: continue+ val name = artist.optJSONObject("profile")?.optString("name").orEmpty()+ if (name.isEmpty()) continue+ add(CatalogArtist(name, artist.optString("uri").takeIf { it.isNotEmpty() }))+ }+ }++ val album = data.optJSONObject("albumOfTrack")++ return CatalogTrack(+ uri = uri,+ name = data.optString("name"),+ artist = credited.joinToString(", ") { it.name },+ artistUri = credited.firstOrNull()?.uri,+ artists = credited,+ album = album?.optString("name").orEmpty(),+ durationMs = data.optJSONObject("duration")?.optLong("totalMilliseconds") ?: 0L,+ explicit = data.optJSONObject("contentRating")?.optString("label") == "EXPLICIT",+ artworkUrl = cover(album),+ // The gateway does not carry the date a track was saved. The pages+ // arrive newest first, which is what the "recently added" order+ // shows anyway, and sorting by a field that is null throughout+ // leaves that order alone.+ addedAt = null,+ )+ }++ /**+ * The middle cover, or whatever there is.+ *+ * Three sizes come back, in no particular order. A row shows a thumbnail+ * and the sheet behind the player wants something bigger, so this takes the+ * 300px one when it is there rather than the first named.+ */+ private fun cover(album: JSONObject?): String? {+ val sources = album?.optJSONObject("coverArt")?.optJSONArray("sources") ?: return null+ var fallback: String? = null+ for (index in 0 until sources.length()) {+ val source = sources.optJSONObject(index) ?: continue+ val url = source.optString("url").takeIf { it.isNotEmpty() } ?: continue+ if (source.optInt("width") == PREFERRED_COVER) return url+ if (fallback == null) fallback = url+ }+ return fallback+ }++ /** What the rows are drawn at; see [cover]. */+ private const val PREFERRED_COVER = 300+}diff --git a/app/src/main/java/dev/lelonio/square/nativecore/NativeBridge.kt b/app/src/main/java/dev/lelonio/square/nativecore/NativeBridge.ktindex 4a6f36c..1e80933 100644--- a/app/src/main/java/dev/lelonio/square/nativecore/NativeBridge.kt+++ b/app/src/main/java/dev/lelonio/square/nativecore/NativeBridge.kt@@ -273,6 +273,21 @@ object NativeBridge {appVersion: String,): String = nativeHomeFeed(timeZone, language, hash, appVersion)+ /**+ * The account's saved tracks, as raw JSON from Spotify's gateway.+ *+ * The same gateway and the same fragility as [homeFeed]. Here for the one+ * list that has nowhere else to come from: the Web API can only be asked+ * for it by a listener who has registered an application of their own, and+ * the access point refuses it as a context. Blocking.+ */+ fun likedSongs(+ variables: String,+ language: String,+ hash: String,+ appVersion: String,+ ): String = nativeLikedSongs(variables, language, hash, appVersion)+/** This device's own Connect id, which is what says "here" rather than "there". */fun deviceId(): String = runCatching { nativeDeviceId() }.getOrDefault("")@@ -407,6 +422,12 @@ object NativeBridge {hash: String,appVersion: String,): String+ private external fun nativeLikedSongs(+ variables: String,+ language: String,+ hash: String,+ appVersion: String,+ ): Stringprivate external fun nativeDeviceId(): Stringprivate external fun nativeSetQueueOrder(urisJson: String, index: Int)private external fun nativePlayingHere(): Stringdiff --git a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.ktindex 1a48c1f..2158105 100644--- a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt+++ b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt@@ -20,6 +20,7 @@ import dev.lelonio.square.data.HomeShelfimport dev.lelonio.square.data.SpotifyHomeimport dev.lelonio.square.data.CatalogTrackimport dev.lelonio.square.data.ContextCacheStore+import dev.lelonio.square.data.SavedTracksimport dev.lelonio.square.data.SearchItemimport dev.lelonio.square.data.TransferRequestDtoimport dev.lelonio.square.data.SearchResults@@ -1829,8 +1830,10 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {uri: String,showProgress: Boolean,): List<CatalogTrack>? {- if (!container.webApi.isReady) return null+ // Liked Songs first, and without the registered-application check: it+ // comes from the gateway, which asks only that somebody is logged in.if (uri.endsWith(":collection")) return savedTracks(base, showProgress)+ if (!container.webApi.isReady) return nullif (!uri.startsWith("spotify:playlist:")) return nullval id = uri.substringAfterLast(':')@@ -1873,6 +1876,13 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {base: PlaylistState,showProgress: Boolean,): List<CatalogTrack> {+ gatewaySavedTracks(base, showProgress)?.let { return it }++ // The gateway said nothing usable — a retired query hash, most likely.+ // The Web API knows the same list, fifty at a time, for a listener who+ // has registered an application of their own.+ check(container.webApi.isReady) { string(R.string.liked_songs_failed) }+val loaded = mutableListOf<CatalogTrack>()var offset = 0while (true) {@@ -1895,6 +1905,68 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {}}+ /**+ * Liked Songs from Spotify's own gateway, two hundred at a time.+ *+ * The list nobody else will answer for: the access point refuses the+ * collection as a context, and the Web API wants the listener to have+ * registered an application. This is the same gateway the personalised+ * home comes from, so it costs nothing that the home page does not already+ * cost, and it hands back whole tracks rather than URIs to look up one by+ * one.+ *+ * Null rather than an exception when the gateway will not answer: the+ * query is addressed by a hash Spotify retires on its own schedule, and+ * the caller has a second way to read the same list.+ */+ private suspend fun gatewaySavedTracks(+ base: PlaylistState,+ showProgress: Boolean,+ ): List<CatalogTrack>? {+ val keys = container.pathfinderKeys+ keys.refresh()+ val language = java.util.Locale.getDefault().language++ val loaded = mutableListOf<CatalogTrack>()+ var offset = 0+ while (true) {+ val page = runCatching {+ val raw = withContext(Dispatchers.IO) {+ NativeBridge.likedSongs(+ """{"offset":$offset,"limit":$GATEWAY_LIBRARY_PAGE}""",+ language,+ keys.likedSongs,+ keys.appVersion,+ )+ }+ SavedTracks.parse(raw)+ }+ .onFailure { android.util.Log.i(TAG, "no liked songs from the gateway: ${describe(it)}") }+ .getOrNull()+ // A page that will not come back gives up the whole read, part+ // way through as much as at the start. What is returned here is+ // written to the cache and stamped as the list, so half of Liked+ // Songs would be remembered as all of it.+ if (page == null) return null++ loaded += page.tracks+ val next = page.nextOffset+ if (showProgress) {+ publishPlaylist(base.copy(+ tracks = loaded.toList(),+ loadingMore = next != null,+ ))+ }+ // Counted as well as followed: a page that names itself as its own+ // successor would otherwise be read for ever.+ if (next == null || next <= offset || loaded.size >= page.total) {+ android.util.Log.i(TAG, "liked songs: ${loaded.size} of ${page.total} from the gateway")+ return loaded+ }+ offset = next+ }+ }+private suspend fun accessPointTracks(base: PlaylistState,uri: String,@@ -2174,6 +2246,14 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {*/const val WEB_API_LIBRARY_PAGE = 50+ /**+ * And what the gateway takes, which is four times either.+ *+ * Two hundred whole tracks came back in half a second on a phone, so+ * the account's whole collection is a handful of requests.+ */+ const val GATEWAY_LIBRARY_PAGE = 200+/** How many track lists to keep resolved; see contextCache. */const val CONTEXT_CACHE_SIZE = 8diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xmlindex 7f9884a..7af1d6b 100644--- a/app/src/main/res/values-de/strings.xml+++ b/app/src/main/res/values-de/strings.xml@@ -79,6 +79,7 @@<string name="hours_minutes">%1$d Std. %2$d Min.</string><string name="minutes_only">%1$d Min.</string><string name="artist_needs_app">Für einen Künstler braucht es deine eigene Spotify-Anwendung: richte sie unter Suchen ein.</string>+ <string name="liked_songs_failed">Deine Lieblingssongs konnten nicht gelesen werden: versuch es gleich noch einmal.</string><string name="add_to_queue">Zur Warteschlange</string><string name="add_to_playlist">Zu einer Playlist hinzufügen</string>diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xmlindex 7d2e4b3..d7c486b 100644--- a/app/src/main/res/values-es/strings.xml+++ b/app/src/main/res/values-es/strings.xml@@ -79,6 +79,7 @@<string name="hours_minutes">%1$d h %2$d min</string><string name="minutes_only">%1$d min</string><string name="artist_needs_app">Para abrir un artista hace falta tu propia aplicación de Spotify: configúrala en Buscar.</string>+ <string name="liked_songs_failed">No se han podido leer tus canciones que te gustan: inténtalo dentro de un momento.</string><string name="add_to_queue">Añadir a la cola</string><string name="add_to_playlist">Añadir a una playlist</string>diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xmlindex 10a74f5..c151c20 100644--- a/app/src/main/res/values-fr/strings.xml+++ b/app/src/main/res/values-fr/strings.xml@@ -79,6 +79,7 @@<string name="hours_minutes">%1$d h %2$d min</string><string name="minutes_only">%1$d min</string><string name="artist_needs_app">Ouvrir un artiste demande votre propre application Spotify : configurez-la dans Rechercher.</string>+ <string name="liked_songs_failed">Impossible de lire vos titres likés : réessayez dans un instant.</string><string name="add_to_queue">Ajouter à la file</string><string name="add_to_playlist">Ajouter à une playlist</string>diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xmlindex 049aaf8..162249f 100644--- a/app/src/main/res/values-hi/strings.xml+++ b/app/src/main/res/values-hi/strings.xml@@ -87,6 +87,7 @@<string name="hours_minutes">%1$d घं %2$d मि</string><string name="minutes_only">%1$d मि</string><string name="artist_needs_app">किसी कलाकार को खोलने के लिए आपका अपना Spotify ऐप्लिकेशन चाहिए; इसे खोज में सेट करें।</string>+ <string name="liked_songs_failed">पसंद किए गए गाने पढ़े नहीं जा सके; थोड़ी देर बाद फिर कोशिश करें।</string><!-- Track menu --><string name="add_to_queue">कतार में जोड़ें</string>diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xmlindex 2342a10..936c643 100644--- a/app/src/main/res/values-it/strings.xml+++ b/app/src/main/res/values-it/strings.xml@@ -80,6 +80,7 @@<string name="hours_minutes">%1$dh %2$dmin</string><string name="minutes_only">%1$dmin</string><string name="artist_needs_app">Per aprire un artista serve la tua applicazione Spotify, configurala in Cerca.</string>+ <string name="liked_songs_failed">Non è stato possibile leggere i brani che ti piacciono, riprova tra poco.</string><string name="add_to_queue">Aggiungi alla coda</string><string name="add_to_playlist">Aggiungi a una playlist</string>diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xmlindex d6dc206..513f43c 100644--- a/app/src/main/res/values-pt/strings.xml+++ b/app/src/main/res/values-pt/strings.xml@@ -79,6 +79,7 @@<string name="hours_minutes">%1$dh %2$dmin</string><string name="minutes_only">%1$dmin</string><string name="artist_needs_app">Para abrir um artista é preciso a sua própria aplicação do Spotify: configure-a em Buscar.</string>+ <string name="liked_songs_failed">Não foi possível ler as suas músicas curtidas: tente de novo daqui a pouco.</string><string name="add_to_queue">Adicionar à fila</string><string name="add_to_playlist">Adicionar a uma playlist</string>diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xmlindex 256f49e..4ef266b 100644--- a/app/src/main/res/values-tr/strings.xml+++ b/app/src/main/res/values-tr/strings.xml@@ -87,6 +87,7 @@<string name="hours_minutes">%1$d sa %2$d dk</string><string name="minutes_only">%1$d dk</string><string name="artist_needs_app">Bir sanatçıyı açmak için kendi Spotify uygulaman gerekir; Ara bölümünden ayarla.</string>+ <string name="liked_songs_failed">Beğenilen şarkılar okunamadı; birazdan tekrar dene.</string><!-- Track menu --><string name="add_to_queue">Sıraya ekle</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 2a96725..92837a8 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -93,6 +93,7 @@<string name="hours_minutes">%1$dh %2$dmin</string><string name="minutes_only">%1$dmin</string><string name="artist_needs_app">Opening an artist needs your own Spotify application; set it up in Search.</string>+ <string name="liked_songs_failed">Liked Songs could not be read; try again in a moment.</string><!-- Track menu --><string name="add_to_queue">Add to queue</string>diff --git a/native/src/ffi.rs b/native/src/ffi.rsindex 9faf465..fb45e69 100644--- a/native/src/ffi.rs+++ b/native/src/ffi.rs@@ -557,6 +557,25 @@ pub extern "system" fn Java_dev_lelonio_square_nativecore_NativeBridge_nativeHom})}+/// The account's saved tracks, as raw JSON from Spotify's gateway.+#[no_mangle]+pub extern "system" fn Java_dev_lelonio_square_nativecore_NativeBridge_nativeLikedSongs(+ mut env: JNIEnv,+ _class: JClass,+ variables: JString,+ language: JString,+ hash: JString,+ app_version: JString,+) -> jstring {+ let variables = read_string(&mut env, &variables).unwrap_or_default();+ let language = read_string(&mut env, &language).unwrap_or_default();+ let hash = read_string(&mut env, &hash).unwrap_or_default();+ let app_version = read_string(&mut env, &app_version).unwrap_or_default();+ guard_string(&mut env, "LikedSongs", || {+ crate::pathfinder::liked_songs(&variables, &language, &hash, &app_version)+ })+}+/// This device's own Connect id.#[no_mangle]pub extern "system" fn Java_dev_lelonio_square_nativecore_NativeBridge_nativeDeviceId(diff --git a/native/src/pathfinder.rs b/native/src/pathfinder.rsindex 3c53170..2c5a6c4 100644--- a/native/src/pathfinder.rs+++ b/native/src/pathfinder.rs@@ -53,6 +53,9 @@ struct Query {/// this is the floor rather than the answer.const HOME_HASH: &str = "76243c78b0e20ecdbe41b794dec8cbe73f75e585b0a7201b8d2e84578412847a";+/// The same, for the saved-tracks query the web player's library page uses.+const LIKED_HASH: &str = "c2c53c28f71da143c0753c22dc84d98b315cb4275472ea5a597c29338ae20b23";+/// Runs one persisted query and returns the raw JSON body.async fn query(session: &Session,@@ -189,3 +192,35 @@ pub fn home(handle.block_on(async move { query(&session, &home, variables, &language, &app_version).await })}++/// The account's saved tracks, as the web player's library page reads them.+///+/// The one list the Web API cannot be asked for without the listener having+/// registered an application of their own, and the one the access point will+/// not resolve as a context. Paged by the caller: `{"offset":n,"limit":n}`,+/// and the gateway answers with the whole of each track rather than its URI.+pub fn liked_songs(+ variables: &str,+ language: &str,+ hash: &str,+ app_version: &str,+) -> engine::EngineResult<String> {+ let handle = engine::runtime_handle()?;+ let session = engine::with_session(|session| session.clone())?;+ let language = if language.is_empty() { "en" } else { language }.to_string();++ let liked = Query {+ name: "getLikedSongs",+ hash: if hash.is_empty() {+ LIKED_HASH.to_string()+ } else {+ hash.to_string()+ },+ };+ let app_version = app_version.to_string();+ let variables = if variables.is_empty() { "{}" } else { variables }.to_string();++ handle.block_on(async move {+ query(&session, &liked, variables, &language, &app_version).await+ })+}diff --git a/pathfinder.json b/pathfinder.jsonindex a225259..1fa0e27 100644--- a/pathfinder.json+++ b/pathfinder.json@@ -1,5 +1,6 @@{"_comment": "Identifiers Spotify's GraphQL gateway wants from a caller. Read by Square at runtime so a change here needs no new version of the app: see app/src/main/java/dev/lelonio/square/data/PathfinderKeys.kt. Both values are retired by Spotify whenever it rebuilds its web client, and both are readable from a network capture of open.spotify.com.","home": "76243c78b0e20ecdbe41b794dec8cbe73f75e585b0a7201b8d2e84578412847a",+ "likedSongs": "c2c53c28f71da143c0753c22dc84d98b315cb4275472ea5a597c29338ae20b23","appVersion": "1.2.97.155.g5dd0dcaf-development"}