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: LRCLIB's search keeps a record whose artists are joined by a word

My-Name-Is-Jeffd4622f6c9454
diff --git a/harness/lyrics-sources/check.m b/harness/lyrics-sources/check.m
index 04293ee7..97f97f35 100644
--- a/harness/lyrics-sources/check.m
+++ b/harness/lyrics-sources/check.m
@@ -403,6 +403,12 @@ int main(int argc, char **argv) {
found = @[@{@"id": @8, @"trackName": @"a - Live", @"artistName": @"b, x", @"duration": @200, @"hasWordSync": @YES, @"syncedLyrics": twoLines, @"lyricsfile": wordFile}];
got = lrclibAnswer(query, nil);
CHECK(got.wordTimed && got.karaokeLines.count == 1);
+ // The artists joined by a word or by punctuation, in either order, as LRCLIB's records write them.
+ for (NSString *joined in @[@"b and x", @"B And X", @"x; b", @"B/X/B/X", @"b x x", @"x • b", @"b vs. x"]) {
+ found = @[@{@"id": @12, @"trackName": @"a", @"artistName": joined, @"duration": @200, @"syncedLyrics": twoLines}];
+ got = lrclibAnswer(query, nil);
+ CHECK(got.synced && got.karaokeLines.count == 2);
+ }
// A record's words count once its Lyricsfile reads: one whose file cannot be read is weighed on its LRC,
// so the words of a record further off win, and with no file that reads the closer LRC does.
NSDictionary *unreadable = @{@"id": @9, @"trackName": @"a", @"artistName": @"b", @"duration": @202, @"hasWordSync": @YES, @"syncedLyrics": twoLines, @"lyricsfile": @"version: '9'"};
diff --git a/tweak/Sources/Shared/LyricsSources/LrcLib.m b/tweak/Sources/Shared/LyricsSources/LrcLib.m
index 7acfac6f..912c5d9b 100644
--- a/tweak/Sources/Shared/LyricsSources/LrcLib.m
+++ b/tweak/Sources/Shared/LyricsSources/LrcLib.m
@@ -143,7 +143,7 @@ static BOOL betterRecord(NSDictionary *record, NSDictionary *best, NSInteger sec
// The search ranks by its own lights, and its first hit is often another song of the artist's or the
// song by someone else, so a record has to be the track (SongMatch.m) before its timing counts. The
-// artists are written as one name, "A, B" for several.
+// artists are written as one name, joined however the uploader's tags had them.
static NSArray<NSDictionary *> *matching(id found, SGLyricsQuery *query) {
NSMutableArray<NSDictionary *> *records = [NSMutableArray array];
for (NSDictionary *record in [found isKindOfClass:NSArray.class] ? found : @[]) {
@@ -151,7 +151,7 @@ static NSArray<NSDictionary *> *matching(id found, SGLyricsQuery *query) {
NSInteger length = (NSInteger)[record[@"duration"] doubleValue];
if (query.seconds > 0 && length > 0 && labs(length - query.seconds) > kLengthSlack) continue;
NSString *artists = [record[@"artistName"] isKindOfClass:NSString.class] ? record[@"artistName"] : @"";
- if (!SGLyricsSongRank(query.title, query.artist, record[@"trackName"], [artists componentsSeparatedByString:@", "])) continue;
+ if (!SGLyricsSongRank(query.title, query.artist, record[@"trackName"], @[artists])) continue;
[records addObject:record];
}
return records;
diff --git a/tweak/Sources/Shared/LyricsSources/SongMatch.m b/tweak/Sources/Shared/LyricsSources/SongMatch.m
index 9aea4363..230deb05 100644
--- a/tweak/Sources/Shared/LyricsSources/SongMatch.m
+++ b/tweak/Sources/Shared/LyricsSources/SongMatch.m
@@ -72,14 +72,27 @@ static NSSet<NSString *> *leadNames(NSString *artist) {
return names;
}
+// A catalog writes several artists as one name, joined by punctuation ("A & B", "A/B", "A; B", "A, B") or a
+// word ("A and B", "A x B"), in either order; LRCLIB has every one of these. Lowercase " x " only: " X " ends
+// Lil Nas X.
+static NSArray<NSString *> *namesJoinedIn(NSString *name) {
+ NSMutableString *split = [name mutableCopy];
+ for (NSString *joiner in @[@"&", @"/", @";", @"+", @"•", @",", @" and ", @" with ", @" vs ", @" vs. "]) {
+ [split replaceOccurrencesOfString:joiner withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0, split.length)];
+ }
+ [split replaceOccurrencesOfString:@" x " withString:@"\n" options:0 range:NSMakeRange(0, split.length)];
+ return [split componentsSeparatedByString:@"\n"];
+}
+
// Whether one of the song's own artists is the track's lead, by either name of one written twice over
-// ("BTS (방탄소년단)", "Дора (Dora)") or by the name before its " feat."; a featured singer or a translation
-// page's "Genius English Translations" never is.
+// ("BTS (방탄소년단)", "Дора (Dora)"), by the name before its " feat.", or by one of the names joined in it;
+// a featured singer or a translation page's "Genius English Translations" never is.
static BOOL byLead(NSArray<NSString *> *songArtists, NSSet<NSString *> *leads) {
for (NSString *name in songArtists) {
if (![name isKindOfClass:NSString.class]) continue;
NSArray<NSString *> *parts = [name componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"()"]];
- for (NSString *part in [parts arrayByAddingObjectsFromArray:@[name, SGLyricsLeadArtist(name)]]) {
+ parts = [parts arrayByAddingObjectsFromArray:@[name, SGLyricsLeadArtist(name)]];
+ for (NSString *part in [parts arrayByAddingObjectsFromArray:namesJoinedIn(name)]) {
if ([leads containsObject:SGLyricsFoldedText(part)]) return YES;
}
}