Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: Spicy Lyrics gives its word timing now the request carries the desktop client's identity
Vojtěch Škopek61febbec110d
diff --git a/harness/spicylyrics/main.m b/harness/spicylyrics/main.mindex 59174341..8293b7e3 100644--- a/harness/spicylyrics/main.m+++ b/harness/spicylyrics/main.m@@ -78,6 +78,12 @@ int main(void) {checkEqual(sg_sentHeaders[@"SpicyLyrics-WebAuth"], sg_token, @"the token goes in the header it names");checkEqual(sg_sentHeaders[@"X-mode"], @"2", @"the packed shape is asked for");check([sg_sentHeaders[@"SpicyLyrics-Version"] length] > 0, @"a client version is sent");+ // The server reads the identity Spotify's desktop client's Chromium puts on every request,+ // and answers a caller without it with plain text instead of syllables.+ checkEqual(sg_sentHeaders[@"Origin"], @"https://xpui.app.spotify.com", @"the desktop client's origin");+ check([sg_sentHeaders[@"User-Agent"] containsString:@"Chrome/"], @"a Chromium user agent");+ check([sg_sentHeaders[@"sec-ch-ua-platform"] length] > 0, @"the client hints go with it");+ check(sg_sentHeaders[@"Accept-Encoding"] == nil, @"encoding is left to URLSession, which can decode what it asks for");NSDictionary *sent = [sg_sentBody[@"queries"] firstObject];checkEqual(sent[@"operation"], @"lyrics", @"the operation");checkEqual(sent[@"variables"][@"id"], @"0VjIjW4GlUZAMYd2vXMi3b", @"the track id, not a name");diff --git a/tweak/Sources/Diagnostics/PlayerState.x b/tweak/Sources/Diagnostics/PlayerState.xnew file mode 100644index 00000000..0b068576--- /dev/null+++ b/tweak/Sources/Diagnostics/PlayerState.x@@ -0,0 +1,115 @@+// Temporary diagnostics (debug builds only): what the player core says about the track it is on,+// for the reports that songs cannot be paused or scrubbed while podcasts can. Spotify greys its+// pause button and its scrubber from the state's restrictions, and nothing about them reaches the+// system log, so the state object is read out here: every property and object ivar of it, the+// restrictions inside it one level deeper, and the track's metadata, which names an ad.+//+// A line arrives on every track change and whenever the readout changes, at most one a second.+#import "Core/SGCore.h"+#import "Diagnostics.h"+#import "Headers/SPTPlayer.h"+#import <objc/runtime.h>++static NSString *summarize(id value, NSUInteger depth);++// Long collections and the queues would bury the line; their size is enough.+static NSString *summarizeCollection(id value) {+ if ([value isKindOfClass:NSArray.class]) return [NSString stringWithFormat:@"[%lu]", (unsigned long)[value count]];+ if ([value isKindOfClass:NSSet.class]) return [NSString stringWithFormat:@"{%lu}", (unsigned long)[value count]];+ return nil;+}++static NSString *readable(id value, NSUInteger depth) {+ if (!value) return @"nil";+ if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class] || [value isKindOfClass:NSURL.class]) {+ return [value description];+ }+ NSString *collection = summarizeCollection(value);+ if (collection) return collection;+ if ([value isKindOfClass:NSDictionary.class]) return [value description];+ return depth > 0 ? summarize(value, depth - 1) : NSStringFromClass([value class]);+}++// Every property the class chain declares, then the object ivars no property covers, so a restriction+// set kept in an ivar alone still shows.+static NSString *summarize(id object, NSUInteger depth) {+ if (!object) return @"nil";+ NSMutableArray<NSString *> *parts = [NSMutableArray array];+ NSMutableSet<NSString *> *seen = [NSMutableSet set];+ for (Class cls = [object class]; cls && cls != NSObject.class; cls = class_getSuperclass(cls)) {+ unsigned count = 0;+ objc_property_t *properties = class_copyPropertyList(cls, &count);+ for (unsigned i = 0; i < count; i++) {+ NSString *name = @(property_getName(properties[i]));+ if ([seen containsObject:name]) continue;+ [seen addObject:name];+ id value = nil;+ @try {+ value = [object valueForKey:name];+ } @catch (NSException *exception) {+ continue;+ }+ [parts addObject:[NSString stringWithFormat:@"%@=%@", name, readable(value, depth)]];+ }+ free(properties);++ count = 0;+ Ivar *ivars = class_copyIvarList(cls, &count);+ for (unsigned i = 0; i < count; i++) {+ const char *type = ivar_getTypeEncoding(ivars[i]);+ if (!type || type[0] != '@') continue;+ NSString *name = [@(ivar_getName(ivars[i])) stringByReplacingOccurrencesOfString:@"_" withString:@""];+ if ([seen containsObject:name]) continue;+ [seen addObject:name];+ id value = nil;+ @try {+ value = object_getIvar(object, ivars[i]);+ } @catch (NSException *exception) {+ continue;+ }+ [parts addObject:[NSString stringWithFormat:@"%@=%@", name, readable(value, depth)]];+ }+ free(ivars);+ }+ return [NSString stringWithFormat:@"<%@ %@>", NSStringFromClass([object class]), [parts componentsJoinedByString:@" "]];+}++static void report(SPTPlayerState *state) {+ static NSString *last;+ static NSDate *lastAt;+ if (lastAt && -lastAt.timeIntervalSinceNow < 1) return;+ NSString *line = summarize(state, 2);+ if ([line isEqualToString:last]) return;+ last = line;+ lastAt = NSDate.date;+ SGLogLong(@"player state", line);+ SPTPlayerTrack *track = state.track;+ if (track) SGLogLong(@"player track metadata", track.metadata.description);+}++%hook SPTEsperantoPlayer+- (id)state {+ id state = %orig;+ if (SGIsDebugBuild() && [state isKindOfClass:NSClassFromString(@"SPTPlayerState")]) report(state);+ return state;+}+%end++// Who greys the button out: Encore draws it disabled at half alpha, and the caller says which of+// Spotify's units decided it.+%hook _TtC28EncoreConsumerMobile_BaseKit14PlayButtonView+- (void)setEnabled:(BOOL)enabled {+ %orig;+ if (!SGIsDebugBuild() || enabled) return;+ static NSUInteger logged;+ if (logged++ >= 4) return;+ SGLogLong(@"play button disabled", [NSThread.callStackSymbols componentsJoinedByString:@"\n"]);+}+%end++%ctor {+ if (!SGIsDebugBuild()) return;+ %init;+ SGRequireClasses(@[@"SPTEsperantoPlayer", @"_TtC28EncoreConsumerMobile_BaseKit14PlayButtonView"]);+ SGLog(@"debug build: the player's state is logged as it changes");+}diff --git a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.mindex ec050680..ad127195 100644--- a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m+++ b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m@@ -272,8 +272,60 @@ static NSArray<SGKaraokeLine *> *linesFromLines(NSArray *content) {return SGKaraokeEstimatedLines(starts, texts);}+// What the server actually sent, named rather than quoted: the field names and counts, never the+// words. For telling a document that has no timing from one whose timing we failed to read.+static NSString *shapeOf(NSDictionary *document) {+ NSMutableString *shape = [NSMutableString stringWithFormat:@"Type=%@ keys=[%@]",+ document[@"Type"], [document.allKeys componentsJoinedByString:@" "]];+ NSArray *content = arrayIn(document[@"Content"]);+ if (content) [shape appendFormat:@" Content=%lu", (unsigned long)content.count];+ NSDictionary *first = dictionaryIn(content.firstObject);+ if (first) [shape appendFormat:@" Content[0]=[%@]", [first.allKeys componentsJoinedByString:@" "]];+ NSDictionary *lead = dictionaryIn(first[@"Lead"]);+ if (lead) [shape appendFormat:@" Lead=[%@] syllables=%lu", [lead.allKeys componentsJoinedByString:@" "],+ (unsigned long)arrayIn(lead[@"Syllables"]).count];+ NSDictionary *syllable = dictionaryIn(arrayIn(lead[@"Syllables"]).firstObject);+ if (syllable) [shape appendFormat:@" Syllable[0]=[%@]", [syllable.allKeys componentsJoinedByString:@" "]];+ NSArray *staticLines = arrayIn(document[@"Lines"]);+ if (staticLines) [shape appendFormat:@" Lines=%lu", (unsigned long)staticLines.count];+ // Whose words these are, where the document says so: a static reply is text Spicy is passing on+ // from somewhere else, and its name tells us why it came without timing.+ if (document[@"source"]) [shape appendFormat:@" source=%@", document[@"source"]];+ NSDictionary *staticLine = dictionaryIn(staticLines.firstObject);+ if (staticLine) [shape appendFormat:@" Lines[0]=[%@]", [staticLine.allKeys componentsJoinedByString:@" "]];+ return shape;+}+#pragma mark - the source+// The API answers a browser. The extension runs inside Spotify's desktop client, which is Chromium,+// and the server reads the identity Chromium puts on every request by itself — none of which a+// native URLSession sends. Without it the reply is the plain-text tier rather than Apple Music's+// syllables, which is why hundreds of tracks came back Type=Static.+//+// Spicy Lyrics' author was asked directly (2026-09-20) and allowed the mod to present itself this+// way, on the one condition that it stays open source, which spoti.pw is. He said he would not add a+// client of his own for us, and that this is the way, as EeveeSpotify already does it.+static NSDictionary<NSString *, NSString *> *desktopClient(void) {+ return @{+ @"Origin": @"https://xpui.app.spotify.com",+ @"Referer": @"https://xpui.app.spotify.com/",+ @"User-Agent": @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "+ "Chrome/146.0.7680.179 Spotify/1.2.92.148 Safari/537.36",+ @"sec-ch-ua": @"\"Not-A.Brand\";v=\"24\", \"Chromium\";v=\"146\"",+ @"sec-ch-ua-mobile": @"?0",+ @"sec-ch-ua-platform": @"\"Windows\"",+ @"sec-fetch-site": @"cross-site",+ @"sec-fetch-mode": @"cors",+ @"sec-fetch-dest": @"empty",+ @"Accept": @"*/*",+ @"Accept-Language": @"en-Latn-US,en-US;q=0.9,en-Latn;q=0.8,en;q=0.7",+ @"priority": @"u=1, i",+ // Accept-Encoding is deliberately left to NSURLSession, which asks for what it can actually+ // decode. Claiming br and zstd as the browser does risks a body nothing here can read.+ };+}+SGLyricsAsk SGSpicyLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *result)) {NSString *authorization = SGKaraokeSpotifyAuthorization();if (!query.trackID.length || !authorization.length) {@@ -287,11 +339,11 @@ SGLyricsAsk SGSpicyLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResu@"client": @{@"version": kClientVersion},};NSURL *url = [NSURL URLWithString:kAPI];- SGLyricsPostJSON(url, @{- @"X-mode": @"2", // answer in the packed shape unpack() reads- @"SpicyLyrics-Version": kClientVersion,- kAuthHeader: authorization, // already a "Bearer ..." of Spotify's own making- }, body, ^(id root) {+ NSMutableDictionary<NSString *, NSString *> *headers = [desktopClient() mutableCopy];+ headers[@"X-mode"] = @"2"; // answer in the packed shape unpack() reads+ headers[@"SpicyLyrics-Version"] = kClientVersion;+ headers[kAuthHeader] = authorization; // already a "Bearer ..." of Spotify's own making+ SGLyricsPostJSON(url, headers, body, ^(id root) {NSDictionary *job = nil;for (id raw in arrayIn(dictionaryIn(root)[@"queries"]) ?: @[]) {if ([dictionaryIn(raw)[@"operationId"] isEqual:kOperationID]) {@@ -318,6 +370,7 @@ SGLyricsAsk SGSpicyLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResureturn;}NSDictionary *document = dictionaryIn(unpack(answer[@"data"]));+ SGLog(@"spicy: %@ came back as %@", query.trackID, shapeOf(document));NSString *type = [document[@"Type"] isKindOfClass:NSString.class] ? document[@"Type"] : nil;NSArray *content = arrayIn(document[@"Content"]);BOOL wordTimed = [type isEqualToString:@"Syllable"];