Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: a Lyricsfile whose end_ms is null keeps its word timing
My-Name-Is-Jeff26b3fd4c9ed9
diff --git a/harness/lyrics-sources/check.m b/harness/lyrics-sources/check.mindex 5e3b9ef4..f86b57a5 100644--- a/harness/lyrics-sources/check.m+++ b/harness/lyrics-sources/check.m@@ -333,6 +333,12 @@ int main(int argc, char **argv) {@[@"- text: a", @"- text: \"\\u1\U0001F600\""]]) {CHECK(!SGLyricsfileLines([wordFile stringByReplacingOccurrencesOfString:swap[0] withString:swap[1]]));}+ // An end written as YAML's null, on a line or a word, is no end: the line stops a second past its last word.+ for (NSString *null in @[@"null", @"~", @""]) {+ lf = SGLyricsfileLines([wordFile stringByReplacingOccurrencesOfString:@" start_ms: 10\n"+ withString:[NSString stringWithFormat:@" start_ms: 10\n end_ms: %@\n end_ms: %@\n", null, null]]);+ CHECK(lf.count == 1 && lf[0].words.count == 1 && lf[0].end == 1010);+ }// YAML's other escapes, a block whose header gives its indent, and lines listed out of time order.lf = SGLyricsfileLines([wordFile stringByAppendingString:@"- text: \"b\\Lc\\N\"\n start_ms: 5\n words:\n - text: \"b\\Lc\"\n start_ms: 5\nplain: |2\n a\n b\n"]);CHECK(lf.count == 2 && lf[0].start == 5 && [lf[0].words[0].text isEqualToString:@"b\u2028c"]);diff --git a/tweak/Sources/Shared/LyricsSources/Lyricsfile.m b/tweak/Sources/Shared/LyricsSources/Lyricsfile.mindex f0e49255..05313d67 100644--- a/tweak/Sources/Shared/LyricsSources/Lyricsfile.m+++ b/tweak/Sources/Shared/LyricsSources/Lyricsfile.m@@ -295,6 +295,13 @@ static NSInteger msOf(id value) {return [value integerValue];}+// Whether a line or word has an end of its own. end_ms is optional, and a writer that dumps its every field+// spells a missing one as YAML's null (`end_ms: null`, `~`, or nothing), which is no end rather than a bad one.+static BOOL endGiven(NSDictionary *raw) {+ id end = raw[@"end_ms"];+ return end && end != NSNull.null && ![@[@"null", @"Null", @"NULL", @"~"] containsObject:end];+}+// Where a line without an end of its own, or of its last word, is taken to stop.static const NSInteger kTailMs = 1000;@@ -304,16 +311,16 @@ static SGKaraokeLine *wordLine(NSArray *rawWords, NSInteger start, NSInteger endNSInteger lineEnd = end;if (lineEnd < 0) {NSDictionary *last = rawWords.lastObject;- lineEnd = msOf(last[@"end_ms"]) >= 0 ? msOf(last[@"end_ms"]) : msOf(last[@"start_ms"]) + kTailMs;+ lineEnd = endGiven(last) ? msOf(last[@"end_ms"]) : msOf(last[@"start_ms"]) + kTailMs;}NSCharacterSet *space = NSCharacterSet.whitespaceAndNewlineCharacterSet;NSMutableArray<SGKaraokePiece *> *pieces = [NSMutableArray array];for (NSUInteger i = 0; i < rawWords.count; i++) {NSDictionary *raw = rawWords[i];NSString *said = raw[@"text"];- NSInteger wordStart = msOf(raw[@"start_ms"]), wordEnd = msOf(raw[@"end_ms"]);+ NSInteger wordStart = msOf(raw[@"start_ms"]), wordEnd = endGiven(raw) ? msOf(raw[@"end_ms"]) : -1;if (![said isKindOfClass:NSString.class] || wordStart < 0) return nil;- if (raw[@"end_ms"] && wordEnd < wordStart) return nil;+ if (endGiven(raw) && wordEnd < wordStart) return nil;if (wordEnd < 0) wordEnd = i + 1 < rawWords.count ? msOf(rawWords[i + 1][@"start_ms"]) : lineEnd;SGKaraokePiece *piece = [SGKaraokePiece new];piece.text = [said stringByTrimmingCharactersInSet:space];@@ -338,8 +345,8 @@ NSArray<SGKaraokeLine *> *SGLyricsfileLines(NSString *yaml) {if (![raw isKindOfClass:NSDictionary.class]) return nil;NSString *text = raw[@"text"];NSArray *words = raw[@"words"];- NSInteger start = msOf(raw[@"start_ms"]), end = msOf(raw[@"end_ms"]);- if (![text isKindOfClass:NSString.class] || start < 0 || (raw[@"end_ms"] && end < start)) return nil;+ NSInteger start = msOf(raw[@"start_ms"]), end = endGiven(raw) ? msOf(raw[@"end_ms"]) : -1;+ if (![text isKindOfClass:NSString.class] || start < 0 || (endGiven(raw) && end < start)) return nil;if (words && ![words isKindOfClass:NSArray.class]) {if (words != (id)NSNull.null) return nil;words = nil;