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
Fetch the covers Spotify's own playlists keep to themselves
Lelonio96fd34950c88
diff --git a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.binindex f856c4c..8f8ba8d 100644--- a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin+++ b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin@@ -2,27 +2,27 @@ C/C++ Structured Logca_/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/additional_project_files.txtCA-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint ��ƌ�3 ��߈�3`+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint ����3 ��߈�3`^-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json ��ƌ�3� ��߈�3e+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json ����3� ��߈�3ec-a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json ��ƌ�3� ��߈�3R+a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json ����3� ��߈�3RP-N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja ��ƌ�3� ��߈�3V+N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja ����3� ��߈�3VT-R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt ��ƌ�3[+R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt ����3[Y-W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt ��ƌ�3 @ ��߈�3\+W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt ����3 @ ��߈�3\Z-X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json ��ƌ�3֚ ��߈�3`+X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json ����3֚ ��߈�3`^-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin ��ƌ�3 �" ��߈�3f+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin ����3 �" ��߈�3fd-b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt ��ƌ�3+b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt ����3� ��߈�3YW-U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json ��ƌ�3 ( ��߈�3^+U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json ����3 ( ��߈�3^\-Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt ��ƌ�3 Y ��߈�3D+Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt ����3 Y ��߈�3DB-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt ��ƌ�3 � �Ȅ��3\ No newline at end of file+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt ����3 � �Ȅ��3\ No newline at end of filediff --git a/app/src/main/java/dev/emanuele/spot/data/Catalog.kt b/app/src/main/java/dev/emanuele/spot/data/Catalog.ktindex 5b8add1..afb3fdb 100644--- a/app/src/main/java/dev/emanuele/spot/data/Catalog.kt+++ b/app/src/main/java/dev/emanuele/spot/data/Catalog.kt@@ -159,6 +159,18 @@ object Catalog {json.decodeFromString<List<CatalogPlaylist>>(NativeBridge.rootlist())}+ /**+ * The cover of one playlist, fetched on its own.+ *+ * Only worth calling for playlists the rootlist gave no artwork for — see+ * the note on the native side. Null both when Spotify has no cover and when+ * the lookup fails: a missing tile falls back to the generated one either+ * way, and a playlist list should not fail over an image.+ */+ suspend fun playlistCover(uri: String): String? = withContext(Dispatchers.IO) {+ runCatching { json.decodeFromString<String?>(NativeBridge.playlistCover(uri)) }.getOrNull()+ }+/*** Tracks of the account's first playlist.*diff --git a/app/src/main/java/dev/emanuele/spot/nativecore/NativeBridge.kt b/app/src/main/java/dev/emanuele/spot/nativecore/NativeBridge.ktindex 9a52bda..dc7440d 100644--- a/app/src/main/java/dev/emanuele/spot/nativecore/NativeBridge.kt+++ b/app/src/main/java/dev/emanuele/spot/nativecore/NativeBridge.kt@@ -133,6 +133,15 @@ object NativeBridge {*/fun canvas(trackUri: String): String = nativeCanvas(trackUri)+ /**+ * A playlist's cover URL as a JSON string, or the string `null`.+ *+ * The account's index of its playlists carries a picture only for the ones+ * the user made; Spotify's own keep theirs on the playlist itself.+ */+ fun playlistCover(uri: String): String = nativePlaylistCover(uri)++ private external fun nativePlaylistCover(uri: String): Stringprivate external fun nativeInitContext(context: android.content.Context)private external fun nativeSetAudioOutput(output: Any)private external fun nativeStart(diff --git a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.ktindex 8e24c12..439f69f 100644--- a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt@@ -564,6 +564,7 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {.onSuccess {_state.value = itloadProfile()+ loadMissingCovers()}.onFailure {android.util.Log.e(TAG, "library load failed: ${chain(it)}", it)@@ -603,6 +604,39 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {}.getOrThrow()+ /** Covers already looked up, so a second visit to the home page is free. */+ private val coverCache = mutableMapOf<String, String>()++ /**+ * Fills in the covers the rootlist did not carry.+ *+ * Spotify's own playlists — the editorial ones, the daily mixes — keep their+ * art on the playlist rather than in the account's index of it, so those+ * tiles came out blank while the user's own were fine. One lookup each,+ * after the page is already on screen, and a failure just leaves the+ * generated tile in place.+ */+ private fun loadMissingCovers() = viewModelScope.launch {+ val ready = _state.value as? UiState.Ready ?: return@launch+ val missing = ready.playlists.filter { it.artworkUrl == null }+ if (missing.isEmpty()) return@launch++ missing.forEach { playlist ->+ val cover = coverCache[playlist.uri] ?: Catalog.playlistCover(playlist.uri)+ if (cover.isNullOrEmpty()) return@forEach+ coverCache[playlist.uri] = cover++ // Re-read each time: the list can have been replaced by a refresh+ // while these were being fetched, one at a time.+ val current = _state.value as? UiState.Ready ?: return@launch+ _state.value = current.copy(+ playlists = current.playlists.map {+ if (it.uri == playlist.uri) it.copy(artworkUrl = cover) else it+ },+ )+ }+ }+private fun loadProfile() = viewModelScope.launch {if (!container.webApi.isReady) return@launchrunCatching { container.api.me() }diff --git a/native/src/catalog.rs b/native/src/catalog.rsindex dfedf3d..7e1de81 100644--- a/native/src/catalog.rs+++ b/native/src/catalog.rs@@ -270,6 +270,73 @@ fn track_json(track: &Track) -> Value {})}+/// The cover of one playlist, as a URL, or `null`.+///+/// The rootlist carries a picture for playlists the user made and nothing for+/// the ones Spotify makes — the editorial and algorithmic lists keep their art+/// on the playlist itself rather than in the account's index of it, so the tiles+/// for those came out blank.+///+/// Two places to look. `attributes.picture` is the ordinary cover. Algorithmic+/// lists — Discover Weekly, the daily mixes — instead carry theirs among the+/// format attributes as a key/value pair, sometimes already a URL and sometimes+/// a `spotify:image:` URI, so both spellings are accepted.+pub fn playlist_cover(uri: &str) -> EngineResult<String> {+ let parsed = SpotifyUri::from_uri(uri).map_err(|e| format!("bad uri: {e}"))?;+ let SpotifyUri::Playlist { id, .. } = parsed else {+ return Ok("null".into());+ };++ let session = with_session(|s| s.clone())?;+ block_on(async move {+ let bytes = session+ .spclient()+ .get_playlist(&id)+ .await+ .map_err(|e| format!("playlist read failed: {e}"))?;++ let list = SelectedListContent::parse_from_bytes(&bytes)+ .map_err(|e| format!("playlist was not a SelectedListContent: {e}"))?;++ let attributes = &list.attributes;+ let cover = image_url(attributes.picture())+ .or_else(|| {+ attributes+ .format_attributes+ .iter()+ .find(|attribute| attribute.key().contains("image_url"))+ .and_then(|attribute| cdn_url(attribute.value()))+ })+ .or_else(|| {+ // The sized variants, when there is no single picture: the+ // largest is last in Spotify's own order, and any of them is a+ // better tile than none.+ attributes+ .picture_size+ .iter()+ .last()+ .and_then(|size| cdn_url(size.url()))+ });++ Ok(json!(cover).to_string())+ })+}++/// Accepts either a URL or a `spotify:image:<hex>` URI, and returns a URL.+fn cdn_url(value: &str) -> Option<String> {+ if value.is_empty() {+ None+ } else if value.starts_with("http") {+ Some(value.to_string())+ } else {+ value+ .rsplit(':')+ .next()+ .filter(|id| !id.is_empty())+ .map(|id| format!("{IMAGE_CDN}{id}"))+ }+}+/// A CDN URL for a raw image id, or None when the field is empty.////// Playlist artwork arrives as the image's raw file id rather than a URL, anddiff --git a/native/src/ffi.rs b/native/src/ffi.rsindex c394459..bbc35f2 100644--- a/native/src/ffi.rs+++ b/native/src/ffi.rs@@ -280,6 +280,16 @@ pub extern "system" fn Java_dev_emanuele_spot_nativecore_NativeBridge_nativeContstring_or_throw(&mut env, result)}+#[no_mangle]+pub extern "system" fn Java_dev_emanuele_spot_nativecore_NativeBridge_nativePlaylistCover(+ mut env: JNIEnv,+ _class: JClass,+ uri: JString,+) -> jstring {+ let result = read_string(&mut env, &uri).and_then(|uri| catalog::playlist_cover(&uri));+ string_or_throw(&mut env, result)+}+#[no_mangle]pub extern "system" fn Java_dev_emanuele_spot_nativecore_NativeBridge_nativeCanvas(mut env: JNIEnv,