Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Ads recognised by metadata, promotion shelves and sponsored hosts blocked; artist discography shows again; lyrics button removed
kota-zod4d844c81ff6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 525c211c..c202f5d1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,12 +4,13 @@ Each release on GitHub shows its section below. The app shows it too when it off## 2.0.0-beta.6-- **Fewer ads abroad**: ads from other countries' ad servers are blocked too; an ad that still gets through is muted and skipped.+- **Fewer ads abroad**: ads from other countries' ad servers, sponsored playlists and promotion shelves are blocked; ads are recognised even when they look like songs; an ad that still gets through is muted and skipped.+- **Artist discography** (Releases) shows albums and singles again.- **A pause stays a pause**, even right at the end of a song.- **Downloads are safe**: a damaged download list no longer deletes your downloaded songs.- **Changes Spotify refuses are undone on screen** (likes, playlist visibility), with a message.- **Search** keeps your query when you come back, and says when it is loading, empty or failed (with Try again). Artist and profile pages can be reloaded too.-- **Lyrics button** in the player; **Jam**: join with a copied link; sharing an episode works.+- **Jam**: join with a copied link; sharing an episode works.- **Logout** stops everything (local songs, video, notification); the data saver applies from launch.- Player buttons are named for TalkBack.diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.ktindex f99262b7..e6c9355c 100644--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt@@ -54,8 +54,15 @@ import java.util.TimeZoneprivate fun idOf(uri: Uri) = uri.substringAfterLast(':')+/** Promotions and ads (HomePromotionShelf, sponsored cards…): never shown as content. */+internal fun isPromotion(typename: String?): Boolean =+ typename != null && Regex("Promotion|Sponsor|Advert|(^|[a-z])Ad([A-Z]|$)").containsMatchIn(typename)+private fun shelf(section: JsonElement): Shelf? {- val items = section.list("sectionItems.items").mapNotNull { card(it.at("content")) }+ if (isPromotion(section.at("data").typename()) || isPromotion(section.typename())) return null+ val items = section.list("sectionItems.items")+ .filterNot { isPromotion(it.at("content").typename()) || isPromotion(it.at("content.data").typename()) }+ .mapNotNull { card(it.at("content")) }if (items.isEmpty()) return nullreturn Shelf(uri = section.str("uri"),diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/BridgeHost.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/BridgeHost.ktindex a9c24b48..3f13fb4c 100644--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/BridgeHost.kt+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/BridgeHost.kt@@ -51,6 +51,13 @@ object AdBlock {"googleads.g.doubleclick.net","pagead2.googlesyndication.com","imasdk.googleapis.com",+ // Sponsored playlists and recommendations.+ "sponsored-recommendations.spotify.com",+ // Ad and audience trackers the page loads (nothing it needs to play).+ "googletagmanager.com",+ "google-analytics.com",+ "scorecardresearch.com",+ "fastly-insights.com",)/** Ad endpoints on Spotify's api hosts (spclient): ad slots, ad logic and ad delivery. */diff --git a/base/api-spotify/src/main/resources/bridge/player-bridge.js b/base/api-spotify/src/main/resources/bridge/player-bridge.jsindex c9847279..6cf15e99 100644--- a/base/api-spotify/src/main/resources/bridge/player-bridge.js+++ b/base/api-spotify/src/main/resources/bridge/player-bridge.js@@ -87,7 +87,11 @@};// Ads come in the same queue as tracks, with `type: "ad"` and a title instead of a name.- const kind = item => item.type === 'ad' || /^spotify:ad:/.test(item.uri) ? 'ad'+ // Some markets give them a track-like uri: the metadata still flags them.+ const isAd = item => item.type === 'ad' || /^spotify:ad:/.test(item.uri || '') ||+ item.provider === 'ad' || !!item.advertiser ||+ (item.metadata && (item.metadata.is_advertisement === 'true' || item.metadata.is_advertisement === true || !!item.metadata.ad_id));+ const kind = item => isAd(item) ? 'ad': /^spotify:episode:/.test(item.uri) ? 'episode' : 'track';const track = item => item && {diff --git a/base/api-spotify/src/test/kotlin/app/myspoti/spotify/bridge/AdBlockTest.kt b/base/api-spotify/src/test/kotlin/app/myspoti/spotify/bridge/AdBlockTest.ktindex eceaf32c..46a73925 100644--- a/base/api-spotify/src/test/kotlin/app/myspoti/spotify/bridge/AdBlockTest.kt+++ b/base/api-spotify/src/test/kotlin/app/myspoti/spotify/bridge/AdBlockTest.kt@@ -25,6 +25,18 @@ class AdBlockTest {assertFalse(AdBlock.isBlocked("https://open.spotify.com/ads/"))}+ @Test+ fun `promotion shelves and sponsored cards are told apart`() {+ assertTrue(app.myspoti.spotify.isPromotion("HomePromotionSectionData"))+ assertTrue(app.myspoti.spotify.isPromotion("HomePromotionShelf"))+ assertTrue(app.myspoti.spotify.isPromotion("SponsoredPlaylist"))+ assertTrue(app.myspoti.spotify.isPromotion("EmbeddedAdVisual"))+ assertFalse(app.myspoti.spotify.isPromotion("HomeGenericSectionData"))+ assertFalse(app.myspoti.spotify.isPromotion("PlaylistResponseWrapper"))+ assertFalse(app.myspoti.spotify.isPromotion("AlbumResponseWrapper"))+ assertFalse(app.myspoti.spotify.isPromotion("Audiobook"))+ }+@Testfun `base62 ids convert to metadata gids`() {// Pair checked against a captured metadata/4 request.diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.ktindex 88e252f8..8b23e6d2 100644--- a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt@@ -273,13 +273,17 @@ fun MyNavHost(navBackStackEntry.arguments?.getString("id")?.let { com.music.spotui.ui.screens.LocalPlaylistScreen(navHostController, it) }}- page("${Routes.ArtistReleases.route}/{aString}") { navBackStackEntry ->+ page(+ "${Routes.ArtistReleases.route}/{aString}?id={artistId}",+ arguments = listOf(navArgument("artistId") { defaultValue = "" }),+ ) { navBackStackEntry ->LaunchedEffect(playerState) {bottomBarState.value = truebottomBarPlayerState.value = playerState != ""}val aId = navBackStackEntry.arguments?.getString("aString")- aId?.let { ArtistReleasesScreen(navHostController, it) }+ val artistId = navBackStackEntry.arguments?.getString("artistId").orEmpty()+ aId?.let { ArtistReleasesScreen(navHostController, it, artistId) }}page(diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.ktindex f4e3a4de..86e78302 100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt@@ -388,7 +388,7 @@ private fun ArtistOverviewContent(if (overview.popularReleases.size > 4) {item {ShowAllButton {- navController.navigate("${Routes.ArtistReleases.route}/$artistName")+ navController.navigate("${Routes.ArtistReleases.route}/${android.net.Uri.encode(artistName)}?id=${android.net.Uri.encode(overview.id)}")}}}@@ -629,7 +629,11 @@ private fun ReleaseRow(album: AlbumsModel, onClick: () -> Unit) {Spacer(Modifier.width(14.dp))Column(modifier = Modifier.weight(1f)) {Text(text = album.name, color = Color.White, fontSize = 17.sp, fontWeight = FontWeight.Bold, maxLines = 1)- val kind = album.type.replaceFirstChar { it.uppercase() }.ifBlank { "" }+ val kind = when (album.type.uppercase()) {+ "SINGLE" -> stringResource(R.string.album_type_single); "EP" -> stringResource(R.string.album_type_ep)+ "COMPILATION" -> stringResource(R.string.album_type_compilation); "" -> ""+ else -> stringResource(R.string.album_type_album)+ }val year = releaseYear(album)Text(text = listOf(year, kind).filter { it.isNotBlank() }.joinToString(" • "),@@ -660,11 +664,11 @@ private fun releaseYear(album: AlbumsModel): String = album.time.take(4)@OptIn(ExperimentalGlideComposeApi::class)@Composable-fun ArtistReleasesScreen(navController: NavController, artistName: String) {+fun ArtistReleasesScreen(navController: NavController, artistName: String, artistId: String = "") {val artistViewModel: ArtistViewModel = viewModel()val overview by artistViewModel.overview.collectAsState()- LaunchedEffect(artistName) { artistViewModel.loadArtistOverview(artistName) }+ LaunchedEffect(artistName, artistId) { artistViewModel.loadArtistOverview(artistName, artistId) }Surface(modifier = Modifier@@ -676,9 +680,10 @@ fun ArtistReleasesScreen(navController: NavController, artistName: String) {val featuredOn = data?.appearsOn ?: emptyList()// Spotify's Releases view: filter chips + a "Latest release" spotlight,// then releases grouped by kind, newest first.- val albums = releases.filter { it.type == "album" || it.type == "compilation" }- val singles = releases.filter { it.type == "single" || it.type == "ep" }- val untyped = releases.filter { it.type.isBlank() }+ // Spotify names the kinds in capitals ("ALBUM", "SINGLE"…): compared without case.+ val albums = releases.filter { it.type.lowercase() == "album" || it.type.lowercase() == "compilation" }+ val singles = releases.filter { it.type.lowercase() == "single" || it.type.lowercase() == "ep" }+ val untyped = releases.filter { it.type.lowercase() !in setOf("album", "compilation", "single", "ep") }val latest = releases.maxByOrNull { it.time }var filter by remember { mutableStateOf("") } // "" | "albums" | "singles" | "featured"diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.ktindex c795f843..95e1fc02 100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt@@ -74,7 +74,6 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport com.music.spotui.ui.components.pressable-import androidx.compose.material.icons.outlined.Lyricsimport androidx.compose.ui.graphics.graphicsLayerimport androidx.compose.ui.input.nestedscroll.nestedScrollimport androidx.compose.runtime.setValue@@ -447,7 +446,6 @@ fun PlayerScreen(navController: NavController) {context = context,onDevices = { showDevices = true },onQueue = { showQueue = true },- onLyrics = { showLyrics = true },)Spacer(modifier = Modifier.height(20.dp))}@@ -971,7 +969,6 @@ fun PlayerConnectRow(context: Context,onDevices: () -> Unit,onQueue: () -> Unit,- onLyrics: () -> Unit = {},) {Row(verticalAlignment = Alignment.CenterVertically,@@ -1006,14 +1003,6 @@ fun PlayerConnectRow()}Row(verticalAlignment = Alignment.CenterVertically) {- // Lyrics also show below the player; this button makes them easy to find.- Icon(- imageVector = androidx.compose.material.icons.Icons.Outlined.Lyrics,- tint = Color.White,- modifier = Modifier.size(22.dp).pressable { onLyrics() },- contentDescription = stringResource(R.string.lyrics_fullscreen),- )- Spacer(modifier = Modifier.width(24.dp))Icon(painter = painterResource(id = R.drawable.ic_share),tint = Color.White,diff --git a/docs/CHANGELOG-full.md b/docs/CHANGELOG-full.mdindex ef081916..ed476239 100644--- a/docs/CHANGELOG-full.md+++ b/docs/CHANGELOG-full.md@@ -5,11 +5,13 @@ Every change, release by release. The short version is in [CHANGELOG.md](../CHAN## 2.0.0-beta.6- **Ads in other countries**: Google's ad servers (audio and video ads), the ad event tracker and Spotify's ad endpoints (`/ads/`, `/ad-logic/` on spclient) are refused. An ad that plays anyway is muted at once and skipped after 1.5 s; if the page holds on to it after one reload, it stays muted until it ends. The volume comes back after the ad, and after a restart if the app was closed during one.+- **Ads, continued**: an ad is recognised by its metadata too (`is_advertisement`, `ad_id`, advertiser), not only by a `spotify:ad:` uri. Home promotion shelves and sponsored cards are dropped. Sponsored recommendations and the page's ad/audience trackers (Google Tag Manager, Google Analytics, Scorecard Research, Fastly Insights) are blocked.+- **Artist discography**: the Releases page filtered on lowercase kinds while Spotify sends "ALBUM", "SINGLE"…, so it stayed empty; it also opens by artist id now, and kinds are shown translated.- **Pause**: a pause you ask for no longer expires; the stall watchdog never restarts playback after it, even when paused in the last seconds of a song.- **Download index**: an index that cannot be read fully is never used to delete files. The last good copy (`index.json.bak`) is used, the damaged one is kept aside (`index.corrupt-*.json`), and no file is deleted.- **Spotify writes**: a write (add to playlist, follow…) is never sent twice when its answer is lost; a GraphQL error on a write is a failure, not a success. Likes, library saves and playlist visibility go one at a time and come back to the real state when Spotify refuses, with a message.- **Search**: query and chip kept when coming back from a result; loading, no results and failure are shown apart, with Try again. Artist and profile pages show an error with Try again instead of an empty page.-- **Player**: a lyrics button next to share (lyrics were only reachable by scrolling); share sends the episode link for episodes; play, pause, next, previous, shuffle, close and devices have names for TalkBack.+- **Player**: share sends the episode link for episodes; play, pause, next, previous, shuffle, close and devices have names for TalkBack.- **Jam**: "Join with a copied link"; a phone without the QR scanner gets a message instead of nothing.- **Logout** stops local playback, the music video and the notification, pauses Spotify and drops the cached pages.- **Data saver**: on mobile data with the saver on, the Spotify page is not loaded at launch.