Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: the ad, upsell and Premium switches return with their license credit

My-Name-Is-Jeffd8553beaccc7
diff --git a/AGENTS.md b/AGENTS.md
index 7c400656..7abd1104 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -15,7 +15,7 @@ A Theos tweak (Objective-C + Logos) injected into the decrypted Spotify iOS app.
playlist, album and artist pages the way the Music app lays them out with one pinned ⋯ over each, black
throughout, and its own accent colour. No native tweak runs.
-Anything that doesn't draw on Spotify's screens works the same under both: privacy, lyrics
+Anything that doesn't draw on Spotify's screens works the same under both: ads, privacy, lyrics
sources, gestures, blocked artists, flags, Vibrations, Speed and pitch, and the Live Activity. Those
last three were the redesign's until they moved to `Shared/`, so their keys lost the `.redesign.` and
`Core/SGPrefs.h`'s `SGMigrateKey` carries the old ones over at launch.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 798312be..f6ae1abd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@
### Fixes
-* Recents with Block telemetry on, lyrics cache eviction, protobuf length overflow, Set rule types, Live Activity update order ([4b21bed](https://github.com/skopevoj/spoti.pw/commit/4b21bed034953c9786521101da9f96197f949b90))
+* Recents with Block telemetry on, Spoof Premium with a 304, lyrics cache eviction, protobuf length overflow, Set rule types, Live Activity update order ([4b21bed](https://github.com/skopevoj/spoti.pw/commit/4b21bed034953c9786521101da9f96197f949b90))
* trim the Lyrics settings page ([76b8577](https://github.com/skopevoj/spoti.pw/commit/76b85776d1b6c4306ade9f2c84cd8039cbae4b55))
* trim the Mod Settings descriptions ([79572ae](https://github.com/skopevoj/spoti.pw/commit/79572ae06b2a606f69d8314d87d57d302e1d0999))
@@ -102,6 +102,7 @@
* add LRCLIB as the floor under the other lyrics sources ([ab78945](https://github.com/skopevoj/spoti.pw/commit/ab78945ecc114e3057af446c9d233d3e8f54cd1b))
* add new record trees flag ([8bbdb6e](https://github.com/skopevoj/spoti.pw/commit/8bbdb6e4eb224df8a7835586848df642068450db))
* Apple Music style lyrics only in the redesign and always on there, the native karaoke copy gone, and AGENTS.md and CLAUDE.md for agents ([cc24a25](https://github.com/skopevoj/spoti.pw/commit/cc24a25e29eaee1b103ca4019747884d3b3793b3))
+* block the ad card under the player and make crossfade and automix play ([55c3c60](https://github.com/skopevoj/spoti.pw/commit/55c3c60f7726e10e1e3bd3e5d0984b56c003e56a))
* declutter the album page and put its blurred cover behind the header ([f414321](https://github.com/skopevoj/spoti.pw/commit/f414321444edb8e8261429677c42560f420c93fd))
* declutter the artist page and fade its photo into a blur ([d169287](https://github.com/skopevoj/spoti.pw/commit/d1692876dcd2f7290cff6da4e5d4f46cb2560f10))
* Home's shortcut tiles hold their cover inset on a surface tinted faintly by it, instead of the stretched blur ([3de8ea1](https://github.com/skopevoj/spoti.pw/commit/3de8ea1431ebca3243c72a282108c829dfadcb71))
diff --git a/README.md b/README.md
index e101cdc8..24ae1dbb 100644
--- a/README.md
+++ b/README.md
@@ -85,7 +85,7 @@ The app keeps Spotify's bundle id, so it installs over the real Spotify.
[cyan](https://github.com/asdfzxcvbn/pyzule-rw) injects, [Theos](https://theos.dev) builds, and
[FLEX](https://github.com/FLEXTool/FLEX), as hopeless's AutoFLEX build in `vendor/`, is the inspector
-the view trees are read through. The lyrics hook follows
-[EeveeSpotify Reincarnated](https://github.com/SideloadLabs/EeveeSpotifyReincarnated)'s.
+the view trees are read through. The ad blocking and the Premium state are ported from
+[EeveeSpotify Reincarnated](https://github.com/SideloadLabs/EeveeSpotifyReincarnated).
GPL-3.0. Not affiliated with Spotify.
diff --git a/docs/parity.md b/docs/parity.md
index 09d91a1b..4240b11f 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -170,4 +170,3 @@ Rebuilt from behaviour-only descriptions; each commit credits the PR's author.
## Still open
- Device checks: nothing above has run on a phone. Each commit body lists what to check.
-- Ad and upsell hiding came back with the revert of `5705ca1`. Credit EeveeSpotify on the Licenses page.
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 65076d76..2bb0da48 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -71,7 +71,11 @@ A feature is a directory in its layer holding everything about one area of the a
Shared:
- Privacy/ telemetry blocking and its counters, and the Search switches that force their flags off (Clutter.m)
+ AdBlock/ EeveeSpotify's ad blocking: the ad and upsell services silenced (AdServices.x), ad components out of the
+ Hub JSON (AdHubs.x) and the feeds (Feeds.m), Premium pop-ups dropped (AdPopups.x), and the responses
+ rewritten on the way in (AdNetwork.x, Premium.m over the protobuf walker in Protobuf.m), with crossfade
+ and automix switched on in the player core and crossfade's switch kept in step with its slider (Crossfade.x)
+ Privacy/ telemetry blocking and its counters
ArtistBlock/ tracks by blocked artists skipped as they start (ArtistSkip.x), the list and the Blocked artists page under Player
Flags/ Spotify's remote-config flags: the provider hook, the generated table, the All flags page and the Labs page
Gestures/ the double tap zones on the player: the grid, what each cell does, the recognizer (each look hooks it on)
@@ -365,9 +369,11 @@ while its switch is on (Reverb has its Room and its Amount, the amount the playe
applying as it changes; the row reads out Off, On or how many effects are on. Home & Library, in the native look only:
the Gradient page (the wash behind the top of Home in one of eight colours, at three strengths and
four heights) and the Home flags, the parts of Home to hide including the DJ button and badge, the
-playlist header, buttons and pills to hide, and the Library flags. Then Privacy & clutter
-(Block telemetry; hiding the video carousel and social proof in Search, and a Tips page under them,
-every switch there forcing a flag Spotify ships on to off; then what the telemetry blocking has stopped) and Labs (features Spotify built and did not ship,
+playlist header, buttons and pills to hide, and the Library flags. Then Premium, ads & privacy
+(EeveeSpotify's Hide ads and Hide upsells, in the native look hiding the video carousel in Search, and
+an Ad and upsell flags page under them, every switch there forcing a flag Spotify ships on to off;
+Spoof Premium; Block telemetry; then what the ad
+blocking and the telemetry blocking have stopped) and Labs (features Spotify built and did not ship,
AI Chat (Martini) first). Last, All flags, Spotify's remote-config flags with a search field and an
Auto / Off / On control per flag (a text field for the number and text ones), and Mod: Updates
(the row reads out where the build stands and opens the changelog of everything newer than it, read
diff --git a/harness/lyrics-translation/build.sh b/harness/lyrics-translation/build.sh
index 7d7c7520..4cfb01c5 100755
--- a/harness/lyrics-translation/build.sh
+++ b/harness/lyrics-translation/build.sh
@@ -8,6 +8,6 @@ SRC=$(cd "$HERE/../../tweak/Sources" && pwd)
mkdir -p "$HERE/build"
xcrun -sdk macosx clang -target arm64-apple-ios17.0-macabi -isysroot "$(xcrun --sdk macosx --show-sdk-path)" -iframework "$(xcrun --sdk macosx --show-sdk-path)/System/iOSSupport/System/Library/Frameworks" -fobjc-arc -g -Wall -I"$SRC" \
"$HERE/check.m" "$SRC/Shared/LyricsSources/Musixmatch.m" "$SRC/Shared/LyricsTranslation/LyricsTranslation.m" \
- "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/Lyrics/Protobuf.m" "$SRC/Shared/LocalFiles/LocalFiles.m" \
+ "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" "$SRC/Shared/LocalFiles/LocalFiles.m" \
-framework UIKit -framework CoreGraphics -framework Security -framework Foundation -o "$HERE/build/check"
"$HERE/build/check"
diff --git a/harness/lyrics/build.sh b/harness/lyrics/build.sh
index 1fc3e28e..acf4a8bf 100755
--- a/harness/lyrics/build.sh
+++ b/harness/lyrics/build.sh
@@ -19,7 +19,7 @@ SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g ${OPT:--O0} \
-I"$SRC" -I"$SRC/Redesigned/Lyrics" -isysroot "$SDK" -Wall -Wno-deprecated-declarations \
"$HERE/main.m" "$HERE/../scene.m" "$HERE/stubs.m" \
- "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m $( [ -f "$SRC"/Redesigned/Lyrics/LyricsText.m ] && echo "$SRC"/Redesigned/Lyrics/LyricsText.m ) "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \
+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m $( [ -f "$SRC"/Redesigned/Lyrics/LyricsText.m ] && echo "$SRC"/Redesigned/Lyrics/LyricsText.m ) "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \
"$SRC"/Shared/LyricsSources/SGTTML.m "$SRC"/Redesigned/Kit/SGRTokens.m \
$( [ -f "$SRC"/Shared/LyricsMeanings/Meanings.m ] && echo "$SRC"/Shared/LyricsMeanings/Meanings.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m ) \
"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGGlass.m \
diff --git a/harness/now-playing/build.sh b/harness/now-playing/build.sh
index b14fdf0e..2782436e 100755
--- a/harness/now-playing/build.sh
+++ b/harness/now-playing/build.sh
@@ -18,7 +18,7 @@ SDK=$(xcrun --sdk macosx --show-sdk-path)
xcrun clang -target arm64-apple-ios18.0-macabi -isysroot "$SDK" -iframework "$SDK/System/iOSSupport/System/Library/Frameworks" \
-fobjc-arc -g -O0 -Wall -I"$SRC" -I"$SRC/Shared/LockScreenLyrics" \
"$(dirname "$0")/main.m" "$OUT/gen/LockScreenLyrics.m" "$OUT/gen/NowPlayingExtras.m" \
- "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/Lyrics/Protobuf.m" \
+ "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \
-framework UIKit -framework MediaPlayer -o "$OUT/now-playing"
"$OUT/now-playing"
diff --git a/harness/player/build.sh b/harness/player/build.sh
index 09c0c5c4..90afe3f8 100755
--- a/harness/player/build.sh
+++ b/harness/player/build.sh
@@ -22,7 +22,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
- "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/SGRSingButton.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \
+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/SGRSingButton.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \
-o "$OUT/PlayerHarness.app/PlayerHarness"
diff --git a/harness/spicy-lyrics/build.sh b/harness/spicy-lyrics/build.sh
index d67a2fbf..fc5e02a2 100755
--- a/harness/spicy-lyrics/build.sh
+++ b/harness/spicy-lyrics/build.sh
@@ -6,6 +6,6 @@ HERE=$(cd "$(dirname "$0")" && pwd)
SRC=$(cd "$HERE/../../tweak/Sources" && pwd)
mkdir -p "$HERE/build"
xcrun -sdk macosx clang -target arm64-apple-ios17.0-macabi -isysroot "$(xcrun --sdk macosx --show-sdk-path)" -iframework "$(xcrun --sdk macosx --show-sdk-path)/System/iOSSupport/System/Library/Frameworks" -fobjc-arc -g -Wall -I"$SRC" \
- "$HERE/check.m" "$SRC/Shared/LyricsSources/SpicyLyrics.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/Lyrics/Protobuf.m" \
+ "$HERE/check.m" "$SRC/Shared/LyricsSources/SpicyLyrics.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \
-framework UIKit -framework Security -framework Foundation -o "$HERE/build/check"
"$HERE/build/check"
diff --git a/tweak/Sources/App/About/Licenses.m b/tweak/Sources/App/About/Licenses.m
index 6ed46ede..653c6bbb 100644
--- a/tweak/Sources/App/About/Licenses.m
+++ b/tweak/Sources/App/About/Licenses.m
@@ -33,12 +33,19 @@ UIViewController *SGLicensesPage(void) {
SGModRow *mod = SGLinkRow(@"Vitrine", @"GNU General Public License v3.0", @"https://www.gnu.org/licenses/gpl-3.0.html");
SGModRow *bs2b = SGLinkRow(@"libbs2b", @"Crossfeed · MIT License", @"https://github.com/alexmarsev/libbs2b");
SGModRow *wdl = SGLinkRow(@"WDL", @"Liveprog's EEL2 · zlib License", @"https://github.com/justinfrankel/WDL");
+ // EeveeSpotify's repo was taken down, so the row opens the license both projects are under.
+ SGModRow *eevee = SGLinkRow(@"EeveeSpotify", @"Ads, upsells, Spoof Premium · GNU GPL v3.0", @"https://www.gnu.org/licenses/gpl-3.0.html");
// Not shipped: the Headphones page downloads its results when asked, but they are AutoEq's work all the same.
SGModRow *autoEq = SGLinkRow(@"AutoEq", @"Headphone corrections · MIT License", @"https://github.com/jaakkopasanen/AutoEq");
// Sing's voice model is downloaded rather than built in, and its NOTICE travels with it here all the same.
SGModRow *voice = SGLinkRow(@"Sing's voice model", @"Mel-Band RoFormer · MIT License", @"https://huggingface.co/My-Name-Is-Jeff/vitrine-sing");
return [[SGModPage alloc] initWithTitle:@"Licenses" intro:@"The mod's own license, and the code from others it includes." sections:@[
SGSection(nil, @[mod]),
+ SGNotedSection(nil, @[eevee], @"By whoeevee (whoeevee/EeveeSpotify), under the GNU General Public License v3.0, as Vitrine is.\n\n"
+ @"Ported from it, on the Premium, ads & privacy page: Hide ads (the ad services kept from starting, "
+ @"ad components taken out of Home and Search, ad sections out of the feeds, ad requests answered empty), "
+ @"Hide upsells (the Premium pop-ups, and the ad and upsell flags it turns off) and Spoof Premium "
+ @"(the account attributes and flag rules it rewrites, and crossfade under it)."),
SGNotedSection(nil, @[bs2b], [@"Copyright (c) 2005 Boris Mikhaylov\n\n" stringByAppendingString:kMIT]),
SGNotedSection(nil, @[wdl], [@"Copyright (C) 2004-2013 Cockos Incorporated\nCopyright (C) 1999-2003 Nullsoft, Inc.\n\n"
stringByAppendingString:kZlib]),
diff --git a/tweak/Sources/App/ModSettings.x b/tweak/Sources/App/ModSettings.x
index f9704e65..b8c6f496 100644
--- a/tweak/Sources/App/ModSettings.x
+++ b/tweak/Sources/App/ModSettings.x
@@ -1,7 +1,7 @@
// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own page: the
// Appearance card with Redesigned UI, then a page per part of Spotify, each holding what that part
// offers in the stored look (App/Pages.m: Navbar, Player, and Home & Library for the native look), Audio
-// effects (Shared/AudioEffects, in either look and applying straight away), Privacy & clutter
+// effects (Shared/AudioEffects, in either look and applying straight away), Premium, ads & privacy
// and Labs, All flags, a searchable list of every flag with an override per flag, and Mod, the
// build, its updates and links. The same row leads the side drawer's list (trees/test6.txt), above
// Your plan, so the page is a tap from Home, and holding Home on the tab bar opens it too. The tweaks read the switches when they run, so a change
@@ -17,7 +17,7 @@
#import "Settings/SGPageStyle.h"
#import "Settings/SGModPage.h"
#import "Native/Home/Home.h"
-#import "Shared/Privacy/Privacy.h"
+#import "Shared/AdBlock/AdBlock.h"
#import "Shared/Flags/Flags.h"
#import "Shared/AudioEffects/AudioEffectsPage.h"
#import "Shared/LiveActivity/LiveActivity.h"
@@ -72,7 +72,7 @@ static UIViewController *modSettingsPage(void) {
SGAppearanceSection(),
SGSection(nil, parts),
SGSection(nil, @[
- pageRow(@"Privacy & clutter", @"hand.raised", ^UIViewController *{ return SGPrivacySettingsPage(); }),
+ pageRow(@"Premium, ads & privacy", @"crown", ^UIViewController *{ return SGAdsSettingsPage(); }),
pageRow(@"Labs", @"testtube.2", ^UIViewController *{ return SGLabsPage(); }),
]),
SGSection(nil, @[
diff --git a/tweak/Sources/Core/SGFlagForce.h b/tweak/Sources/Core/SGFlagForce.h
index 86d95a1e..3780048c 100644
--- a/tweak/Sources/Core/SGFlagForce.h
+++ b/tweak/Sources/Core/SGFlagForce.h
@@ -1,6 +1,6 @@
// The flags something of the mod's forces, gathered in one place so that the flag provider
// (Shared/Flags/Flags.x) and the flag rows of the settings pages (Settings/SGModPage.m) ask here
-// rather than knowing every feature that forces one: the Search switches, the lyrics sources, the redesign.
+// rather than knowing every feature that forces one: the ad blocking, the lyrics sources, the redesign.
//
// A forcer answers a flag key with the value it forces, or nil. `atLaunch` answers for the running
// app, from the switches as they were at launch; `locked`, which may be nil, answers for a settings
diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.m
index a99dfd36..07114cdd 100644
--- a/tweak/Sources/Settings/SGModPage.m
+++ b/tweak/Sources/Settings/SGModPage.m
@@ -257,7 +257,7 @@ static BOOL flagRowOn(SGModRow *row) {
return value && [value boolValue] != row.forceOff;
}
-// A flag something of the mod's forces (Core/SGFlagForce.h: the redesign, the Search switches): its row
+// A flag something of the mod's forces (Core/SGFlagForce.h: the redesign, the ad blocking): its row
// shows what is forced and takes no touch, so the flag has one place to change.
static BOOL flagRowLocked(SGModRow *row) {
return row.flag && SGLockedFlagValue(row.key, NULL) != nil;
diff --git a/tweak/Sources/Shared/AdBlock/AdBlock.h b/tweak/Sources/Shared/AdBlock/AdBlock.h
new file mode 100644
index 00000000..66d17a8d
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdBlock.h
@@ -0,0 +1,38 @@
+// EeveeSpotify's layers, ported, at the top of the Premium, ads & privacy page. Three switches, each off until asked for. Hide ads
+// keeps the ad services from starting (AdServices.x), takes ad components out of Home and Search
+// before they render (AdHubs.x, Feeds.m) and answers the requests behind them empty (AdNetwork.x).
+// Hide upsells drops the Premium prompts (AdPopups.x, AdServices.x) and forces the flags that show
+// them off (AdBlock.m, through Flags.x). Spoof Premium rewrites the product state and remote
+// config as they arrive (Premium.m), crossfade and automix included (Crossfade.x), and keeps the
+// session alive when the server disagrees (AdNetwork.x). Hide the video carousel in Search forces its
+// flag off (AdBlock.m, through Flags.x).
+#import <UIKit/UIKit.h>
+
+#define SGKeyHideAds @"spotifyglass.adblock.ads"
+#define SGKeyHideUpsells @"spotifyglass.adblock.upsells"
+#define SGKeyFakePremium @"spotifyglass.adblock.premium"
+#define SGKeyHideSearchVideos @"spotifyglass.adblock.searchVideos"
+
+// What a switch turning Spoof Premium on is told first.
+extern NSString *const SGFakePremiumWarning;
+
+// A flag the ads or upsells switch forces off while it is on. Flags.x asks, and the row for it locks.
+BOOL SGAdBlockForcesFlagOff(NSString *key);
+
+// What the hooks stopped, by kind, for the counts under the switches (nil label for all of them).
+void SGAdBlockCountOne(NSString *label);
+NSArray<NSString *> *SGAdBlockLabels(void);
+NSUInteger SGAdBlockCount(NSString *label);
+void SGResetAdBlock(void);
+
+// Premium.m: the body of v1/customize, or the bootstrap message that wraps one, rewritten to a
+// Premium account's. nil when the bytes do not parse.
+NSData *SGPatchCustomize(NSData *body);
+NSData *SGPatchBootstrap(NSData *body);
+
+// Feeds.m: a browsita, casita or scrollsita feed with its ad sections taken out; nil when there
+// were none, or the bytes were not the shape expected.
+NSData *SGStripFeed(NSData *body);
+
+// The Premium, ads & privacy page: these switches, the ad flags they lock, telemetry, the counters.
+UIViewController *SGAdsSettingsPage(void);
diff --git a/tweak/Sources/Shared/AdBlock/AdBlock.m b/tweak/Sources/Shared/AdBlock/AdBlock.m
new file mode 100644
index 00000000..feceea5c
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdBlock.m
@@ -0,0 +1,104 @@
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+#pragma mark - flags
+
+// Both lists are EeveeSpotify's, kept to the flags this Spotify has.
+static NSString *const adFlags[] = {
+ @"ios-feature-adonappopen.enabled",
+ @"ios-feature-adonappopen.cta_card_enabled",
+ @"ios-nowplaying-scroll-impl.unified_leavebehind_npv_scroll_music_enabled",
+ @"ios-nowplaying-scroll-impl.unified_leavebehind_npv_scroll_podcast_enabled",
+ @"ios-feature-embeddedplaylist.use_unified_leavebehind_fetch",
+ @"ios-adsnowplaying-embeddednpv-impl.foreground_enabled",
+ @"ios-adsnowplaying-embeddednpv-impl.music_track_change_enabled",
+ @"ios-adsnowplaying-embeddednpv-impl.enable_ads_on_podcast",
+ @"ios-feature-adsbase.enable_ads_connect_state_observer",
+ @"ios-feature-adsbase.enable_minimal_preroll_management",
+ @"ios-feature-adsnowplayingui.embedded_npv_video_show_with_canvas",
+ @"ios-feature-adssponsoredcontext.sponsored_playlist_v2_enabled",
+ @"ios-feature-adssponsoredcontext.sponsored_context_mismatch_aderror_enabled",
+ @"ios-feature-adssponsoredcontextnpbattachment.sponsored_npb_slot_fetch_enabled",
+};
+
+static NSString *const upsellFlags[] = {
+ @"ios-feature-shuffletoggleupsell.is_enabled_pt2",
+ @"ios-feature-shuffletoggleupsell.linear_upsell_new_style_experiment_enabled",
+ @"ios-feature-shuffletoggleupsell.play_modes_upsell_new_style_experiment_enabled",
+ @"ios-feature-nowplaying-modes.video_first_shuffle_upsell_enabled",
+ @"ios-jam-freeusershuffleupsellsheetpage-impl.free_user_shuffle_upsell_sheet_enabled",
+ @"ios-jam-freeuserskipupsellpage-impl.free_user_skip_upsell_sheet_enabled",
+ @"ios-jam-freehostedjamsupsell-impl.free_hosted_jams_upsell_enabled",
+ @"ios-reinventfree-contextualupsellpremiumpromo-impl.is_promo_cta_enabled",
+ @"ios-reinventfree-contextualupsellpremiumpromo-impl.show_time_cap_upsell_with_premium_badge",
+ @"ios-reinventfree-controllerui-impl.enable_video_time_cap_upsell",
+ @"ios-reinventfree-controllerui-impl.enable_video_time_cap_upsell_on_search",
+ @"ios-reinventfree-timecappivot-impl.music_video_upsell_enabled",
+ @"ios-settings-mediaqualitypageplugin-impl.is_gbb_upsell_enabled",
+ @"ios-settings-mediaqualitypageplugin-impl.should_show_pigeon_upsell",
+ @"ios-system-listeningparties.preview_ended_upsell_enabled",
+};
+
+static BOOL listed(NSString *key, NSString *const list[], size_t count) {
+ for (size_t i = 0; i < count; i++) {
+ if ([key isEqualToString:list[i]]) return YES;
+ }
+ return NO;
+}
+
+BOOL SGAdBlockForcesFlagOff(NSString *key) {
+ if (SGHidden(SGKeyHideAds) && listed(key, adFlags, sizeof(adFlags) / sizeof(adFlags[0]))) return YES;
+ if (SGHidden(SGKeyHideSearchVideos) && [key isEqualToString:@"ios-feature-search.video_carousel_section_enabled"]) return YES;
+ return SGHidden(SGKeyHideUpsells) && listed(key, upsellFlags, sizeof(upsellFlags) / sizeof(upsellFlags[0]));
+}
+
+// After an override from the All flags page, and locking the rows that would turn the same flag off.
+__attribute__((constructor)) static void registerForcer(void) {
+ SGFlagForcer off = ^id(NSString *key) { return SGAdBlockForcesFlagOff(key) ? @NO : nil; };
+ SGRegisterFlagForcer(NO, off, off);
+}
+
+#pragma mark - counters
+
+static NSString *const kCounts = @"spotifyglass.adblock.counts";
+static NSString *const labels[] = {
+ @"Ad services", @"Upsell services", @"Popups", @"Page components", @"Feed sections", @"Requests", @"Config rewrites",
+};
+static NSMutableDictionary<NSString *, NSNumber *> *sg_counts;
+
+// Counting happens on whichever thread the hook ran on, the page reads on the main one.
+static NSMutableDictionary<NSString *, NSNumber *> *countsLocked(void) {
+ if (!sg_counts) {
+ sg_counts = [[NSUserDefaults.standardUserDefaults dictionaryForKey:kCounts] mutableCopy] ?: [NSMutableDictionary dictionary];
+ }
+ return sg_counts;
+}
+
+void SGAdBlockCountOne(NSString *label) {
+ @synchronized (kCounts) {
+ NSMutableDictionary<NSString *, NSNumber *> *counts = countsLocked();
+ counts[label] = @(counts[label].unsignedIntegerValue + 1);
+ [NSUserDefaults.standardUserDefaults setObject:counts forKey:kCounts];
+ }
+}
+
+NSArray<NSString *> *SGAdBlockLabels(void) {
+ return [NSArray arrayWithObjects:labels count:sizeof(labels) / sizeof(labels[0])];
+}
+
+NSUInteger SGAdBlockCount(NSString *label) {
+ @synchronized (kCounts) {
+ NSDictionary<NSString *, NSNumber *> *counts = countsLocked();
+ if (label) return counts[label].unsignedIntegerValue;
+ NSUInteger total = 0;
+ for (NSNumber *count in counts.allValues) total += count.unsignedIntegerValue;
+ return total;
+ }
+}
+
+void SGResetAdBlock(void) {
+ @synchronized (kCounts) {
+ sg_counts = [NSMutableDictionary dictionary];
+ [NSUserDefaults.standardUserDefaults removeObjectForKey:kCounts];
+ }
+}
diff --git a/tweak/Sources/Shared/AdBlock/AdBlockSettings.m b/tweak/Sources/Shared/AdBlock/AdBlockSettings.m
new file mode 100644
index 00000000..1d25660f
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdBlockSettings.m
@@ -0,0 +1,71 @@
+#import "Core/SGCore.h"
+#import "Settings/SGModPage.h"
+#import "AdBlock.h"
+#import "Shared/Privacy/Privacy.h"
+
+NSString *const SGFakePremiumWarning = @"This is the part of EeveeSpotify Spotify's takedown went after, and it has not been tested here. It can end in a forced logout or worse for the account. A Premium account gains nothing from it.";
+
+// Every switch here forces a flag Spotify ships on to off, so the titles name the blocking: on stops
+// the thing, off is Spotify's own value. Hide ads and Hide upsells already force the first two
+// sections off, which locks those rows.
+static UIViewController *adFlagsPage(void) {
+ return [[SGModPage alloc] initWithTitle:@"Ad and upsell flags" intro:SGRestartNote sections:@[
+ SGNotedSection(@"Ads", @[
+ SGKillRow(@"Block the ad when the app opens", @"ios-feature-adonappopen.enabled"),
+ SGKillRow(@"Block its CTA card", @"ios-feature-adonappopen.cta_card_enabled"),
+ ], @"Locked while Hide ads is on."),
+ SGNotedSection(@"Upsells", @[
+ SGKillRow(@"Hide the shuffle toggle upsell", @"ios-feature-shuffletoggleupsell.is_enabled_pt2"),
+ SGKillRow(@"Hide the shuffle upsell in the video player", @"ios-feature-nowplaying-modes.video_first_shuffle_upsell_enabled"),
+ ], @"Locked while Hide upsells is on."),
+ SGSection(@"Reduce interventions", @[
+ SGFlagRow(@"Reduce interventions", @"ios-messaging-reduceinterventions-impl.enabled"),
+ ]),
+ SGSection(@"Tooltips", @[
+ SGKillRow(@"Hide the smart shuffle helper", @"ios-messaging-reduceinterventions-impl.enable_message_smart_shuffle_helper_tooltip"),
+ SGKillRow(@"Hide the data saver tip", @"ios-feature-nowplayingbar.data_saver_tooltip"),
+ SGKillRow(@"Hide the player suggestions upsell", @"ios-messaging-reduceinterventions-impl.enable_message_reinvent_free_n_p_v_suggestions_upsell"),
+ SGKillRow(@"Hide the AI playlist creation tip", @"ios-messaging-reduceinterventions-impl.enable_message_your_library_ai_playlist_creation_tooltip"),
+ SGKillRow(@"Hide the watch feed explorer tip", @"ios-messaging-reduceinterventions-impl.enable_message_watch_feed_entity_explorer_tooltip"),
+ SGKillRow(@"Hide the account switching tip", @"ios-messaging-reduceinterventions-impl.enable_message_account_switching_tooltip"),
+ SGKillRow(@"Hide the concert notifications tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_concert_notifications_tooltip"),
+ SGKillRow(@"Hide the live event tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_safe_tooltip"),
+ SGKillRow(@"Hide the live event venue tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_venuename_header_tooltip"),
+ SGKillRow(@"Hide the Puffin nudge", @"ios-messaging-reduceinterventions-impl.enable_message_puffin_nudge_end_optimization"),
+ ]),
+ ] footer:nil];
+}
+
+// The switches first and what they have stopped last, so the counters bury no setting.
+UIViewController *SGAdsSettingsPage(void) {
+ NSMutableArray<SGModRow *> *counts = [NSMutableArray array];
+ for (NSString *label in SGAdBlockLabels()) {
+ [counts addObject:SGStatRow(label, ^NSString *{
+ return @(SGAdBlockCount(label)).stringValue;
+ })];
+ }
+ [counts addObject:SGStatRow(@"Total", ^NSString *{
+ return @(SGAdBlockCount(nil)).stringValue;
+ })];
+ [counts addObject:SGActionRow(@"Reset the counters", nil, ^{ SGResetAdBlock(); })];
+
+ SGModRow *fakePremium = SGOptionRow(@"Spoof Premium", nil, SGKeyFakePremium);
+ fakePremium.warning = SGFakePremiumWarning;
+
+ // The redesign's Search keeps only its category cards, so the video carousel switch is the native look's.
+ NSMutableArray<SGModRow *> *ads = [NSMutableArray arrayWithObjects:
+ SGWithSymbol(SGOptionRow(@"Hide ads", nil, SGKeyHideAds), @"speaker.slash"),
+ SGWithSymbol(SGOptionRow(@"Hide upsells", nil, SGKeyHideUpsells), @"hand.raised"), nil];
+ if (!SGRedesignedUIStored()) [ads addObject:SGWithSymbol(SGOptionRow(@"Hide the video carousel in Search", nil, SGKeyHideSearchVideos), @"play.rectangle.on.rectangle")];
+ [ads addObject:SGWithSymbol(SGPageRow(@"Ad and upsell flags", ^UIViewController *{ return adFlagsPage(); }), @"flag")];
+
+ return [[SGModPage alloc] initWithTitle:@"Premium, ads & privacy" intro:SGRestartNote sections:@[
+ SGNotedSection(@"Ads", ads, @"Audio ads between songs need Spoof Premium."),
+ SGNotedSection(@"Premium", @[
+ SGWithSymbol(fakePremium, @"crown"),
+ ], @"Free accounts only."),
+ SGPrivacySection(),
+ SGSection(@"Ads blocked so far", counts),
+ SGPrivacyCountersSection(),
+ ] footer:nil];
+}
diff --git a/tweak/Sources/Shared/AdBlock/AdHubs.x b/tweak/Sources/Shared/AdBlock/AdHubs.x
new file mode 100644
index 00000000..b9dbda1c
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdHubs.x
@@ -0,0 +1,120 @@
+// Ad components taken out of the Hub JSON Home, Browse and Search pages are built from, before
+// the builder renders them (EeveeSpotify's HubsAdBlocker). A component is an ad when its
+// namespace, name, id, type or the keys of its metadata, logging or custom dictionaries say so;
+// its title never counts, "Billboard Hot 100" is a playlist. The plain ad words go with the ads
+// switch, a promotion word next to a surface word with the upsells one.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+// Bare "ad" and "ads" are absent on purpose: as substrings they hit made-for-you and release-radar.
+static NSString *const adWords[] = {
+ @"sponsored", @"upsell", @"campaign", @"promoted", @"premium-upsell", @"billboard", @"interstitial", @"marquee",
+ @"leavebehind", @"leave-behind", @"displayad", @"display-ad", @"fullbleed", @"full-bleed", @"leaderboard",
+ @"advertisement", @"sponsor", @"native-ad", @"mobile-ads", @"on-surface", @"onsurface", @"search-ad", @"home-ad",
+ @"sponsored-content", @"sponsored-ad", @"ad-card", @"native-ad-home-shelf", @"sponsored-shelf", @"sponsored-row",
+ @"ad-shelf", @"ad-row", @"sponsored-item", @"ad-item", @"upgrade-component", @"mobile-display-ad-card",
+ @"mobile-ads-display-ad-element",
+};
+static NSString *const intentWords[] = {@"premium", @"upgrade", @"offer", @"marketing", @"promo", @"promotion", @"subscribe", @"subscription"};
+static NSString *const surfaceWords[] = {@"banner", @"card", @"popup", @"pop-up", @"sheet", @"overlay", @"component", @"message"};
+
+#define COUNT(list) (sizeof(list) / sizeof(list[0]))
+
+static BOOL ads, upsells;
+
+static BOOL containsAny(NSString *text, NSString *const words[], size_t count) {
+ for (size_t i = 0; i < count; i++) {
+ if ([text containsString:words[i]]) return YES;
+ }
+ return NO;
+}
+
+static BOOL adWord(NSString *text) {
+ if (![text isKindOfClass:NSString.class]) return NO;
+ text = text.lowercaseString;
+ if (ads && containsAny(text, adWords, COUNT(adWords))) return YES;
+ return upsells && containsAny(text, intentWords, COUNT(intentWords)) && containsAny(text, surfaceWords, COUNT(surfaceWords));
+}
+
+static BOOL anyKey(NSDictionary *dictionary) {
+ if (![dictionary isKindOfClass:NSDictionary.class]) return NO;
+ for (NSString *key in dictionary) {
+ if (adWord(key)) return YES;
+ }
+ return NO;
+}
+
+static BOOL isAd(NSDictionary *component) {
+ id kind = component[@"component"];
+ if ([kind isKindOfClass:NSDictionary.class]) {
+ NSString *ns = kind[@"namespace"], *name = kind[@"name"];
+ if (adWord(ns) || adWord(name) || adWord([NSString stringWithFormat:@"%@:%@", ns, name])) return YES;
+ } else if (adWord(kind)) {
+ return YES;
+ }
+ if (adWord(component[@"id"]) || adWord(component[@"type"])) return YES;
+ NSDictionary *metadata = component[@"metadata"];
+ if ([metadata isKindOfClass:NSDictionary.class]) {
+ for (NSString *key in @[@"ad", @"is_ad", @"is_sponsored"]) {
+ if ([metadata[key] respondsToSelector:@selector(boolValue)] && [metadata[key] boolValue]) return YES;
+ }
+ }
+ if (anyKey(metadata) || anyKey(component[@"custom"])) return YES;
+ NSDictionary *logging = component[@"logging"];
+ return [logging isKindOfClass:NSDictionary.class] && (adWord(logging[@"type"]) || anyKey(logging));
+}
+
+static NSArray *filtered(NSArray *components) {
+ if (![components isKindOfClass:NSArray.class]) return components;
+ NSMutableArray *kept = [NSMutableArray array];
+ for (NSDictionary *component in components) {
+ if (![component isKindOfClass:NSDictionary.class]) {
+ [kept addObject:component];
+ continue;
+ }
+ if (isAd(component)) {
+ SGAdBlockCountOne(@"Page components");
+ SGLog(@"dropped page component %@", component[@"id"] ?: component[@"component"]);
+ continue;
+ }
+ NSMutableDictionary *copy = [component mutableCopy];
+ for (NSString *key in @[@"children", @"rows", @"body"]) {
+ if (copy[key]) copy[key] = filtered(copy[key]);
+ }
+ [kept addObject:copy];
+ }
+ return kept;
+}
+
+%hook HUBViewModelBuilderImplementation
+- (void)addJSONDictionary:(NSDictionary *)dictionary {
+ if (![dictionary isKindOfClass:NSDictionary.class]) {
+ %orig;
+ return;
+ }
+ NSMutableDictionary *copy = [dictionary mutableCopy];
+ for (NSString *key in @[@"body", @"overlays", @"sections"]) {
+ if (copy[key]) copy[key] = filtered(copy[key]);
+ }
+ NSDictionary *header = copy[@"header"];
+ if ([header isKindOfClass:NSDictionary.class]) {
+ if (isAd(header)) {
+ SGAdBlockCountOne(@"Page components");
+ [copy removeObjectForKey:@"header"];
+ } else if (header[@"children"]) {
+ NSMutableDictionary *headerCopy = [header mutableCopy];
+ headerCopy[@"children"] = filtered(header[@"children"]);
+ copy[@"header"] = headerCopy;
+ }
+ }
+ %orig(copy);
+}
+%end
+
+%ctor {
+ ads = SGHidden(SGKeyHideAds);
+ upsells = SGHidden(SGKeyHideUpsells);
+ if (!ads && !upsells) return;
+ %init;
+ SGRequireClasses(@[@"HUBViewModelBuilderImplementation"]);
+}
diff --git a/tweak/Sources/Shared/AdBlock/AdNetwork.x b/tweak/Sources/Shared/AdBlock/AdNetwork.x
new file mode 100644
index 00000000..1af3d3cc
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdNetwork.x
@@ -0,0 +1,291 @@
+// Spotify's responses on their way in, through the URLSession delegates it reads them by:
+// SPTDataLoaderService for most of spclient, HttpClientURLSession for what some regions route the
+// other way. A request for an ad is answered empty. With Spoof Premium on, the bootstrap
+// and customize bodies are rewritten by Premium.m before the client sees them, the endpoints the
+// server would use to log the account out are answered as if they succeeded, and past the first
+// thirty seconds the re-fetches that could bring the real state back are cancelled before they
+// leave. Feeds go through Feeds.m. Everything here is EeveeSpotify's, less its Ably hooks, which
+// it does not turn on for 9.1 either.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+static BOOL ads, premium;
+static NSDate *started;
+static NSObject *cacheLock;
+static NSData *cachedCustomize; // the last rewritten customize body, for a 304 and the re-fetches
+static char kBufferKey, kServedKey, kPassKey;
+
+typedef NS_ENUM(NSInteger, SGNet) { SGNetPass, SGNetBlock, SGNetPatch };
+
+static NSTimeInterval elapsed(void) {
+ return -started.timeIntervalSinceNow;
+}
+
+static BOOL has(NSString *text, NSString *needle) {
+ return [text containsString:needle];
+}
+
+static BOOL isBootstrap(NSString *path) { return has(path, @"v1/bootstrap"); }
+static BOOL isCustomize(NSString *path) { return has(path, @"v1/customize"); }
+
+// The feeds Home, Search and the page under the player are built from. casita/v1/feeds is the flat
+// list of tab chips, not sections.
+static BOOL isFeed(NSString *path) {
+ if (has(path, @"/casita/v1/feeds")) return NO;
+ return has(path, @"/browsita/") || has(path, @"/casita/") || has(path, @"/scrollsita/");
+}
+
+static BOOL isLogout(NSString *path) {
+ return has(path, @"logout") || has(path, @"sign-out") || has(path, @"session/purge") || has(path, @"token/revoke")
+ || has(path, @"auth/expire") || (has(path, @"melody") && has(path, @"check")) || has(path, @"product-state")
+ || (has(path, @"license") && has(path, @"check")) || has(path, @"deletetoken");
+}
+
+static NSString *const adPaths[] = {
+ @"/ads/", @"/ad-logic/", @"/dac/view/v1/", @"/ad-slot/", @"/ad-inventory/", @"/ad-on-app-open", @"/sponsored/",
+ @"/promoted/", @"/upsell/", @"/premium-upsell", @"/upsell-banner", @"/upsell-card", @"/referrals/upsell",
+ @"/campaign/", @"/billboard/", @"/banner/", @"/interstitial/", @"/overlay/", @"/popup/", @"/pop-up/",
+ @"/search-ad/", @"/home-ad/", @"/marquee/", @"/leavebehind", @"/leave-behind", @"/display-ad/", @"/fullbleed/",
+ @"/leaderboard/", @"/ad-card/", @"/sponsored-content/", @"/sponsored-ad/", @"/native-ad/", @"/sponsored-shelf/",
+ @"/sponsored-row/", @"/ad-shelf/", @"/ad-row/", @"/sponsored-item/", @"/ad-item/", @"/merchandising/",
+ @"/upgrade-component/", @"/marketing/", @"/home-ads/", @"/search-ads/",
+};
+
+static BOOL isAd(NSURL *url, NSString *path) {
+ for (size_t i = 0; i < sizeof(adPaths) / sizeof(adPaths[0]); i++) {
+ if (has(path, adPaths[i])) return YES;
+ }
+ if (has(path, @"/esperanto/") && (has(path, @"ad") || has(path, @"slot"))) return YES;
+ NSString *host = url.host.lowercaseString ?: @"";
+ return has(host, @"doubleclick") || has(host, @"googlesyndication") || [host hasPrefix:@"aet."]
+ || [@[@"ad.spotify.com", @"ads.spotify.com", @"aet.spotify.com"] containsObject:host];
+}
+
+// The first thirty seconds are a fresh login's: signup/public and customize are part of it, and
+// answering them broke first launch.
+static BOOL isRefetch(NSString *path) {
+ return has(path, @"signup/public") || has(path, @"select-ondemand-set") || has(path, @"trials-facade/start-trial")
+ || has(path, @"premium-marketing/upselloffer") || (has(path, @"pendragon") && has(path, @"fetchmessagelist"))
+ || has(path, @"pushka-tokens") || has(path, @"apresolve") || has(path, @"pses/screenconfig") || isCustomize(path);
+}
+
+static SGNet classify(NSURL *url) {
+ NSString *path = url.path.lowercaseString ?: @"";
+ if (premium && isLogout(path)) return SGNetBlock;
+ if (ads && isAd(url, path)) return SGNetBlock;
+ if (premium && elapsed() > 30 && isRefetch(path)) return SGNetBlock;
+ if (premium && (isBootstrap(path) || isCustomize(path))) return SGNetPatch;
+ if (ads && isFeed(path)) return SGNetPatch;
+ return SGNetPass;
+}
+
+static NSData *cached(void) {
+ @synchronized (cacheLock) { return cachedCustomize; }
+}
+
+static NSData *json(NSString *text) {
+ return [text dataUsingEncoding:NSUTF8StringEncoding];
+}
+
+// The body a blocked request is answered with: what its reader parses for, so that nothing is
+// retried and no logout path taken.
+static NSData *blockedReply(NSString *path) {
+ if (has(path, @"signup/public")) return json(@"{\"status\":1,\"country\":\"US\",\"is_country_launched\":true}");
+ if (has(path, @"trials-facade")) return json(@"{\"result\":\"NOT_ELIGIBLE\"}");
+ if (has(path, @"premium-marketing") || has(path, @"pses/screenconfig")) return json(@"{}");
+ if (isLogout(path) || has(path, @"apresolve")) return json(@"{\"status\":\"OK\"}");
+ if (isCustomize(path) && cached()) return cached();
+ return [NSData data];
+}
+
+static NSData *patched(NSURL *url, NSData *body) {
+ NSString *path = url.path.lowercaseString ?: @"";
+ if (isFeed(path)) return SGStripFeed(body);
+ NSData *result = isBootstrap(path) ? SGPatchBootstrap(body) : SGPatchCustomize(body);
+ if (!result) {
+ SGLog(@"could not rewrite %@, passed through", path);
+ return nil;
+ }
+ if (isCustomize(path)) {
+ @synchronized (cacheLock) { cachedCustomize = result; }
+ }
+ SGAdBlockCountOne(@"Config rewrites");
+ SGLog(@"rewrote %@, %lu -> %lu bytes", path, (unsigned long)body.length, (unsigned long)result.length);
+ return result;
+}
+
+#pragma mark - the delegate's three calls
+
+// Data handed to the delegate by the mod goes through its hooked didReceiveData like Spotify's own,
+// with the pass mark on the task so the hook lets it by.
+static void deliver(id<NSURLSessionDataDelegate> delegate, NSURLSession *session, NSURLSessionTask *task, NSData *data) {
+ objc_setAssociatedObject(task, &kPassKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ [delegate URLSession:session dataTask:(NSURLSessionDataTask *)task didReceiveData:data];
+ objc_setAssociatedObject(task, &kPassKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+// A customize the server says has not changed, answered with the rewritten one from last time.
+static NSHTTPURLResponse *replayFor(NSURLSessionTask *task, NSURLResponse *response) {
+ if (!premium || ![response isKindOfClass:NSHTTPURLResponse.class] || ((NSHTTPURLResponse *)response).statusCode != 304) return nil;
+ NSURL *url = task.currentRequest.URL;
+ if (!isCustomize(url.path.lowercaseString ?: @"") || !cached()) return nil;
+ objc_setAssociatedObject(task, &kServedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return [[NSHTTPURLResponse alloc] initWithURL:url statusCode:200 HTTPVersion:@"HTTP/2.0" headerFields:@{}];
+}
+
+// YES when the data is not the delegate's to see yet: dropped for a blocked request, kept back for
+// one whose reply is rewritten when it finishes.
+static BOOL holds(NSURLSessionTask *task, NSData *data) {
+ if (objc_getAssociatedObject(task, &kPassKey)) return NO;
+ switch (classify(task.currentRequest.URL)) {
+ case SGNetBlock:
+ return YES;
+ case SGNetPatch: {
+ NSMutableData *buffer = objc_getAssociatedObject(task, &kBufferKey);
+ if (!buffer) objc_setAssociatedObject(task, &kBufferKey, (buffer = [NSMutableData data]), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ [buffer appendData:data];
+ return YES;
+ }
+ default:
+ return NO;
+ }
+}
+
+static void complete(id<NSURLSessionDataDelegate> delegate, NSURLSession *session, NSURLSessionTask *task, NSError *error, void (^finish)(NSError *)) {
+ NSURL *url = task.currentRequest.URL;
+ NSString *path = url.path.lowercaseString ?: @"";
+ NSMutableData *buffer = objc_getAssociatedObject(task, &kBufferKey);
+ objc_setAssociatedObject(task, &kBufferKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ if (objc_getAssociatedObject(task, &kServedKey)) {
+ finish(nil);
+ return;
+ }
+ switch (classify(url)) {
+ case SGNetBlock:
+ SGAdBlockCountOne(@"Requests");
+ SGLog(@"answered %@ empty", path);
+ deliver(delegate, session, task, blockedReply(path));
+ finish(nil);
+ return;
+ case SGNetPatch:
+ if (error) {
+ finish(error);
+ return;
+ }
+ // Nothing to rewrite: a 304, or a body of no bytes. The delegate is told of a body either
+ // way, since a completion with none hangs some readers.
+ if (!buffer) {
+ deliver(delegate, session, task, (isCustomize(path) ? cached() : nil) ?: [NSData data]);
+ finish(nil);
+ return;
+ }
+ deliver(delegate, session, task, patched(url, buffer) ?: buffer);
+ finish(nil);
+ return;
+ default:
+ finish(error);
+ }
+}
+
+%hook SPTDataLoaderService
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))handler {
+ NSHTTPURLResponse *replay = replayFor(task, response);
+ %orig(session, task, replay ?: response, handler);
+ if (replay) deliver((id)self, session, task, cached());
+}
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveData:(NSData *)data {
+ if (!holds(task, data)) %orig;
+}
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
+ complete((id)self, session, task, error, ^(NSError *passed) { %orig(session, task, passed); });
+}
+%end
+
+%hook _TtC26Connectivity_HttpClientKit20HttpClientURLSession
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))handler {
+ NSHTTPURLResponse *replay = replayFor(task, response);
+ %orig(session, task, replay ?: response, handler);
+ if (replay) deliver((id)self, session, task, cached());
+}
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveData:(NSData *)data {
+ if (!holds(task, data)) %orig;
+}
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
+ complete((id)self, session, task, error, ^(NSError *passed) { %orig(session, task, passed); });
+}
+%end
+
+#pragma mark - before a request leaves
+
+// The re-fetches that could put the real product state back, or drop the push token, use sessions
+// of their own that the delegate hooks do not see; they are cancelled at the task. login5 and the
+// Google token stay: blocking those was a crash loop.
+%group Premium
+%hook NSURLSessionTask
+- (void)resume {
+ NSURL *url = self.currentRequest.URL ?: self.originalRequest.URL;
+ NSString *host = url.host.lowercaseString ?: @"", *path = url.path.lowercaseString ?: @"";
+ BOOL spotify = has(host, @"spotify") || has(host, @"spclient");
+ if (spotify && elapsed() > 30 && (has(path, @"deletetoken") || has(path, @"signup/public") || has(path, @"pses/screenconfig")
+ || isCustomize(path) || has(host, @"apresolve"))) {
+ SGAdBlockCountOne(@"Requests");
+ SGLog(@"cancelled %@%@ before it left", host, path);
+ [self cancel];
+ return;
+ }
+ %orig;
+}
+%end
+%end
+
+// The config comes back 304 with no body when the app holds a copy of it and asks whether that is still
+// current, and a copy taken while Spoof Premium was off is the server's own: the mod then has nothing to
+// rewrite, and the account stays free until the server changes the config (device 2026-09-21). So the two
+// go out without the question, and the server always answers in full.
+static NSURLRequest *unconditional(NSURLRequest *request) {
+ NSString *host = request.URL.host.lowercaseString ?: @"", *path = request.URL.path.lowercaseString ?: @"";
+ if (!(has(host, @"spotify") || has(host, @"spclient")) || !(isBootstrap(path) || isCustomize(path))) return nil;
+ if (![request valueForHTTPHeaderField:@"If-None-Match"] && ![request valueForHTTPHeaderField:@"If-Modified-Since"]) return nil;
+ NSMutableURLRequest *plain = [request mutableCopy];
+ [plain setValue:nil forHTTPHeaderField:@"If-None-Match"];
+ [plain setValue:nil forHTTPHeaderField:@"If-Modified-Since"];
+ plain.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
+ SGLog(@"premium: %@ sent without its validators", path);
+ return plain;
+}
+
+%group PremiumRequests
+%hook NSURLSession
+- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request {
+ return %orig(unconditional(request) ?: request);
+}
+%end
+%end
+
+// The sessions Spotify makes are __NSURLSessionLocal; hooked as well only when that class answers
+// dataTaskWithRequest: itself, since a hook on an inherited method would sit on NSURLSession's twice.
+%group PremiumLocalRequests
+%hook __NSURLSessionLocal
+- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request {
+ return %orig(unconditional(request) ?: request);
+}
+%end
+%end
+
+%ctor {
+ ads = SGHidden(SGKeyHideAds);
+ premium = SGHidden(SGKeyFakePremium);
+ if (!ads && !premium) return;
+ started = NSDate.date;
+ cacheLock = [NSObject new];
+ %init;
+ if (premium) {
+ %init(Premium);
+ %init(PremiumRequests);
+ SEL selector = @selector(dataTaskWithRequest:);
+ Class local = objc_getClass("__NSURLSessionLocal");
+ Method own = local ? class_getInstanceMethod(local, selector) : NULL;
+ if (own && own != class_getInstanceMethod(NSURLSession.class, selector)) %init(PremiumLocalRequests);
+ }
+ SGRequireClasses(@[@"SPTDataLoaderService", @"_TtC26Connectivity_HttpClientKit20HttpClientURLSession"]);
+}
diff --git a/tweak/Sources/Shared/AdBlock/AdPopups.x b/tweak/Sources/Shared/AdBlock/AdPopups.x
new file mode 100644
index 00000000..2cfaa108
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdPopups.x
@@ -0,0 +1,72 @@
+// The Premium prompts Spotify presents as Encore pop-ups, dropped when their words sell Premium
+// (EeveeSpotify's UpsellPopupBlocker). The words are read where the dialog model is made, since
+// the dialog handed to the presenter does not expose them on every build; the presenter reads
+// them itself as a fallback.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+static NSString *const words[] = {
+ @"premium", @"upgrade", @"subscribe", @"subscription", @"listening without limits", @"unlimited skips",
+ @"play the songs you love", @"go premium", @"like listening", @"free account", @"ad-free", @"ad free", @"try free",
+ @"get premium", @"start premium", @"upsell", @"paywall", @"free tier", @"limited listening",
+ @"předplatn", @"bez reklam",
+};
+
+static char kUpsellKey;
+
+static BOOL sells(NSString *text) {
+ if (![text isKindOfClass:NSString.class]) return NO;
+ text = text.lowercaseString;
+ for (size_t i = 0; i < sizeof(words) / sizeof(words[0]); i++) {
+ if ([text containsString:words[i]]) return YES;
+ }
+ return NO;
+}
+
+static void mark(id object) {
+ objc_setAssociatedObject(object, &kUpsellKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+static BOOL marked(id object) {
+ return objc_getAssociatedObject(object, &kUpsellKey) != nil;
+}
+
+// valueForKey: on a key the object lacks raises, so it is only asked what it answers to.
+static id readKey(id object, NSString *key) {
+ return [object respondsToSelector:NSSelectorFromString(key)] ? [object valueForKey:key] : nil;
+}
+
+%hook SPTEncorePopUpDialogModel
+- (id)initWithTitle:(NSString *)title description:(NSString *)description image:(id)image primaryButtonTitle:(NSString *)primary secondaryButtonTitle:(NSString *)secondary {
+ id model = %orig;
+ if (model && (sells(title) || sells(description) || sells(primary) || sells(secondary))) mark(model);
+ return model;
+}
+%end
+
+%hook SPTEncorePopUpDialog
+- (void)update:(id)model {
+ if (marked(model)) mark(self);
+ %orig;
+}
+%end
+
+%hook SPTEncorePopUpPresenter
+- (void)presentPopUp:(id)popUp {
+ id model = readKey(popUp, @"model") ?: popUp;
+ NSString *title = readKey(model, @"title") ?: readKey(model, @"dialogTitle");
+ NSString *body = readKey(model, @"descriptionText") ?: readKey(model, @"body") ?: readKey(model, @"subtitle");
+ if (marked(popUp) || sells(title) || sells(body)) {
+ SGAdBlockCountOne(@"Popups");
+ SGLog(@"dropped pop-up %@", title ?: @"(marked at its model)");
+ return;
+ }
+ %orig;
+}
+%end
+
+%ctor {
+ if (!SGHidden(SGKeyHideUpsells)) return;
+ %init;
+ SGRequireClasses(@[@"SPTEncorePopUpDialogModel", @"SPTEncorePopUpDialog", @"SPTEncorePopUpPresenter"]);
+}
diff --git a/tweak/Sources/Shared/AdBlock/AdServices.x b/tweak/Sources/Shared/AdBlock/AdServices.x
new file mode 100644
index 00000000..77a1f212
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/AdServices.x
@@ -0,0 +1,126 @@
+// The services behind every ad surface and Premium prompt, each an SPTService Spotify starts by
+// sending it -load. Hooked to do nothing, the surface is never built: the brand ad on Home, the card
+// under the player, the sponsored playlist header, the sponsorship on the now playing bar, the
+// in-stream ad, and the sheets and cards that sell Premium. The two views are a fallback for a
+// header or banner already on screen before its service was silenced.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+static void takeDown(UIView *view) {
+ view.hidden = YES;
+ view.userInteractionEnabled = NO;
+ if (view.superview) [view removeFromSuperview];
+}
+
+%group Ads
+
+%hook _TtC19AdsPlatform_AdsImpl14AdsServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC29AdsNowPlaying_InStreamAdsImpl18InStreamAdsService
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC29AdsNowPlaying_EmbeddedNPVImpl22EmbeddedNPVServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC36AdsStandalone_LeavebehindAdsBaseImpl25LeavebehindAdsBaseService
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC36AdsStandalone_LeavebehindAdsBaseImpl33LeavebehindAdsBaseInternalService
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC35AdsEmbedded_AdsSponsoredContextImpl30AdsSponsoredContextServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC48AdsEmbedded_AdsSponsoredContextNPBAttachmentImpl43AdsSponsoredContextNPBAttachmentServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC42AdsEmbedded_AdsSponsoredPlaylistHeaderImpl37AdsSponsoredPlaylistHeaderServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+%hook _TtC20NativeAds_LoggerImpl26NativeAdsLoggerServiceImpl
+- (void)load { SGAdBlockCountOne(@"Ad services"); }
+%end
+// The leavebehind card among the player's scroll cards. It has no -load; its card is added the way
+// lyrics and credits add theirs, so it is kept off the list instead.
+%hook _TtC32AdsEmbedded_EmbeddedCTACardsImpl23EmbeddedCTACardsService
+- (void)registerScrollProviderIn:(id)registry { SGAdBlockCountOne(@"Ad services"); }
+%end
+
+%hook _TtC18AdsPlatform_ECMKit37AdsSponsoredPlaylistHeaderCentralView
+- (void)didMoveToSuperview {
+ %orig;
+ takeDown((UIView *)self);
+}
+%end
+
+%end
+
+%group Upsells
+
+%hook _TtC19Upsells_ServiceImpl18UpsellsServiceImpl
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC31PremiumUpsell_UpsellServiceImpl17UpsellServiceImpl
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC45ReinventFree_ContextualUpsellPremiumPromoImpl39ContextualUpsellPremiumPromoServiceImpl
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC40Referrals_ReferralsUpsellCardElementImpl37ReferralsUpsellCardElementServiceImpl
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC31ReinventFree_DownloadUpsellImpl21DownloadUpsellService
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC28Jam_FreeHostedJamsUpsellImpl31FreeHostedJamsUpsellServiceImpl
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC30Jam_FreeUserSkipUpsellPageImpl29FreeUserSkipUpsellPageService
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+%hook _TtC38Jam_FreeUserShuffleUpsellSheetPageImpl37FreeUserShuffleUpsellSheetPageService
+- (void)load { SGAdBlockCountOne(@"Upsell services"); }
+%end
+
+%hook _TtC13Upsells_UIKit29SelfLoadingUpsellBannerUIView
+- (void)didMoveToSuperview {
+ %orig;
+ takeDown((UIView *)self);
+}
+%end
+
+%end
+
+%ctor {
+ if (SGHidden(SGKeyHideAds)) {
+ %init(Ads);
+ SGRequireClasses(@[
+ @"_TtC19AdsPlatform_AdsImpl14AdsServiceImpl",
+ @"_TtC29AdsNowPlaying_InStreamAdsImpl18InStreamAdsService",
+ @"_TtC29AdsNowPlaying_EmbeddedNPVImpl22EmbeddedNPVServiceImpl",
+ @"_TtC36AdsStandalone_LeavebehindAdsBaseImpl25LeavebehindAdsBaseService",
+ @"_TtC36AdsStandalone_LeavebehindAdsBaseImpl33LeavebehindAdsBaseInternalService",
+ @"_TtC35AdsEmbedded_AdsSponsoredContextImpl30AdsSponsoredContextServiceImpl",
+ @"_TtC48AdsEmbedded_AdsSponsoredContextNPBAttachmentImpl43AdsSponsoredContextNPBAttachmentServiceImpl",
+ @"_TtC42AdsEmbedded_AdsSponsoredPlaylistHeaderImpl37AdsSponsoredPlaylistHeaderServiceImpl",
+ @"_TtC20NativeAds_LoggerImpl26NativeAdsLoggerServiceImpl",
+ @"_TtC32AdsEmbedded_EmbeddedCTACardsImpl23EmbeddedCTACardsService",
+ @"_TtC18AdsPlatform_ECMKit37AdsSponsoredPlaylistHeaderCentralView",
+ ]);
+ }
+ if (SGHidden(SGKeyHideUpsells)) {
+ %init(Upsells);
+ SGRequireClasses(@[
+ @"_TtC19Upsells_ServiceImpl18UpsellsServiceImpl",
+ @"_TtC31PremiumUpsell_UpsellServiceImpl17UpsellServiceImpl",
+ @"_TtC45ReinventFree_ContextualUpsellPremiumPromoImpl39ContextualUpsellPremiumPromoServiceImpl",
+ @"_TtC40Referrals_ReferralsUpsellCardElementImpl37ReferralsUpsellCardElementServiceImpl",
+ @"_TtC31ReinventFree_DownloadUpsellImpl21DownloadUpsellService",
+ @"_TtC28Jam_FreeHostedJamsUpsellImpl31FreeHostedJamsUpsellServiceImpl",
+ @"_TtC30Jam_FreeUserSkipUpsellPageImpl29FreeUserSkipUpsellPageService",
+ @"_TtC38Jam_FreeUserShuffleUpsellSheetPageImpl37FreeUserShuffleUpsellSheetPageService",
+ @"_TtC13Upsells_UIKit29SelfLoadingUpsellBannerUIView",
+ ]);
+ }
+}
diff --git a/tweak/Sources/Shared/AdBlock/Crossfade.x b/tweak/Sources/Shared/AdBlock/Crossfade.x
new file mode 100644
index 00000000..ea71958a
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/Crossfade.x
@@ -0,0 +1,21 @@
+// Crossfade under Spoof Premium (EeveeSpotify's): the fade engine reads the stored crossfade switch,
+// but the duration slider only writes the duration, so the fade stayed off at any length.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+
+@interface _TtC31Preferences_CorePreferencesImpl28SPTPreferencesImplementation : NSObject
+- (void)setAudioCrossfade:(BOOL)on;
+@end
+
+%hook _TtC31Preferences_CorePreferencesImpl28SPTPreferencesImplementation
+- (void)setAudioCrossfadeTime:(NSInteger)time {
+ %orig;
+ [self setAudioCrossfade:time > 0];
+}
+%end
+
+%ctor {
+ if (!SGHidden(SGKeyFakePremium)) return;
+ %init;
+ SGRequireClasses(@[@"_TtC31Preferences_CorePreferencesImpl28SPTPreferencesImplementation"]);
+}
diff --git a/tweak/Sources/Shared/AdBlock/Feeds.m b/tweak/Sources/Shared/AdBlock/Feeds.m
new file mode 100644
index 00000000..e38d30bb
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/Feeds.m
@@ -0,0 +1,65 @@
+// Ad sections taken out of the feeds Home, Search and the page under the player are built from
+// (EeveeSpotify's BrowsitaSectionStripper). A feed is one container field of sections, each a
+// field 1 message; a section goes when its bytes name an ad, or a promotion and a surface for it.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+#import "Protobuf.h"
+
+static const char *const hardMarkers[] = {
+ "spotify:ad:", "ad-formats", "advertisement", "brand-ad", "sponsored", "marquee", "promoted", "home-ads",
+ "adsproduct", "leavebehind", "leave-behind", "premium-upsell", "premium_upsell", "premiumupsell",
+ "referralsupsellcard",
+};
+static const char *const intentMarkers[] = {
+ "upsell", "upgrade", "subscribe", "premium", "promo", "promotion", "marketing", "offer",
+};
+static const char *const surfaceMarkers[] = {
+ "banner", "card", "popup", "pop-up", "sheet", "interstitial", "promotion", "promo",
+};
+// The filter chips of Search carry "browse" and "chip" in their ids and are never the ad.
+static const char *const keepMarkers[] = {"filter", "chip", "pillar", "browse:chips"};
+
+#define COUNT(list) (sizeof(list) / sizeof(list[0]))
+
+// ASCII, case-insensitive; the markers are lower case.
+static BOOL contains(NSData *data, const char *needle) {
+ const uint8_t *bytes = data.bytes;
+ size_t length = data.length, n = strlen(needle);
+ for (size_t i = 0; i + n <= length; i++) {
+ size_t k = 0;
+ while (k < n && tolower(bytes[i + k]) == needle[k]) k++;
+ if (k == n) return YES;
+ }
+ return NO;
+}
+
+static BOOL containsAny(NSData *data, const char *const markers[], size_t count) {
+ for (size_t i = 0; i < count; i++) {
+ if (contains(data, markers[i])) return YES;
+ }
+ return NO;
+}
+
+static BOOL adSection(NSData *section) {
+ if (containsAny(section, hardMarkers, COUNT(hardMarkers))) return YES;
+ if (containsAny(section, keepMarkers, COUNT(keepMarkers))) return NO;
+ return containsAny(section, intentMarkers, COUNT(intentMarkers)) && containsAny(section, surfaceMarkers, COUNT(surfaceMarkers));
+}
+
+NSData *SGStripFeed(NSData *body) {
+ NSMutableArray<SGPBField *> *fields = SGPBParse(body);
+ SGPBField *container = fields.firstObject;
+ if (container.number != 1 || container.wire != 2) return nil;
+ NSMutableArray<SGPBField *> *sections = SGPBParse(container.payload);
+ if (!sections) return nil;
+ NSMutableArray<SGPBField *> *kept = [NSMutableArray array];
+ for (SGPBField *section in sections) {
+ if (section.number != 1 || section.wire != 2) return nil;
+ if (adSection(section.payload)) SGAdBlockCountOne(@"Feed sections");
+ else [kept addObject:section];
+ }
+ if (kept.count == sections.count) return nil;
+ SGLog(@"dropped %lu of %lu feed sections", (unsigned long)(sections.count - kept.count), (unsigned long)sections.count);
+ container.payload = SGPBSerialize(kept);
+ return SGPBSerialize(fields);
+}
diff --git a/tweak/Sources/Shared/AdBlock/Premium.m b/tweak/Sources/Shared/AdBlock/Premium.m
new file mode 100644
index 00000000..c55a3b75
--- /dev/null
+++ b/tweak/Sources/Shared/AdBlock/Premium.m
@@ -0,0 +1,433 @@
+// Spoof Premium: the UCS response, which carries the account's product state and its remote
+// config, rewritten as it arrives. The attributes and the flag rules are EeveeSpotify's. Offline,
+// audio quality and the social session attributes are left alone: the server still decides those,
+// and a spoofed one only shows UI the request behind it will fail.
+//
+// UcsResponse: 1 ResolveResponse { 1 ResolveConfiguration { 3 repeated AssignedValue } },
+// 3 AccountAttributesResponse { 1 repeated entry { 1 key, 2 AccountAttribute { 2 bool, 4 string } } }
+// AssignedValue: 1 { 1 scope, 2 name }, 3 BoolValue { 1 }, 4 IntValue { 1 }, 5 EnumValue { 1 }
+// A customize body is CustomizeMessage { 1 UcsResponse }; bootstrap wraps that in 2 { 1 { 1 { it } } }.
+#import "Core/SGCore.h"
+#import "AdBlock.h"
+#import "Protobuf.h"
+
+#pragma mark - account attributes
+
+// A string goes in as one, a number as a bool.
+static NSDictionary<NSString *, id> *forcedAttributes(void) {
+ NSISO8601DateFormatter *iso = [NSISO8601DateFormatter new];
+ iso.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
+ NSString *yearOn = [iso stringFromDate:[NSCalendar.currentCalendar dateByAddingUnit:NSCalendarUnitYear value:1 toDate:NSDate.date options:0]];
+ return @{
+ @"ads": @NO,
+ @"ab-ad-player-targeting": @"0",
+ @"allow-advertising-id-transmission": @NO,
+ @"restrict-advertising-id-transmission": @YES,
+ @"can_use_superbird": @YES,
+ @"enable-crossfade-product-state": @"1",
+ @"enable-gapless-product-state": @"1",
+ @"catalogue": @"premium",
+ @"financial-product": @"pr:premium,tc:0",
+ @"is-eligible-premium-unboxing": @YES,
+ @"name": @"Spotify Premium",
+ @"nft-disabled": @"1",
+ @"on-demand": @YES,
+ @"payments-initial-campaign": @"default",
+ @"player-license": @"premium",
+ @"player-license-v2": @"premium",
+ @"product-expiry": yearOn,
+ @"shuffle-eligible": @YES,
+ @"streaming-rules": @"",
+ @"subscription-enddate": yearOn,
+ @"type": @"premium",
+ @"unrestricted": @YES,
+ @"high-bitrate": @YES,
+ @"loudness-levels": @"1:-5.0,0.0,3.0:-2.0",
+ @"pick-and-shuffle": @NO,
+ @"mixing-tools": @"EDIT",
+ @"your-library-tags": @YES,
+ @"libspotify": @YES,
+ @"mobile": @YES,
+ };
+}
+
+// Attributes that would have the client validate the state against the server, or offer a trial.
+static NSString *const strippedAttributes[] = {
+ @"payment-state", @"last-premium-activation-date", @"on-demand-trial", @"on-demand-trial-in-progress",
+ @"smart-shuffle", @"at-signal", @"feature-set-id-masked", @"strider-key", @"is-eligible-for-trial",
+ @"is-eligible-for-upsell", @"upsell-state", @"ad-session-persistence", @"ad-formats-preroll-video",
+};
+
+static BOOL stripped(NSString *key) {
+ if ([key hasPrefix:@"is-premium-eligible"]) return YES;
+ for (size_t i = 0; i < sizeof(strippedAttributes) / sizeof(strippedAttributes[0]); i++) {
+ if ([key isEqualToString:strippedAttributes[i]]) return YES;
+ }
+ return NO;
+}
+
+static SGPBField *attributeEntry(NSString *key, id value) {
+ SGPBField *attribute = [value isKindOfClass:NSString.class] ? SGPBString(4, value) : SGPBVarint(2, [value boolValue]);
+ return SGPBBytes(1, SGPBSerialize(@[SGPBString(1, key), SGPBBytes(2, SGPBSerialize(@[attribute]))]));
+}
+
+static NSData *patchAttributes(NSData *response) {
+ NSMutableArray<SGPBField *> *fields = SGPBParse(response);
+ if (!fields) return nil;
+ NSDictionary<NSString *, id> *forced = forcedAttributes();
+ NSMutableArray<SGPBField *> *out = [NSMutableArray array];
+ NSMutableSet<NSString *> *seen = [NSMutableSet set];
+ for (SGPBField *field in fields) {
+ NSString *key = field.number == 1 && field.wire == 2 ? SGPBText(SGPBFirst(SGPBParse(field.payload), 1)) : nil;
+ if (!key || (!forced[key] && !stripped(key))) {
+ [out addObject:field];
+ continue;
+ }
+ if (!forced[key]) continue;
+ [seen addObject:key];
+ [out addObject:attributeEntry(key, forced[key])];
+ }
+ for (NSString *key in forced) {
+ if (![seen containsObject:key]) [out addObject:attributeEntry(key, forced[key])];
+ }
+ return SGPBSerialize(out);
+}
+
+#pragma mark - remote config
+
+typedef NS_ENUM(NSInteger, SGRuleKind) { SGRuleRemove, SGRuleSet, SGRuleForce, SGRuleEnum };
+// A NULL scope or name matches any. Set changes a value that is there, Force adds it when it is not.
+typedef struct { const char *scope, *name; SGRuleKind kind; BOOL on; const char *text; } SGRule;
+
+static const SGRule rules[] = {
+ // The ios-feature-settings flags only draw the rows; the player core gates each on its own scope.
+ {"ios-feature-settings", "crossfade_enabled", SGRuleForce, YES, NULL},
+ {"ios-feature-settings", "automix_enabled", SGRuleForce, YES, NULL},
+ {"core-playback-setup", "crossfade_enabled", SGRuleForce, YES, NULL},
+ {"core-automix", "automix_enabled", SGRuleForce, YES, NULL},
+ {"ios-feature-settings", "use_playback_settings_crossfade", SGRuleForce, NO, NULL},
+ {"ios-feature-settings", "use_playback_settings_gapless", SGRuleForce, NO, NULL},
+ {NULL, "enable_common_capping", SGRuleRemove, NO, NULL},
+ {NULL, "enable_pns_common_capping", SGRuleRemove, NO, NULL},
+ {NULL, "enable_pick_and_shuffle_common_capping", SGRuleRemove, NO, NULL},
+ {NULL, "enable_pick_and_shuffle_dynamic_cap", SGRuleRemove, NO, NULL},
+ {NULL, "pick_and_shuffle_timecap", SGRuleRemove, NO, NULL},
+ {"ios-feature-queue", NULL, SGRuleRemove, NO, NULL},
+ {NULL, "enable_free_on_demand_experiment", SGRuleRemove, NO, NULL},
+ {NULL, "enable_free_on_demand_context_menu_experiment", SGRuleRemove, NO, NULL},
+ {NULL, "enable_mft_plus_queue", SGRuleRemove, NO, NULL},
+ {NULL, "enable_mft_plus_extended_queue", SGRuleRemove, NO, NULL},
+ {NULL, "enable_playback_timeout_service", SGRuleSet, NO, NULL},
+ {NULL, "enable_playback_timeout_error_ui", SGRuleSet, NO, NULL},
+ {NULL, "playback_timeout_action", SGRuleEnum, NO, "Nothing"},
+ {NULL, "is_remove_from_queue_enabled_for_mft_plus", SGRuleRemove, NO, NULL},
+ {NULL, "is_reordering_for_mft_plus_allowed", SGRuleRemove, NO, NULL},
+ {NULL, "ads", SGRuleSet, NO, NULL},
+ {NULL, "ad_metadata", SGRuleRemove, NO, NULL},
+ {NULL, "ad_slots", SGRuleRemove, NO, NULL},
+ {NULL, "enable_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_audio_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_display_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_premium_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_upsell", SGRuleSet, NO, NULL},
+ {NULL, "show_upsell", SGRuleSet, NO, NULL},
+ {NULL, "show_premium_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_campaigns", SGRuleSet, NO, NULL},
+ {NULL, "enable_promotions", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_upsell", SGRuleSet, NO, NULL},
+ {"ios-feature-shuffletoggleupsell", "is_enabled_pt2", SGRuleForce, NO, NULL},
+ {"ios-feature-shuffletoggleupsell", "linear_upsell_new_style_experiment_enabled", SGRuleForce, NO, NULL},
+ {"ios-feature-shuffletoggleupsell", "play_modes_upsell_new_style_experiment_enabled", SGRuleForce, NO, NULL},
+ {"ios-jam-freeusershuffleupsellsheetpage-impl", "free_user_shuffle_upsell_sheet_enabled", SGRuleForce, NO, NULL},
+ {"ios-jam-freeuserskipupsellpage-impl", "free_user_skip_upsell_sheet_enabled", SGRuleForce, NO, NULL},
+ {"ios-jam-freehostedjamsupsell-impl", "free_hosted_jams_upsell_enabled", SGRuleForce, NO, NULL},
+ {"ios-reinventfree-contextualupsellpremiumpromo-impl", "is_promo_cta_enabled", SGRuleForce, NO, NULL},
+ {"ios-reinventfree-contextualupsellpremiumpromo-impl", "show_time_cap_upsell_with_premium_badge", SGRuleForce, NO, NULL},
+ {"ios-reinventfree-controllerui-impl", "enable_video_time_cap_upsell", SGRuleForce, NO, NULL},
+ {"ios-reinventfree-controllerui-impl", "enable_video_time_cap_upsell_on_search", SGRuleForce, NO, NULL},
+ {"ios-reinventfree-timecappivot-impl", "music_video_upsell_enabled", SGRuleForce, NO, NULL},
+ {"ios-settings-mediaqualitypageplugin-impl", "is_gbb_upsell_enabled", SGRuleForce, NO, NULL},
+ {"ios-settings-mediaqualitypageplugin-impl", "should_show_pigeon_upsell", SGRuleForce, NO, NULL},
+ {"ios-system-listeningparties", "preview_ended_upsell_enabled", SGRuleForce, NO, NULL},
+ {NULL, "enable_now_playing_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_now_playing_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_artist_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_playlist_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_album_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_library_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_audiobook_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_banner_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_banner_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_podcast_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_content", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_playlists", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_sessions", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_stories", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_videos", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artist", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artists", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_album", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_albums", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_track", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_tracks", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_show", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_shows", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_episode", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_episodes", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobook", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobooks", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcast", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcasts", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_results", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_now_playing", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_now_playing_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_now_playing_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artist_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artist_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_playlist_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_playlist_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_album_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_album_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_library_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_library_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobook_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobook_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcast_banner", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcast_banners", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_now_playing_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_now_playing_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artist_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_artist_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_playlist_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_playlist_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_album_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_album_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_library_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_library_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobook_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_audiobook_sponsored_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcast_sponsored_ad", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_podcast_sponsored_ads", SGRuleSet, NO, NULL},
+ {"ios-ad-on-app-open", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-adonappopen", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-adonappopen", "enabled", SGRuleSet, NO, NULL},
+ {"ios-feature-adonappopen", "background_refresh_frequency_seconds", SGRuleSet, NO, NULL},
+ {NULL, "is_ad_on_app_open_enabled", SGRuleSet, NO, NULL},
+ {NULL, "ad_on_app_open_enabled", SGRuleSet, NO, NULL},
+ {NULL, "adonappopen_enabled", SGRuleSet, NO, NULL},
+ {"marquee", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-marquee", NULL, SGRuleRemove, NO, NULL},
+ {"leavebehindadsbase", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-leavebehindadsbase", NULL, SGRuleRemove, NO, NULL},
+ {"ios-nowplaying-scroll-impl", "unified_leavebehind_npv_scroll_music_enabled", SGRuleForce, NO, NULL},
+ {"ios-nowplaying-scroll-impl", "unified_leavebehind_npv_scroll_podcast_enabled", SGRuleForce, NO, NULL},
+ {"ios-feature-embeddedplaylist", "use_unified_leavebehind_fetch", SGRuleForce, NO, NULL},
+ {"ios-adsnowplaying-embeddednpv-impl", "foreground_enabled", SGRuleForce, NO, NULL},
+ {"ios-adsnowplaying-embeddednpv-impl", "music_track_change_enabled", SGRuleForce, NO, NULL},
+ {"ios-adsnowplaying-embeddednpv-impl", "enable_ads_on_podcast", SGRuleForce, NO, NULL},
+ {"ios-feature-instreamads", NULL, SGRuleRemove, NO, NULL},
+ {"ios-adsembedded-embeddedctaelements-impl", NULL, SGRuleRemove, NO, NULL},
+ {"ios-adsnowplaying-embeddednpv-impl", NULL, SGRuleRemove, NO, NULL},
+ {"ios-adsplatform-elementimpl", NULL, SGRuleRemove, NO, NULL},
+ {"ios-system-adssponsoredcontext", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-adsbase", "enable_ads_connect_state_observer", SGRuleSet, NO, NULL},
+ {"ios-feature-adsbase", "enable_minimal_preroll_management", SGRuleSet, NO, NULL},
+ {"ios-feature-adsbase", "enable_swift_ads_base_movement_logger", SGRuleSet, NO, NULL},
+ {"ios-feature-adsswift", NULL, SGRuleRemove, NO, NULL},
+ {"ios-feature-adsnowplayingui", "embedded_npv_video_show_with_canvas", SGRuleForce, NO, NULL},
+ {"ios-feature-adssponsoredcontext", "sponsored_context_mismatch_aderror_enabled", SGRuleSet, NO, NULL},
+ {"ios-feature-adssponsoredcontext", "sponsored_playlist_v2_enabled", SGRuleSet, NO, NULL},
+ {"ios-feature-adssponsoredcontextnpbattachment", "sponsored_npb_slot_fetch_enabled", SGRuleSet, NO, NULL},
+ {"ios-feature-adsidentitytracking", NULL, SGRuleRemove, NO, NULL},
+ {NULL, "enable_popups", SGRuleSet, NO, NULL},
+ {NULL, "enable_leave_behind_ads_card_element", SGRuleSet, NO, NULL},
+ {NULL, "music_npv_leavebehinds_enabled", SGRuleSet, NO, NULL},
+ {NULL, "enable_ads_on_podcast", SGRuleSet, NO, NULL},
+ {NULL, "enable_display_element", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_element", SGRuleSet, NO, NULL},
+ {NULL, "is_promo_cta_enabled", SGRuleSet, NO, NULL},
+ {NULL, "show_time_cap_upsell_with_premium_badge", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_time_cap_upsell", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_time_cap_upsell_on_search", SGRuleSet, NO, NULL},
+ {NULL, "music_video_upsell_enabled", SGRuleSet, NO, NULL},
+ {NULL, "is_gbb_upsell_enabled", SGRuleSet, NO, NULL},
+ {NULL, "should_show_pigeon_upsell", SGRuleSet, NO, NULL},
+ {NULL, "disable_suggested_tracks_upsell", SGRuleSet, YES, NULL},
+ {NULL, "is_enabled_pt2", SGRuleSet, NO, NULL},
+ {NULL, "show_skip_button_during_skippable_ads", SGRuleSet, YES, NULL},
+ {NULL, "sponsored_playlist_v2_header_dismissible", SGRuleSet, YES, NULL},
+ {NULL, "use_mock_sponsorship_endpoint", SGRuleSet, NO, NULL},
+ {NULL, "enable_popup", SGRuleSet, NO, NULL},
+ {NULL, "show_popups", SGRuleSet, NO, NULL},
+ {NULL, "show_popup", SGRuleSet, NO, NULL},
+ {NULL, "enable_interstitials", SGRuleSet, NO, NULL},
+ {NULL, "enable_interstitial", SGRuleSet, NO, NULL},
+ {NULL, "enable_overlays", SGRuleSet, NO, NULL},
+ {NULL, "enable_overlay", SGRuleSet, NO, NULL},
+ {NULL, "enable_promotions_on_home", SGRuleSet, NO, NULL},
+ {NULL, "enable_promotions_on_search", SGRuleSet, NO, NULL},
+ {NULL, "enable_search_page_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_home_page_ads", SGRuleSet, NO, NULL},
+ {NULL, "enable_billboard", SGRuleSet, NO, NULL},
+ {NULL, "enable_billboards", SGRuleSet, NO, NULL},
+ {NULL, "enable_audio_ads_player", SGRuleSet, NO, NULL},
+ {NULL, "enable_display_ads_player", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_ads_player", SGRuleSet, NO, NULL},
+ {NULL, "enable_audio_ads_player_v2", SGRuleSet, NO, NULL},
+ {NULL, "enable_display_ads_player_v2", SGRuleSet, NO, NULL},
+ {NULL, "enable_video_ads_player_v2", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_search_results_v2", SGRuleSet, NO, NULL},
+ {NULL, "enable_sponsored_home_results_v2", SGRuleSet, NO, NULL},
+ {"ios-feature-search", "prompted_playlist_merchandizing_enabled", SGRuleSet, NO, NULL},
+ {NULL, "should_nova_scroll_use_scrollsita", SGRuleRemove, NO, NULL},
+ {"ios-sociallistening-configuration-impl", "premium_gated_start_jam_buttons_enabled", SGRuleForce, NO, NULL},
+};
+static const size_t ruleCount = sizeof(rules) / sizeof(rules[0]);
+
+static BOOL ruleMatches(const SGRule *rule, NSString *scope, NSString *name) {
+ if (rule->scope && ![scope isEqualToString:@(rule->scope)]) return NO;
+ return !rule->name || [name isEqualToString:@(rule->name)];
+}
+
+// A false BoolValue is an empty message, as protobuf writes it.
+static NSData *boolValue(BOOL on) {
+ return on ? SGPBSerialize(@[SGPBVarint(1, 1)]) : [NSData data];
+}
+
+static void setValue(NSMutableArray<SGPBField *> *value, SGPBField *replacement) {
+ [value filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(SGPBField *field, NSDictionary *bindings) {
+ return field.number < 3 || field.number > 5;
+ }]];
+ [value addObject:replacement];
+}
+
+static NSData *patchConfiguration(NSData *configuration) {
+ NSMutableArray<SGPBField *> *fields = SGPBParse(configuration);
+ if (!fields) return nil;
+ NSMutableArray<SGPBField *> *out = [NSMutableArray array];
+ NSMutableSet<NSString *> *present = [NSMutableSet set];
+ for (SGPBField *field in fields) {
+ NSMutableArray<SGPBField *> *value = field.number == 3 && field.wire == 2 ? SGPBParse(field.payload) : nil;
+ SGPBField *identifier = SGPBFirst(value, 1);
+ NSArray<SGPBField *> *parts = identifier ? SGPBParse(identifier.payload) : nil;
+ if (!parts) {
+ [out addObject:field];
+ continue;
+ }
+ NSString *scope = SGPBText(SGPBFirst(parts, 1)) ?: @"", *name = SGPBText(SGPBFirst(parts, 2)) ?: @"";
+ BOOL removed = NO;
+ for (size_t i = 0; i < ruleCount && !removed; i++) {
+ if (!ruleMatches(&rules[i], scope, name)) continue;
+ switch (rules[i].kind) {
+ case SGRuleRemove: removed = YES; break;
+ case SGRuleSet:
+ // Set changes a boolean that is there; a value of another kind (a count of seconds, say)
+ // under the same name is left as the server sent it rather than turned into a false.
+ if (SGPBFirst(value, 3)) setValue(value, SGPBBytes(3, boolValue(rules[i].on)));
+ break;
+ case SGRuleForce: setValue(value, SGPBBytes(3, boolValue(rules[i].on))); break;
+ case SGRuleEnum: setValue(value, SGPBBytes(5, SGPBSerialize(@[SGPBString(1, @(rules[i].text))]))); break;
+ }
+ }
+ if (removed) continue;
+ [present addObject:[NSString stringWithFormat:@"%@.%@", scope, name]];
+ field.payload = SGPBSerialize(value);
+ [out addObject:field];
+ }
+ for (size_t i = 0; i < ruleCount; i++) {
+ if (rules[i].kind != SGRuleForce || !rules[i].scope || !rules[i].name) continue;
+ if ([present containsObject:[NSString stringWithFormat:@"%s.%s", rules[i].scope, rules[i].name]]) continue;
+ NSData *identifier = SGPBSerialize(@[SGPBString(1, @(rules[i].scope)), SGPBString(2, @(rules[i].name))]);
+ [out addObject:SGPBBytes(3, SGPBSerialize(@[SGPBBytes(1, identifier), SGPBBytes(3, boolValue(rules[i].on))]))];
+ }
+ return SGPBSerialize(out);
+}
+
+#pragma mark - the response
+
+static NSData *patchUcs(NSData *ucs) {
+ NSMutableArray<SGPBField *> *fields = SGPBParse(ucs);
+ if (!fields) return nil;
+ SGPBField *resolve = SGPBFirst(fields, 1);
+ if (resolve.wire == 2) {
+ NSData *edited = SGPBEdit(resolve.payload, @[@1], ^NSData *(NSData *configuration) {
+ return patchConfiguration(configuration);
+ });
+ if (edited) resolve.payload = edited;
+ }
+ SGPBField *attributes = SGPBFirst(fields, 3);
+ if (!attributes) [fields addObject:(attributes = SGPBBytes(3, nil))];
+ if (attributes.wire == 2) attributes.payload = patchAttributes(attributes.payload) ?: attributes.payload;
+ return SGPBSerialize(fields);
+}
+
+NSData *SGPatchCustomize(NSData *body) {
+ return SGPBEdit(body, @[@1], ^NSData *(NSData *ucs) { return patchUcs(ucs); });
+}
+
+NSData *SGPatchBootstrap(NSData *body) {
+ return SGPBEdit(body, @[@2, @1, @1, @1], ^NSData *(NSData *ucs) { return patchUcs(ucs); });
+}
diff --git a/tweak/Sources/Shared/Lyrics/Protobuf.h b/tweak/Sources/Shared/AdBlock/Protobuf.h
similarity index 92%
rename from tweak/Sources/Shared/Lyrics/Protobuf.h
rename to tweak/Sources/Shared/AdBlock/Protobuf.h
index e814f591..9dbda88c 100644
--- a/tweak/Sources/Shared/Lyrics/Protobuf.h
+++ b/tweak/Sources/Shared/AdBlock/Protobuf.h
@@ -1,5 +1,5 @@
// The protobuf wire format, just enough to walk into a message, change a few fields and write it
-// back with everything else untouched. The lyrics read Spotify's replies through it.
+// back with everything else untouched. Premium.m and Feeds.m read Spotify's responses through it.
#import <Foundation/Foundation.h>
// A field as it sits on the wire: a varint carries its value, everything else its raw payload.
diff --git a/tweak/Sources/Shared/Lyrics/Protobuf.m b/tweak/Sources/Shared/AdBlock/Protobuf.m
similarity index 100%
rename from tweak/Sources/Shared/Lyrics/Protobuf.m
rename to tweak/Sources/Shared/AdBlock/Protobuf.m
diff --git a/tweak/Sources/Shared/Flags/Flags.x b/tweak/Sources/Shared/Flags/Flags.x
index 065514d5..dd0ae9c9 100644
--- a/tweak/Sources/Shared/Flags/Flags.x
+++ b/tweak/Sources/Shared/Flags/Flags.x
@@ -1,7 +1,7 @@
// Spotify reads every remote-config flag once at startup through the configuration provider,
// keyed "component.property". The value handed back is Core/SGFlagForce.h's: what the redesign forces
// (Redesigned/Kit/SGRedesign.h), which comes before an override so one left from Spotify's own screens
-// cannot pull a redesigned one apart, then an override from the Flags page, then what the Search switches
+// cannot pull a redesigned one apart, then an override from the Flags page, then what the ad blocking
// and the lyrics sources force.
#import "Core/SGCore.h"
#import "Flags.h"
diff --git a/tweak/Sources/Shared/Lyrics/KaraokeSource.x b/tweak/Sources/Shared/Lyrics/KaraokeSource.x
index 582ad332..f99624fb 100644
--- a/tweak/Sources/Shared/Lyrics/KaraokeSource.x
+++ b/tweak/Sources/Shared/Lyrics/KaraokeSource.x
@@ -1,5 +1,5 @@
// Where the karaoke page gets its lines and its clock. The color-lyrics body is copied as it passes
-// Spotify's URLSession delegates, untouched, and kept per track, since the
+// the same URLSession delegates AdBlock/AdNetwork.x reads, untouched, and kept per track, since the
// page may open long after the request finished. The clock is SPTEsperantoPlayer's state, asked for on
// every frame: the player is caught the first time the app asks it, and its position runs on by itself.
// With a source of the mod's on, the color-lyrics body is Shared/LyricsSources' to answer and it
diff --git a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
index 00c7481d..a95b93cc 100644
--- a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
+++ b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
@@ -1,5 +1,5 @@
#import "Lyrics.h"
-#import "Shared/Lyrics/Protobuf.h"
+#import "Shared/AdBlock/Protobuf.h"
@implementation SGKaraokeWord
@end
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsHook.x b/tweak/Sources/Shared/LyricsSources/LyricsHook.x
index ef28e2cd..6ec368ff 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsHook.x
+++ b/tweak/Sources/Shared/LyricsSources/LyricsHook.x
@@ -3,7 +3,7 @@
// list gets a lyrics section, without which the player never asks for lyrics at all.
#import "Core/SGCore.h"
#import "LyricsSources.h"
-#import "Shared/Lyrics/Protobuf.h"
+#import "Shared/AdBlock/Protobuf.h"
#import "Headers/SPTPlayer.h"
#import <os/lock.h>
diff --git a/tweak/Sources/Shared/Privacy/Clutter.m b/tweak/Sources/Shared/Privacy/Clutter.m
deleted file mode 100644
index 663ae920..00000000
--- a/tweak/Sources/Shared/Privacy/Clutter.m
+++ /dev/null
@@ -1,22 +0,0 @@
-#import "Core/SGCore.h"
-#import "Privacy.h"
-
-static NSString *const socialProofFlags[] = {
- @"ios-feature-search.social_proof_playlist_enabled",
- @"ios-feature-search.social_proof_plays_in_search_enabled",
-};
-
-static BOOL forcedOff(NSString *key) {
- if (SGHidden(SGKeyHideSearchVideos) && [key isEqualToString:@"ios-feature-search.video_carousel_section_enabled"]) return YES;
- if (!SGHidden(SGKeyHideSocialProof)) return NO;
- for (size_t i = 0; i < sizeof(socialProofFlags) / sizeof(socialProofFlags[0]); i++) {
- if ([key isEqualToString:socialProofFlags[i]]) return YES;
- }
- return NO;
-}
-
-// After an override from the All flags page, and locking the rows that would turn the same flag off.
-__attribute__((constructor)) static void registerForcer(void) {
- SGFlagForcer off = ^id(NSString *key) { return forcedOff(key) ? @NO : nil; };
- SGRegisterFlagForcer(NO, off, off);
-}
diff --git a/tweak/Sources/Shared/Privacy/Privacy.h b/tweak/Sources/Shared/Privacy/Privacy.h
index d16c5934..f176a3af 100644
--- a/tweak/Sources/Shared/Privacy/Privacy.h
+++ b/tweak/Sources/Shared/Privacy/Privacy.h
@@ -3,9 +3,6 @@
#import <UIKit/UIKit.h>
#define SGKeyBlockTelemetry @"spotifyglass.blockTelemetry"
-// Search clutter (Clutter.m); on forces its flags off.
-#define SGKeyHideSearchVideos @"spotifyglass.adblock.searchVideos"
-#define SGKeyHideSocialProof @"spotifyglass.adblock.socialProof"
// The destinations it knows in the order it lists them, and how many requests to one of them it
// has answered instead of letting out (nil label for all of them).
@@ -13,5 +10,7 @@ NSArray<NSString *> *SGBlockedLabels(void);
NSUInteger SGBlockedCount(NSString *label);
void SGResetBlocked(void);
-// The Privacy & clutter page: telemetry, the Search switches, the tips, what telemetry blocking stopped.
-UIViewController *SGPrivacySettingsPage(void);
+@class SGModSection;
+// The telemetry switch and what it has stopped, on the Premium, ads & privacy page.
+SGModSection *SGPrivacySection(void);
+SGModSection *SGPrivacyCountersSection(void);
diff --git a/tweak/Sources/Shared/Privacy/PrivacySettings.m b/tweak/Sources/Shared/Privacy/PrivacySettings.m
index 55d96b0a..599eebfa 100644
--- a/tweak/Sources/Shared/Privacy/PrivacySettings.m
+++ b/tweak/Sources/Shared/Privacy/PrivacySettings.m
@@ -1,28 +1,13 @@
#import "Settings/SGModPage.h"
#import "Privacy.h"
-// Every switch here forces a flag Spotify ships on to off, so the titles name the hiding: on hides
-// the thing, off is Spotify's own value.
-static UIViewController *tipsPage(void) {
- return [[SGModPage alloc] initWithTitle:@"Tips" intro:SGRestartNote sections:@[
- SGSection(@"Reduce interventions", @[
- SGFlagRow(@"Reduce interventions", @"ios-messaging-reduceinterventions-impl.enabled"),
- ]),
- SGSection(@"Tooltips", @[
- SGKillRow(@"Hide the smart shuffle helper", @"ios-messaging-reduceinterventions-impl.enable_message_smart_shuffle_helper_tooltip"),
- SGKillRow(@"Hide the data saver tip", @"ios-feature-nowplayingbar.data_saver_tooltip"),
- SGKillRow(@"Hide the AI playlist creation tip", @"ios-messaging-reduceinterventions-impl.enable_message_your_library_ai_playlist_creation_tooltip"),
- SGKillRow(@"Hide the watch feed explorer tip", @"ios-messaging-reduceinterventions-impl.enable_message_watch_feed_entity_explorer_tooltip"),
- SGKillRow(@"Hide the account switching tip", @"ios-messaging-reduceinterventions-impl.enable_message_account_switching_tooltip"),
- SGKillRow(@"Hide the concert notifications tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_concert_notifications_tooltip"),
- SGKillRow(@"Hide the live event tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_safe_tooltip"),
- SGKillRow(@"Hide the live event venue tip", @"ios-messaging-reduceinterventions-impl.enable_message_live_events_event_entity_venuename_header_tooltip"),
- SGKillRow(@"Hide the Puffin nudge", @"ios-messaging-reduceinterventions-impl.enable_message_puffin_nudge_end_optimization"),
- ]),
- ] footer:nil];
+SGModSection *SGPrivacySection(void) {
+ return SGSection(@"Privacy", @[
+ SGWithSymbol(SGSwitchRow(@"Block telemetry", @"Spotify's own events still go out, since Recents is built from them", SGKeyBlockTelemetry), @"antenna.radiowaves.left.and.right.slash"),
+ ]);
}
-static SGModSection *countersSection(void) {
+SGModSection *SGPrivacyCountersSection(void) {
NSMutableArray<SGModRow *> *counts = [NSMutableArray array];
for (NSString *label in SGBlockedLabels()) {
[counts addObject:SGStatRow(label, ^NSString *{
@@ -35,18 +20,3 @@ static SGModSection *countersSection(void) {
[counts addObject:SGActionRow(@"Reset the telemetry counters", nil, ^{ SGResetBlocked(); })];
return SGSection(@"Telemetry blocked so far", counts);
}
-
-// The switches first and what they have stopped last, so the counters bury no setting.
-UIViewController *SGPrivacySettingsPage(void) {
- return [[SGModPage alloc] initWithTitle:@"Privacy & clutter" intro:SGRestartNote sections:@[
- SGSection(@"Privacy", @[
- SGWithSymbol(SGSwitchRow(@"Block telemetry", @"Spotify's own events still go out, since Recents is built from them", SGKeyBlockTelemetry), @"antenna.radiowaves.left.and.right.slash"),
- ]),
- SGSection(@"Clutter", @[
- SGWithSymbol(SGOptionRow(@"Hide the video carousel in Search", nil, SGKeyHideSearchVideos), @"play.rectangle.on.rectangle"),
- SGWithSymbol(SGOptionRow(@"Hide social proof in Search", nil, SGKeyHideSocialProof), @"person.2"),
- SGWithSymbol(SGPageRow(@"Tips", ^UIViewController *{ return tipsPage(); }), @"lightbulb"),
- ]),
- countersSection(),
- ] footer:nil];
-}