Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Show playlist covers sharp and whole

Lelonio5c8fe1d7f232
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/Artwork.kt b/app/src/main/java/dev/lelonio/square/ui/components/Artwork.kt
index a2ec416..c5da86d 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/Artwork.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/Artwork.kt
@@ -294,6 +294,47 @@ fun spotifyResizedUrl(url: String, targetPx: Int): String {
return url.dropLast(SPOTIFY_ID_LEN) + family + rendition + tail
}
+/**
+ * The largest print the CDN publishes of the same picture, for one drawn
+ * across the whole screen.
+ *
+ * What a page is handed is a list-sized print: a playlist of Spotify's own
+ * comes as `ab67706f00000002…`, which is 300 across, and the header crops it
+ * to its own shape and draws it the width of the phone — five times over,
+ * which is the soft cover a listener reported. The same picture is there
+ * larger under another prefix, measured against the CDN rather than guessed:
+ * - Spotify's playlists (`ab67706f`): `00000004` → 1280 px
+ * - Listeners' own playlist covers (`ab67706c`): `0000bebb` → 640 px
+ * - Albums (`ab67616d`): `000082c1` → 2000 px
+ * - Artists (`ab676161`): `0000e5eb` → 640 px
+ * - Playlist mosaics (`mosaic.scdn.co/<size>/…`): 640 px, the most it makes
+ *
+ * Anything else comes back unchanged. A print that turns out to be missing is
+ * the caller's to fall back from, to the url it had.
+ */
+fun spotifyLargeUrl(url: String): String {
+ if (url.startsWith("https://mosaic.scdn.co/")) {
+ val rest = url.removePrefix("https://mosaic.scdn.co/")
+ val size = rest.substringBefore('/')
+ if (size.all(Char::isDigit) && size != "640") {
+ return "https://mosaic.scdn.co/640/" + rest.substringAfter('/')
+ }
+ return url
+ }
+ val id = url.substringAfterLast('/')
+ if (id.length != SPOTIFY_ID_LEN || !id.all { it.isDigit() || it in 'a'..'f' }) return url
+ val family = id.take(8)
+ val rendition = when (family) {
+ "ab67706f" -> "00000004"
+ "ab67706c" -> "0000bebb"
+ "ab67616d" -> "000082c1"
+ "ab676161" -> "0000e5eb"
+ else -> return url
+ }
+ val tail = id.drop(SPOTIFY_SIZE_PREFIX_LEN)
+ return url.dropLast(SPOTIFY_ID_LEN) + family + rendition + tail
+}
+
/**
* Resolves a canonical cache key for an image URL.
*
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
index 7169c5f..a9d6877 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
@@ -170,7 +170,15 @@ fun HeroBackdrop(
return@produceState
}
value = coroutineScope {
- val cover = async { loadArt(context, artworkUrl, COVER_PX) }
+ // The largest print there is, since this one fills the screen;
+ // the url as given when there is no larger one, and offline, where
+ // only the copy kept on the phone may be drawn.
+ val cover = async {
+ val large = spotifyLargeUrl(artworkUrl)
+ val sharper = large != artworkUrl && !dev.lelonio.square.playback.OfflineMode.active.value
+ (if (sharper) loadArt(context, large, COVER_PX) else null)
+ ?: loadArt(context, artworkUrl, COVER_PX)
+ }
val edge = async { if (extended) loadArt(context, artworkUrl, EXTENSION_PX) else null }
val blur = async { loadArt(context, artworkUrl, HERO_BLUR_PX, blurred = true) }
cover.await()?.let { ArtSet(it, edge.await(), blur.await(), zoom) }
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
index 6315f16..f0b8b1a 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
@@ -563,7 +563,12 @@ fun PlaylistScreen(
// as a square, and each is drawn at the shape it was made in. What is left
// of the header below it is the picture carrying on, blurred.
val screenWidth = androidx.compose.ui.platform.LocalConfiguration.current.screenWidthDp.dp
- val artHeight = state.heroAspect
+ // A cover is square, and drawn whole. Cropped to fill the header, which is
+ // taller than it is wide, it lost a strip down either side — the words
+ // and faces a playlist's cover has at its edges. Only a photograph made
+ // for a header is laid over the whole of it.
+ val shownAspect = if (state.heroUrl != null) state.heroAspect else 1f
+ val artHeight = shownAspect
?.let { (screenWidth / it).coerceIn(200.dp, heroHeight) }
?: heroHeight
@@ -640,7 +645,7 @@ fun PlaylistScreen(
heroPx = heroPx,
collapsedPx = collapsedPx,
collapse = collapseFraction,
- imageAspect = state.heroAspect,
+ imageAspect = shownAspect,
pending = state.heroPending,
)
}