Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: Automatic in Lyrics Source, and a switch to prefer word-by-word timing
My-Name-Is-Jeff10c7d9d146e7
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 809bc602..59cd7bde 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -138,7 +138,11 @@ Shared:source is on. In the redesign, with a translation language chosen, lines kept for the lyrics view withno translation of their own take Musixmatch's community translations (Musixmatch.m), whicheversource won, Spotify's own included: matched by the line's folded text, as copies kept in place of the- lines (KaraokeSource.x), which the view picks up+ lines (KaraokeSource.x), which the view picks up. The walk stops at the first timed answer; with+ Prefer word-by-word timing (off by default, read by every walk) it asks on to the first source with+ words timed and else keeps the finest it saw, the highest among equals (settled()). The redesigned+ player's ⋯ has Lyrics Source (LyricsPick.m): every source asked at once for the song playing, a pick+ shown at once and kept in memory until Spotify quits, and Automatic putting back what the order choseLyricsTranslation/ a song's lines translated from the lyrics' corner menu, for the lines no source translated, threeways, each its own item: on the iPhone by Apple's Translate (iOS 26, the song's language told byNaturalLanguage, both languages downloaded in the Translate app or the item says where to) and by Applediff --git a/tweak/Sources/Redesigned/Player/PlayerMenu.m b/tweak/Sources/Redesigned/Player/PlayerMenu.mindex 8938bd35..6560f1e6 100644--- a/tweak/Sources/Redesigned/Player/PlayerMenu.m+++ b/tweak/Sources/Redesigned/Player/PlayerMenu.m@@ -67,24 +67,26 @@ static NSString *timingText(NSArray<SGKaraokeLine *> *lines) {}}-// The sources with lines for the track, in the order, the one shown checked: the one picked, else the one the-// credit names.+// Automatic, checked while nothing is picked and naming what the order chose, then the sources with lines for+// the track, in the order, the one picked checked.static NSArray<UIMenuElement *> *sourceItems(NSString *track, NSDictionary<NSString *, SGLyricsResult *> *offers) {NSString *current = SGLyricsChosenSource(track);- NSString *credit = SGLyricsCreditFor(track);- NSMutableArray<UIMenuElement *> *items = [NSMutableArray array];+ UIAction *automatic = [UIAction actionWithTitle:@"Automatic" image:nil identifier:nil+ handler:^(UIAction *action) { SGLyricsChooseAutomatic(track); }];+ automatic.subtitle = current ? @"As the order chooses" : SGLyricsCreditFor(track);+ automatic.state = current ? UIMenuElementStateOff : UIMenuElementStateOn;+ NSMutableArray<UIMenuElement *> *items = [NSMutableArray arrayWithObject:automatic];for (NSString *key in SGLyricsOrder()) {SGLyricsResult *offer = offers[key];if (!offer) continue;SGLyricsProvider *provider = SGLyricsProviderFor(key);- if (!current && [credit containsString:provider.name]) current = key;UIAction *pick = [UIAction actionWithTitle:provider.name image:nil identifier:nilhandler:^(UIAction *action) { SGLyricsChooseSource(track, key); }];pick.subtitle = timingText(offer.karaokeLines);pick.state = [key isEqualToString:current] ? UIMenuElementStateOn : UIMenuElementStateOff;[items addObject:pick];}- if (!items.count) {+ if (items.count == 1) {UIAction *none = [UIAction actionWithTitle:@"No Source Has Lyrics" image:nil identifier:nil handler:^(UIAction *action) {}];none.attributes = UIMenuElementAttributesDisabled;[items addObject:none];diff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.mindex 13141bd1..26952eec 100644--- a/tweak/Sources/Shared/Lyrics/LyricsSettings.m+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m@@ -20,7 +20,8 @@ SGModSection *SGLyricsSourcesSection(BOOL namingSource) {NSUInteger count = SGImportedLRCFiles().count;return count ? @(count).stringValue : @"None";};- NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObjects:sources, imported,+ SGModRow *words = SGOptionRow(@"Prefer word-by-word timing", @"Asks down the order past lines timed by the line", SGKeyLyricsPreferWordTiming);+ NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObjects:sources, words, imported,SGSwitchRow(@"Lyrics for every track", @"Even where Spotify has none", SGKeyLyricsAllTracks), SGSpicyLyricsKeyRow(), nil];// Spicy Lyrics' terms ask for its credit wherever its lines show (Shared/LyricsSources/SpicyLyrics.m), so the switch// says so, or its credit under the lyrics reads as the switch not working (issue #20).diff --git a/tweak/Sources/Shared/LyricsSources/LyricsPick.m b/tweak/Sources/Shared/LyricsSources/LyricsPick.mindex 381d1279..4d398e52 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsPick.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsPick.m@@ -20,8 +20,19 @@ static const NSUInteger kAskedTracks = 10, kChosenTracks = 200;@implementation SGLyricsOfferAsk@end+// What a track showed before its first pick, the order's choice, for Automatic to put back.+@interface SGLyricsAutomatic : NSObject+@property (nonatomic, strong) id kept; // the walk's kept answer, as SGLyricsKeptAnswer reads it+@property (nonatomic, copy) NSString *credit;+@property (nonatomic, copy) NSArray<SGKaraokeLine *> *lines;+@end++@implementation SGLyricsAutomatic+@end+static NSMutableDictionary<NSString *, SGLyricsOfferAsk *> *sg_asks;static NSMutableDictionary<NSString *, NSString *> *sg_chosen;+static NSMutableDictionary<NSString *, SGLyricsAutomatic *> *sg_automatic; // the tracks in sg_chosenNSString *SGLyricsChosenSource(NSString *trackID) {return trackID ? sg_chosen[trackID] : nil;@@ -88,20 +99,48 @@ void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDictidispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(wait * NSEC_PER_SEC)), dispatch_get_main_queue(), once);}+// The track's lines and credit everywhere they show, at once.+static void show(NSString *trackID, NSString *credit, NSArray<SGKaraokeLine *> *lines) {+ // The credit before the lines, which the lyrics page asks for once it has them.+ SGLyricsSetCredit(trackID, credit);+ SGKaraokeKeepLines(trackID, lines);+ // Queued behind the keep above, so a page that drops its lines on this finds the new ones kept.+ dispatch_async(dispatch_get_main_queue(), ^{+ [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsSourceChosenNotification object:trackID];+ });+}+void SGLyricsChooseSource(NSString *trackID, NSString *key) {id result = sg_asks[trackID].answers[key];if (![result isKindOfClass:SGLyricsResult.class]) return;SGLyricsResult *lyrics = result;- if (!sg_chosen) sg_chosen = [NSMutableDictionary dictionary];- if (sg_chosen.count >= kChosenTracks) [sg_chosen removeAllObjects];+ if (!sg_chosen) {+ sg_chosen = [NSMutableDictionary dictionary];+ sg_automatic = [NSMutableDictionary dictionary];+ }+ if (sg_chosen.count >= kChosenTracks) {+ [sg_chosen removeAllObjects];+ [sg_automatic removeAllObjects];+ }+ if (!sg_chosen[trackID]) {+ SGLyricsAutomatic *automatic = [SGLyricsAutomatic new];+ automatic.kept = SGLyricsKeptAnswer(trackID);+ automatic.credit = SGLyricsCreditFor(trackID);+ automatic.lines = SGKaraokeLinesForTrack(trackID);+ sg_automatic[trackID] = automatic;+ }sg_chosen[trackID] = key;SGLog(@"lyrics: %@ picked for %@, %lu lines", key, trackID, (unsigned long)lyrics.karaokeLines.count);SGLyricsKeepChosen(trackID, lyrics);- // The credit before the lines, which the lyrics page asks for once it has them.- SGLyricsSetCredit(trackID, lyrics.provider);- SGKaraokeKeepLines(trackID, lyrics.karaokeLines);- // Queued behind the keep above, so a page that drops its lines on this finds the new ones kept.- dispatch_async(dispatch_get_main_queue(), ^{- [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsSourceChosenNotification object:trackID];- });+ show(trackID, lyrics.provider, lyrics.karaokeLines);+}++void SGLyricsChooseAutomatic(NSString *trackID) {+ SGLyricsAutomatic *automatic = trackID ? sg_automatic[trackID] : nil;+ if (!automatic) return;+ [sg_chosen removeObjectForKey:trackID];+ [sg_automatic removeObjectForKey:trackID];+ SGLog(@"lyrics: pick dropped for %@, back to %@, %lu lines", trackID, automatic.credit, (unsigned long)automatic.lines.count);+ SGLyricsRestoreKept(trackID, automatic.kept);+ show(trackID, automatic.credit, automatic.lines);}diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.h b/tweak/Sources/Shared/LyricsSources/LyricsSources.hindex cc021543..fb14bf1f 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.h+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.h@@ -13,6 +13,8 @@#define SGKeyLyricsProviders @"spotifyglass.lyricsProviders"// Offers the lyrics card on tracks Spotify itself has no lyrics for.#define SGKeyLyricsAllTracks @"spotifyglass.lyricsAllTracks"+// The walk goes on past a line-timed answer to the first source with words timed; read by every walk.+#define SGKeyLyricsPreferWordTiming @"spotifyglass.lyricsPreferWordTiming"// Names the source the shown lines came from, on the full screen page.#define SGKeyLyricsCredit @"spotifyglass.lyricsCredit"// The language a line's translation is asked for in, as an index into SGLyricsTranslationLanguages;@@ -239,7 +241,12 @@ void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDicti// Makes the offer of `key` the track's lyrics now, everywhere they show, and posts// SGLyricsSourceChosenNotification (object the track's id) once its lines are kept.void SGLyricsChooseSource(NSString *trackID, NSString *key);+// Drops the track's pick and puts back what the order had chosen, shown before the first pick, the same way.+void SGLyricsChooseAutomatic(NSString *trackID);extern NSNotificationName const SGLyricsSourceChosenNotification;// LyricsSources.m, for LyricsPick.m: the query a walk would start with, and a picked answer kept as the walk's.SGLyricsQuery *SGLyricsQueryFor(NSString *trackID);void SGLyricsKeepChosen(NSString *trackID, SGLyricsResult *result);+// The walk's kept answer for the track: a result, NSNull for none, nil when not kept; and that put back.+id SGLyricsKeptAnswer(NSString *trackID);+void SGLyricsRestoreKept(NSString *trackID, id kept);diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.mindex 9a353299..4f158128 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m@@ -425,11 +425,23 @@ static void finish(SGLyricsWalk *walk) {for (void (^done)(SGLyricsResult *) in waiting) done(lyrics);}+// Whether the walk has its answer. walk.merged is the best seen so far: betterLines keeps the finest timed+// lines, the first in the order among equals, so a walk run to the end takes words over a line's start over+// plain text. It stops at the first timed answer, or with Prefer word-by-word timing at the first with words+// timed; a source picked for the track is asked first and stands, timed by words or not.+static BOOL settled(SGLyricsWalk *walk) {+ SGLyricsResult *merged = walk.merged;+ if (!(merged.synced && merged.texts.count && merged.karaokeLines.count)) return NO;+ if (!SGFlag(SGKeyLyricsPreferWordTiming, NO) || SGLyricsChosenSource(walk.query.trackID)) return YES;+ if (SGKaraokeLinesTiming(merged.karaokeLines) == SGKaraokeTimingWords) return YES;+ if (walk.index < walk.order.count) SGLog(@"lyrics: %@ line timed by %@, asking on for words timed", walk.query.trackID, merged.provider);+ return NO;+}+static void step(SGLyricsWalk *walk) {SGLyricsQuery *query = walk.query;SGLyricsResult *merged = walk.merged;- // A source higher in the order has answered with timed lyrics: that is the answer.- if (merged.synced && merged.texts.count && merged.karaokeLines.count) {+ if (settled(walk)) {finish(walk);return;}@@ -646,7 +658,10 @@ UIViewController *SGLyricsSourcesPage(void) {NSString *detail = [provider.key isEqualToString:SGSpicyLyricsKey] ? SGSpicyLyricsStatus() ?: provider.detail : provider.detail;[all addObject:[SGSource sourceWithKey:provider.key name:provider.name detail:detail]];}- return SGSourcesPageMake(@"Lyrics sources", @"Asked top to bottom until one has word timing. Sources get only the track, never your account.",+ NSString *note = SGFlag(SGKeyLyricsPreferWordTiming, NO)+ ? @"Asked top to bottom until one has word timing. Sources get only the track, never your account."+ : @"Asked top to bottom until one has timed lyrics. Sources get only the track, never your account.";+ return SGSourcesPageMake(@"Lyrics sources", note,all, ^NSArray<NSString *> * { return SGLyricsOrder(); }, ^(NSArray<NSString *> *keys) { SGLyricsSetOrder(keys); });}@@ -673,3 +688,18 @@ void SGLyricsKeepChosen(NSString *trackID, SGLyricsResult *result) {sg_kept[trackID] = result;@synchronized (sg_missing) { [sg_missing removeObject:trackID]; }}++id SGLyricsKeptAnswer(NSString *trackID) {+ setUp();+ return sg_kept[trackID];+}++void SGLyricsRestoreKept(NSString *trackID, id kept) {+ setUp();+ if (kept) sg_kept[trackID] = kept;+ else [sg_kept removeObjectForKey:trackID];+ @synchronized (sg_missing) {+ if (kept == NSNull.null) [sg_missing addObject:trackID];+ else [sg_missing removeObject:trackID];+ }+}