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

refactor: one helper turns plain rows into untimed lyrics

My-Name-Is-Jeff4b8df7df5126
diff --git a/harness/genius-lyrics/build.sh b/harness/genius-lyrics/build.sh
index 217c33f5..aa1d4b0f 100755
--- a/harness/genius-lyrics/build.sh
+++ b/harness/genius-lyrics/build.sh
@@ -5,7 +5,7 @@ set -e
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/Genius.m" "$SRC/Shared/LyricsMeanings/Meanings.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \
+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" -DSG_VERSION=\"0.0.0\" \
+ "$HERE/check.m" "$SRC/Shared/LyricsSources/Genius.m" "$SRC/Shared/LyricsSources/LrcLib.m" "$SRC/Shared/LyricsMeanings/Meanings.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \
-framework UIKit -framework Foundation -o "$HERE/build/check"
"$HERE/build/check" "$@"
diff --git a/harness/genius-lyrics/check.m b/harness/genius-lyrics/check.m
index 7e94d1e2..da98dfa6 100644
--- a/harness/genius-lyrics/check.m
+++ b/harness/genius-lyrics/check.m
@@ -11,7 +11,7 @@
#define CHECK(cond) do { if (!(cond)) { fprintf(stderr, "FAILED line %d: %s\n", __LINE__, #cond); exit(1); } } while (0)
-// What the two files reach outside themselves for. The requests go to genius.com in live mode and
+// What the files reach outside themselves for. The requests go to genius.com in live mode and
// answer nothing otherwise.
@implementation SGLyricsResult
@end
@@ -20,6 +20,7 @@
NSInteger SGInt(NSString *key, NSInteger fallback) { return fallback; }
SGModRow *SGChoiceRow(NSString *title, NSString *subtitle, NSString *key, NSArray<NSString *> *choices, NSInteger fallback) { return nil; }
SPTPlayerTrack *SGKaraokeTrackFor(NSString *trackID) { return nil; }
+void SGLyricsPageLines(NSArray<SGKaraokeLine *> *lines, NSArray<NSNumber *> **starts, NSArray<NSString *> **texts) {}
NSURL *SGLyricsURL(NSString *base, NSDictionary<NSString *, NSString *> *query) {
NSURLComponents *url = [NSURLComponents componentsWithString:base];
NSMutableArray<NSURLQueryItem *> *items = [NSMutableArray array];
diff --git a/tweak/Sources/Shared/LyricsMeanings/Meanings.m b/tweak/Sources/Shared/LyricsMeanings/Meanings.m
index 2166fe96..4a38febe 100644
--- a/tweak/Sources/Shared/LyricsMeanings/Meanings.m
+++ b/tweak/Sources/Shared/LyricsMeanings/Meanings.m
@@ -161,19 +161,18 @@ static NSSet<NSString *> *leadNames(NSString *artist) {
return names;
}
-// Whether one of the song's own artists is the track's lead, the way Genius names them or without the
-// bracket ("BTS (방탄소년단)"); a featured singer or a translation page's "Genius English Translations"
+// Whether one of the song's own artists is the track's lead, the way Genius names them or by either name
+// of one it writes twice over ("BTS (방탄소년단)", "Дора (Dora)"); a featured singer or a translation page's "Genius English Translations"
// never is.
static BOOL byLead(NSDictionary *song, NSSet<NSString *> *leads) {
id primaries = song[@"primary_artists"];
for (NSDictionary *primary in [primaries isKindOfClass:NSArray.class] ? primaries : @[]) {
NSString *name = [primary isKindOfClass:NSDictionary.class] ? stringIn(primary[@"name"]) : nil;
if (!name) continue;
- if ([leads containsObject:folded(name)] || [leads containsObject:folded(bareTitle(name))]) return YES;
- // "Дора (Dora)": the name in the bracket is the one Spotify may use.
- NSRange open = [name rangeOfString:@"("], close = [name rangeOfString:@")" options:NSBackwardsSearch];
- if (open.location != NSNotFound && close.location != NSNotFound && close.location > NSMaxRange(open)
- && [leads containsObject:folded([name substringWithRange:NSMakeRange(NSMaxRange(open), close.location - NSMaxRange(open))])]) return YES;
+ NSArray<NSString *> *parts = [name componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"()"]];
+ for (NSString *part in [parts arrayByAddingObject:name]) {
+ if ([leads containsObject:folded(part)]) return YES;
+ }
}
return NO;
}
diff --git a/tweak/Sources/Shared/LyricsSources/Genius.m b/tweak/Sources/Shared/LyricsSources/Genius.m
index 1a0aa18b..ef4eb62e 100644
--- a/tweak/Sources/Shared/LyricsSources/Genius.m
+++ b/tweak/Sources/Shared/LyricsSources/Genius.m
@@ -103,24 +103,13 @@ SGLyricsAsk SGGeniusAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *r
NSURL *embed = [NSURL URLWithString:[NSString stringWithFormat:@"https://genius.com/songs/%@/embed.js", song]];
SGLyricsGetText(embed, ^(NSString *js) {
NSArray<NSString *> *rows = SGGeniusEmbedRows(js);
- SGLog(@"genius: %@ by %@ is song %@, %@", query.title, query.artist, song,
- rows ? [NSString stringWithFormat:@"%lu untimed lines", (unsigned long)rows.count] : @"no lines in its embed");
if (!rows) {
+ SGLog(@"genius: %@ by %@ is song %@, no lines in its embed", query.title, query.artist, song);
done(nil);
return;
}
- // As LrcLib.m takes its plain lyrics: every start 0, a ♪ where a stanza ends.
- NSMutableArray<NSNumber *> *starts = [NSMutableArray array];
- NSMutableArray<NSString *> *texts = [NSMutableArray array];
- for (NSString *row in rows) {
- [starts addObject:@0];
- [texts addObject:row.length ? row : @"♪"];
- }
- SGLyricsResult *result = [SGLyricsResult new];
- result.starts = starts;
- result.texts = texts;
- result.karaokeLines = SGKaraokeStaticLines(texts);
- done(result);
+ SGLog(@"genius: %@ by %@ is song %@, %lu untimed lines", query.title, query.artist, song, (unsigned long)rows.count);
+ done(SGLyricsPlainResult(rows));
});
});
};
diff --git a/tweak/Sources/Shared/LyricsSources/LrcLib.m b/tweak/Sources/Shared/LyricsSources/LrcLib.m
index 7fca41de..7676a9fe 100644
--- a/tweak/Sources/Shared/LyricsSources/LrcLib.m
+++ b/tweak/Sources/Shared/LyricsSources/LrcLib.m
@@ -87,6 +87,20 @@ SGLyricsResult *SGLyricsLRCResult(NSString *lrc) {
return syncedResult([lrc isKindOfClass:NSString.class] ? linesFromLRC(lrc) : nil);
}
+SGLyricsResult *SGLyricsPlainResult(NSArray<NSString *> *rows) {
+ NSMutableArray<NSNumber *> *starts = [NSMutableArray array];
+ NSMutableArray<NSString *> *texts = [NSMutableArray array];
+ for (NSString *row in rows) {
+ [starts addObject:@0];
+ [texts addObject:row.length ? row : @"♪"];
+ }
+ SGLyricsResult *result = [SGLyricsResult new];
+ result.starts = starts;
+ result.texts = texts;
+ result.karaokeLines = SGKaraokeStaticLines(texts);
+ return result;
+}
+
// wordLines: the record's Lyricsfile as lines, nil when it has none this reads.
static SGLyricsResult *resultFrom(NSDictionary *record, NSArray<SGKaraokeLine *> *wordLines) {
if (![record isKindOfClass:NSDictionary.class]) return nil;
@@ -106,16 +120,7 @@ static SGLyricsResult *resultFrom(NSDictionary *record, NSArray<SGKaraokeLine *>
if (timed) return timed;
// Nothing timed, but the words still beat an empty page when no other source has any.
if (![plain isKindOfClass:NSString.class] || ![plain length]) return nil;
- NSMutableArray<NSNumber *> *starts = [NSMutableArray array];
- NSMutableArray<NSString *> *texts = [NSMutableArray array];
- for (NSString *row in [plain componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) {
- [starts addObject:@0];
- [texts addObject:row.length ? row : @"♪"];
- }
- result.starts = starts;
- result.texts = texts;
- result.karaokeLines = SGKaraokeStaticLines(texts);
- return result;
+ return SGLyricsPlainResult([plain componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]);
}
// Calls back on the main queue, where it is called. A Lyricsfile is read on another queue: a long one
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.h b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
index 86514cd8..44cd4b21 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.h
+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
@@ -178,6 +178,8 @@ SGLyricsResult *SGLyricsLRCResult(NSString *lrc);
// Lyricsfile.m. LRCLIB's Lyricsfile YAML as word timed lines; nil when it times no word, or is not
// a Lyricsfile 1.0 this reads.
NSArray<SGKaraokeLine *> *SGLyricsfileLines(NSString *yaml);
+// Untimed rows as a result: every start 0, a ♪ for each empty row.
+SGLyricsResult *SGLyricsPlainResult(NSArray<NSString *> *rows);
// NetEase.m. Word timed lines from NetEase's yrc, or with krc from KuGou's KRC text; nil for none.
NSArray<SGKaraokeLine *> *SGLyricsPieceLines(NSString *body, BOOL krc);
// QQMusic.m, for it and KuGou. A title as the two are matched by: lowercased, without spaces,