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

fix: Hide ads blocks the ad requests that Spotify's core sends

My-Name-Is-Jeff34681b548434
diff --git a/tweak/Sources/Shared/AdBlock/AdNetwork.x b/tweak/Sources/Shared/AdBlock/AdNetwork.x
index 121aecf7..f91a6a98 100644
--- a/tweak/Sources/Shared/AdBlock/AdNetwork.x
+++ b/tweak/Sources/Shared/AdBlock/AdNetwork.x
@@ -1,11 +1,12 @@
// 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 canceled 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.
+// SPTDataLoaderService and HttpClientURLSession for the app's own requests, and
+// SPTCoreURLSessionDataDelegate for the C++ core's, which fetch the ad config (ads/v2/config and
+// ad-logic/state/config, device 2026-10-10). 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 canceled 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"
@@ -13,7 +14,7 @@ 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;
+static char kBufferKey, kServedKey, kPassKey, kCoreAdKey;
typedef NS_ENUM(NSInteger, SGNet) { SGNetPass, SGNetBlock, SGNetPatch };
@@ -233,6 +234,32 @@ static void complete(id<NSURLSessionDataDelegate> delegate, NSURLSession *sessio
}
%end
+// The C++ core's requests: most of Spotify's traffic, the access point lookup among it. Only its ad
+// requests are touched. Each gets an empty 200 of the mod's own in place of the server's headers and
+// body. Spoof Premium's rules stay off this path, and a failed request keeps its error.
+%hook SPTCoreURLSessionDataDelegate
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))handler {
+ NSURL *url = task.currentRequest.URL;
+ if (ads && isAd(url, url.path.lowercaseString ?: @"")) {
+ objc_setAssociatedObject(task, &kCoreAdKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ response = [[NSHTTPURLResponse alloc] initWithURL:url statusCode:200 HTTPVersion:@"HTTP/2.0" headerFields:@{}];
+ }
+ %orig(session, task, response, handler);
+}
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveData:(NSData *)data {
+ if (!objc_getAssociatedObject(task, &kCoreAdKey) || objc_getAssociatedObject(task, &kPassKey)) %orig;
+}
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
+ if (!error && objc_getAssociatedObject(task, &kCoreAdKey)) {
+ SGAdBlockSawOne(@"Requests");
+ SGAdBlockCountOne(@"Requests");
+ SGLog(@"answered the core's %@ empty", task.currentRequest.URL.path);
+ deliver((id)self, session, task, [NSData data]);
+ }
+ %orig;
+}
+%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
@@ -306,5 +333,6 @@ static NSURLRequest *unconditional(NSURLRequest *request) {
Method own = local ? class_getInstanceMethod(local, selector) : NULL;
if (own && own != class_getInstanceMethod(NSURLSession.class, selector)) %init(PremiumLocalRequests);
}
- SGRequireClasses(@[@"SPTDataLoaderService", @"_TtC26Connectivity_HttpClientKit20HttpClientURLSession"]);
+ SGRequireClasses(@[@"SPTDataLoaderService", @"_TtC26Connectivity_HttpClientKit20HttpClientURLSession",
+ @"SPTCoreURLSessionDataDelegate"]);
}