Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: BiniLyrics finds the exact recording by its ISRC
My-Name-Is-Jeff15a36f8ee171
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex d6dc4fdb..84d5301e 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -103,8 +103,10 @@ Shared:answer Spotify's requests and the mod's sources and its own requests stand asideLyricsSources/ the sources lyrics come from, asked in the order the Lyrics page puts them in and merged into thebest answer (LyricsSources.m, the list to drag in LyricsSourcesPage.m): Apple Music's TTML from- BiniLyrics.m and Unison.m, read by SGTTML.m, which carries a second voice and the- backing vocals, and in its head Apple's translation and its pronunciation of a line, the pronunciation+ BiniLyrics.m (now lrc.red: first the TTML filed under Spotify's ISRC for the track, from+ SGSpotifyISRC in Haptics/SystemMusicHaptics.x, else its search by name) and Unison.m, read by SGTTML.m,+ which carries a second voice and the backing vocals, and in its head Apple's translation and its+ pronunciation of a line, each keyed to the line by its itunes:key or lrc:key, the pronunciationtimed word by word (the translation taken in the Lyrics page's language); Musixmatch.m, matched bySpotify's track id with an anonymous token, word timed where it has richsync; NetEase.m, word timing from yrc for what the others only line time; LrcLib.m, open andkeyless and timed by the line, the floor under the rest. SpicyLyrics.m, Spicy Lyrics' Developer Platformdiff --git a/tweak/Sources/Shared/Haptics/Haptics.h b/tweak/Sources/Shared/Haptics/Haptics.hindex 83cb01e8..9a0cc517 100644--- a/tweak/Sources/Shared/Haptics/Haptics.h+++ b/tweak/Sources/Shared/Haptics/Haptics.h@@ -99,6 +99,10 @@ BOOL SGSystemMusicHapticsOn(void);void SGSetSystemMusicHapticsOn(BOOL on);extern NSNotificationName const SGSystemMusicHapticsChangedNotification;+// A Spotify track URI's ISRC from Spotify's own metadata (SystemMusicHaptics.x), nil for none, on the main queue.+// Kept for the last 100 tracks; `tries` asks again 4 s apart when Spotify does not answer.+void SGSpotifyISRC(NSString *uri, NSUInteger tries, void (^done)(NSString *isrc));+// A strength key's percentage as a factor, 1 for 100%, kept within its range.double SGHapticsStrength(NSString *key);SGMusicFollows SGMusicHapticsFollows(void);diff --git a/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.xindex 76594782..8468b82e 100644--- a/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x+++ b/tweak/Sources/Shared/Haptics/SystemMusicHaptics.x@@ -79,7 +79,7 @@ static void askSpotify(NSString *uri, NSUInteger triesLeft, void (^done)(NSStrindone(isrc);return;}- SGLog(@"music haptics: Spotify's metadata for %@ not answered (%ld, %@), %lu tries left", uri, (long)status,+ SGLog(@"isrc: Spotify's metadata for %@ not answered (%ld, %@), %lu tries left", uri, (long)status,error.localizedDescription, (unsigned long)triesLeft - 1);if (triesLeft <= 1) {done(nil);@@ -93,13 +93,13 @@ static void askSpotify(NSString *uri, NSUInteger triesLeft, void (^done)(NSStrin});}-static void spotifyISRC(NSString *uri, void (^done)(NSString *isrc)) {+void SGSpotifyISRC(NSString *uri, NSUInteger tries, void (^done)(NSString *isrc)) {id kept = [sg_isrcs objectForKey:uri];if (kept) {done(kept == NSNull.null ? nil : kept);return;}- askSpotify(uri, kSpotifyTries, done);+ askSpotify(uri, MAX(tries, 1), done);}#pragma mark - iOS@@ -206,7 +206,7 @@ API_AVAILABLE(ios(18.0))id length = state.track.metadata[@"duration"];double ms = [length respondsToSelector:@selector(doubleValue)] && [length doubleValue] > 0 ? [length doubleValue] : state.duration * 1000;self.phase = SGNativeChecking;- spotifyISRC(track, ^(NSString *isrc) {+ SGSpotifyISRC(track, kSpotifyTries, ^(NSString *isrc) {if (revision != self->_revision) return;if (!isrc) {self.phase = SGNativeUnavailable;@@ -273,9 +273,9 @@ API_AVAILABLE(ios(18.0))%ctor {// MusicHaptics.x's constructor moves it too, but may run after this one.SGMigrateMusicHaptics();+ sg_isrcs = [NSCache new];+ sg_isrcs.countLimit = kKeptISRCs;if (@available(iOS 18.0, *)) {- sg_isrcs = [NSCache new];- sg_isrcs.countLimit = kKeptISRCs;static SGNativeMusicHaptics *native;native = [SGNativeMusicHaptics new];SGAddPlayerStateObserver(native);diff --git a/tweak/Sources/Shared/LyricsSources/BiniLyrics.m b/tweak/Sources/Shared/LyricsSources/BiniLyrics.mindex 9af6987f..e9718b40 100644--- a/tweak/Sources/Shared/LyricsSources/BiniLyrics.m+++ b/tweak/Sources/Shared/LyricsSources/BiniLyrics.m@@ -1,11 +1,15 @@// BiniLyrics, the widest of the sources that serve Apple Music's own TTML: over a million recordings,-// word timed, and no key to ask for. Searched by title, artist and length, so it needs a source-// before it in the order — or the player — to have named the track. The search answers with metadata-// and a link; the TTML itself is a second request, to a plain file host.+// word timed, and no key to ask for. Its API now redirects to lrc.red, which files each TTML under the+// recording's ISRC: with Spotify's ISRC for the track, that file is asked for first, the exact recording.+// Else, or when it has none, the search by title, artist and length, so it needs a source before it in+// the order — or the player — to have named the track. The search answers with metadata and a link; the+// TTML itself is a second request, to a plain file host.#import "Core/SGCore.h"+#import "Shared/Haptics/Haptics.h"#import "LyricsSources.h"static NSString *const kAPI = @"https://lyrics-api.binimum.org/";+static NSString *const kByISRC = @"https://lrc.red/s/%@.ttml";// A recording is only taken when its length is this close to the track's, so the words fall on the// same beat. The search is by name, and a live or sped up cut of the same song is a different take.static const NSInteger kLengthSlack = 4;@@ -29,7 +33,23 @@ static NSDictionary *bestOf(id results, NSInteger seconds) {return best;}-SGLyricsAsk SGBiniLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *result)) {+// The result for a TTML, nil when it has no lines the page can show.+static SGLyricsResult *resultFor(NSString *ttml, BOOL wordTimed) {+ NSArray<SGKaraokeLine *> *lines = SGTTMLLines(ttml);+ if (!lines) return nil;+ SGLyricsResult *result = [SGLyricsResult new];+ result.synced = YES;+ result.wordTimed = wordTimed;+ result.karaokeLines = lines;+ NSArray<NSNumber *> *starts;+ NSArray<NSString *> *texts;+ SGLyricsPageLines(lines, &starts, &texts);+ result.starts = starts;+ result.texts = texts;+ return result;+}++static void search(SGLyricsQuery *query, void (^done)(SGLyricsResult *result)) {if (!query.title.length || !query.artist.length) {SGLog(@"binilyrics: nothing to search with for %@", query.trackID);done(nil);@@ -49,23 +69,35 @@ SGLyricsAsk SGBiniLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResulreturn;}SGLyricsGetText([NSURL URLWithString:found[@"lyricsUrl"]], ^(NSString *ttml) {- NSArray<SGKaraokeLine *> *lines = SGTTMLLines(ttml);- if (!lines) {- SGLog(@"binilyrics: %@ gave nothing the page could show", found[@"lyricsUrl"]);- done(nil);+ SGLyricsResult *result = resultFor(ttml, [found[@"timing_type"] isEqual:@"word"]);+ if (!result) SGLog(@"binilyrics: %@ gave nothing the page could show", found[@"lyricsUrl"]);+ else SGLog(@"binilyrics: %@ by %@ has %lu %@ lines", query.title, query.artist,+ (unsigned long)result.karaokeLines.count, result.wordTimed ? @"word timed" : @"line timed");+ done(result);+ });+ });+}++SGLyricsAsk SGBiniLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *result)) {+ if (query.trackID.length != 22) {+ search(query, done);+ return;+ }+ // Asked once: the lyrics wait on it, and the search is there when Spotify does not answer.+ SGSpotifyISRC([@"spotify:track:" stringByAppendingString:query.trackID], 1, ^(NSString *isrc) {+ if (!isrc) {+ search(query, done);+ return;+ }+ SGLyricsGetText([NSURL URLWithString:[NSString stringWithFormat:kByISRC, isrc]], ^(NSString *ttml) {+ SGLyricsResult *result = resultFor(ttml, [ttml containsString:@"timing=\"Word\""]);+ if (!result) {+ SGLog(@"binilyrics: nothing filed under %@, searched by name", isrc);+ search(query, done);return;}- SGLyricsResult *result = [SGLyricsResult new];- result.synced = YES;- result.wordTimed = [found[@"timing_type"] isEqual:@"word"];- result.karaokeLines = lines;- NSArray<NSNumber *> *starts;- NSArray<NSString *> *texts;- SGLyricsPageLines(lines, &starts, &texts);- result.starts = starts;- result.texts = texts;- SGLog(@"binilyrics: %@ by %@ has %lu %@ lines", query.title, query.artist,- (unsigned long)lines.count, result.wordTimed ? @"word timed" : @"line timed");+ SGLog(@"binilyrics: %@ (%@) has %lu %@ lines", query.title ?: query.trackID, isrc,+ (unsigned long)result.karaokeLines.count, result.wordTimed ? @"word timed" : @"line timed");done(result);});});