Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: NetEase, KuGou and Musixmatch no longer end a joined word before its pieces are sung
My-Name-Is-Jeff8ec3eb27c81c
diff --git a/harness/lyrics-sources/README.md b/harness/lyrics-sources/README.mdindex 02e9cd3c..ce5d2420 100644--- a/harness/lyrics-sources/README.md+++ b/harness/lyrics-sources/README.md@@ -7,6 +7,9 @@Japanese lines split as before. The pieces are printed, so a script the system does not split shows;- KuGou's KRC (`KuGou.m`, read by `SGLyricsPieceLines` in `NetEase.m`): packed here the way KuGou packsit, then unpacked and read, with the word times, the joining and the line ends checked;+- NetEase's yrc and Musixmatch's richsync (`Musixmatch.m`), whose pieces `SGKaraokePieceLine` in+ `KaraokeTiming.m` runs together into words, as the Lyricsfile's are: which pieces join, and where each+ word and line ends;- the QQ Music and KuGou asks against made-up search replies: titles, singers and lengths that do notfit are passed over, the closest KuGou lengths are tried first and at most three, and QQ's LRC is read.- LRCLIB's Lyricsfile (`Lyricsfile.m`): the spec's example and LRCLIB's own way of writing it read as worddiff --git a/harness/lyrics-sources/build.sh b/harness/lyrics-sources/build.shindex 80949480..54ddc13e 100755--- a/harness/lyrics-sources/build.sh+++ b/harness/lyrics-sources/build.sh@@ -7,6 +7,6 @@ SRC=$(cd "$HERE/../../tweak/Sources" && pwd)LS="$SRC/Shared/LyricsSources"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" -DSG_VERSION=\"0.0.0\" \- "$HERE/check.m" "$LS/KuGou.m" "$LS/QQMusic.m" "$LS/NetEase.m" "$LS/LrcLib.m" "$LS/Lyricsfile.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \+ "$HERE/check.m" "$LS/KuGou.m" "$LS/QQMusic.m" "$LS/NetEase.m" "$LS/Musixmatch.m" "$LS/LrcLib.m" "$LS/Lyricsfile.m" "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \-framework UIKit -framework Foundation -lz -o "$HERE/build/check""$HERE/build/check" "$@"diff --git a/harness/lyrics-sources/check.m b/harness/lyrics-sources/check.mindex 124f64f5..5e3b9ef4 100644--- a/harness/lyrics-sources/check.m+++ b/harness/lyrics-sources/check.m@@ -34,6 +34,9 @@ NSURL *SGLyricsURL(NSString *base, NSDictionary<NSString *, NSString *> *query)url.queryItems = items;return url.URL;}+// Musixmatch.m asks these of a local file, which no check here plays.+BOOL SGLocalFileIs(NSString *uri) { return NO; }+NSDictionary<NSString *, id> *SGLocalFileInfo(NSString *uri) { return nil; }static id (^sg_answer)(NSURL *url, id body);void SGLyricsGetJSON(NSURL *url, NSDictionary *headers, void (^done)(id root)) { done(sg_answer(url, nil)); }void SGLyricsPostJSON(NSURL *url, NSDictionary *headers, id body, void (^done)(id root)) { done(sg_answer(url, body)); }@@ -172,6 +175,45 @@ int main(int argc, char **argv) {CHECK(lines[1].words.count == 3 && [SGKaraokeLineText(lines[1]) isEqualToString:@"你好啊"]);CHECK(lines[1].words[1].joined && lines[1].words[2].start == 4800 && lines[1].words[2].end == 4801);CHECK(lines[2].end == 7300);+ // NetEase's yrc, timed from the track's start: "wan" runs on into "ted ", and a piece after one+ // with no space after it runs on into it even when it opens with a space of its own.+ lines = SGLyricsPieceLines(@"[1000,3000](1000,200,0)wan(1200,300,0)ted (1500,0,0)to(1600,100,0) go\n"+ "[5000,1000](5000,100,0)你(5100,100,0)好", NO);+ CHECK(lines.count == 2 && [SGKaraokeLineText(lines[0]) isEqualToString:@"wanted togo"]);+ CHECK(lines[0].words[0].start == 1000 && lines[0].words[0].end == 1500 && !lines[0].words[0].joined);+ CHECK(lines[0].words[1].start == 1500 && lines[0].words[1].end == 1700 && !lines[0].words[1].joined);+ CHECK(lines[0].start == 1000 && lines[0].end == 4000);+ CHECK(lines[1].words.count == 2 && lines[1].words[1].joined && lines[1].words[1].start == 5100 && lines[1].end == 6000);+ CHECK(!SGLyricsPieceLines(@"[1000,3000]", NO) && !SGLyricsPieceLines(@"", NO));+ // A piece run on into a word that is sung longer leaves the word's end where it was.+ lines = SGLyricsPieceLines(@"[1000,500](1000,800,0)ab(1200,100,0)cd ", NO);+ CHECK(lines.count == 1 && lines[0].words.count == 1 && lines[0].words[0].end == 1800 && lines[0].end == 1800);++ // Musixmatch's richsync: an entry's offset is from its line's start, and only an entry of spaces+ // ends a word, so "Mil" "ion" is one word and "ab" " cd" another. A word is sung until the next+ // word starts, the last until a space after it or the line's end; a syllable of an unspaced+ // script is a word of its own, joined to the one before.+ SGLyricsResult *rich = SGMusixmatchRichsyncResult(@[+ @{@"ts": @10, @"te": @14, @"x": @"Milion +, go", @"l": @[@{@"c": @"Mil", @"o": @0}, @{@"c": @"ion", @"o": @0.3}, @{@"c": @" ", @"o": @0.6},+ @{@"c": @"+", @"o": @0.8}, @{@"c": @",", @"o": @0.9}, @{@"c": @" ", @"o": @1.0}, @{@"c": @"go", @"o": @1.5}]},+ @{@"ts": @20, @"te": @22, @"l": @[@{@"c": @"a", @"o": @0}, @{@"c": @" ", @"o": @0.5}]},+ @{@"ts": @30, @"te": @31, @"l": @[@{@"c": @"日", @"o": @0}, @{@"c": @"本", @"o": @0}]},+ @{@"ts": @40, @"te": @42, @"l": @[@{@"c": @"ab", @"o": @0}, @{@"c": @" cd", @"o": @0.5}, @{@"c": @5, @"o": @0.7}]},+ @{@"ts": @50, @"te": @51, @"l": @[@{@"c": @" ", @"o": @0}]},+ ]);+ NSArray<SGKaraokeLine *> *rl = rich.karaokeLines;+ CHECK(rich.wordTimed && rl.count == 4);+ CHECK([SGKaraokeLineText(rl[0]) isEqualToString:@"Milion +, go"] && rl[0].start == 10000 && rl[0].end == 14000);+ CHECK(rl[0].words[0].start == 10000 && rl[0].words[0].end == 10800 && rl[0].words[1].start == 10800 && rl[0].words[1].end == 11500);+ CHECK(rl[0].words[2].start == 11500 && rl[0].words[2].end == 14000 && !rl[0].words[1].joined && !rl[0].words[2].joined);+ CHECK(rl[1].words.count == 1 && rl[1].words[0].end == 20500 && rl[1].end == 22000);+ CHECK(rl[2].words.count == 2 && rl[2].words[0].end == 30000 && rl[2].words[1].joined && rl[2].words[1].end == 31000);+ CHECK([SGKaraokeLineText(rl[3]) isEqualToString:@"abcd"] && rl[3].words[0].start == 40000 && rl[3].words[0].end == 42000);+ CHECK(([rich.texts isEqualToArray:@[@"Milion +, go", @"♪", @"a", @"♪", @"日本", @"♪", @"abcd", @""]]));+ CHECK(!SGMusixmatchRichsyncResult(@[]) && !SGMusixmatchRichsyncResult(@"x"));+ // An entry run on into a word after the line's end is sung to its own end, not cut off before it.+ rl = SGMusixmatchRichsyncResult(@[@{@"ts": @60, @"te": @61, @"l": @[@{@"c": @"ab", @"o": @0}, @{@"c": @"cd", @"o": @2}]}]).karaokeLines;+ CHECK(rl.count == 1 && rl[0].words.count == 1 && rl[0].words[0].end == 62000 && rl[0].end == 62000);CHECK(!SGKuGouLines(packed(kKRC, @"krc2")) && !SGKuGouLines(@"bm90IGtyYw==") && !SGKuGouLines(nil));CHECK(!SGKuGouLines(packed(@"[ar:only tags]", @"krc1")));diff --git a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m b/tweak/Sources/Shared/Lyrics/KaraokeTiming.mindex 34622550..7da2b0a0 100644--- a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m+++ b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m@@ -79,6 +79,47 @@ BOOL SGKaraokeUnspacedScript(NSString *text) {return text.length && [text rangeOfCharacterFromSet:unspacedScript()].location != NSNotFound;}+@implementation SGKaraokePiece+@end++SGKaraokeLine *SGKaraokePieceLine(NSArray<SGKaraokePiece *> *pieces, NSInteger start, NSInteger end) {+ NSMutableArray<SGKaraokeWord *> *words = [NSMutableArray array];+ SGKaraokeWord *open = nil; // the word the next piece runs on into+ BOOL spaced = YES; // a space has gone by, so the next word is not joined to the last+ for (SGKaraokePiece *piece in pieces) {+ if (piece.spaceBefore) {+ open = nil;+ spaced = YES;+ }+ // A source times a Chinese or Japanese syllable a piece at a time and never spaces them, so+ // running them together would light a line up whole instead of sweeping it.+ BOOL unspaced = SGKaraokeUnspacedScript(piece.text);+ if (piece.text.length && open && !unspaced) {+ open.text = [open.text stringByAppendingString:piece.text];+ open.end = MAX(open.end, piece.end);+ } else if (piece.text.length) {+ SGKaraokeWord *word = [SGKaraokeWord new];+ word.text = piece.text;+ word.start = piece.start;+ word.end = piece.end;+ word.joined = !spaced;+ [words addObject:word];+ open = unspaced ? nil : word;+ spaced = NO;+ }+ if (!piece.text.length || piece.spaceAfter) {+ open = nil;+ spaced = YES;+ }+ }+ if (!words.count) return nil;+ SGKaraokeLine *line = [SGKaraokeLine new];+ line.words = words;+ line.start = start;+ line.end = MAX(end, words.lastObject.end);+ return line;+}+// Thai, Lao, Burmese and Khmer, which leave no space between words either, but whose syllables are a// letter with marks around it: they are split where the system's dictionary finds a word, not a// character at a time.diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.hindex 2184786d..5c60fb84 100644--- a/tweak/Sources/Shared/Lyrics/Lyrics.h+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h@@ -105,6 +105,19 @@ void SGKaraokeAlignVoices(NSArray<SGKaraokeLine *> *lines);// A color-lyrics body, protobuf or JSON, as lines: timed by the line where Spotify synced it, plain// (SGKaraokeTimingNone) where it did not; nil for a body with no lines.NSArray<SGKaraokeLine *> *SGKaraokeLinesFromBody(NSData *body);+// One timed piece of a line as a source sends it, before the pieces are run together into words: its+// text without the spaces around it, when it is sung, and whether a space stood before or after it. A+// piece with no text is a space.+@interface SGKaraokePiece : NSObject+@property (nonatomic, copy) NSString *text;+@property (nonatomic) NSInteger start, end;+@property (nonatomic) BOOL spaceBefore, spaceAfter;+@end+// A line timed by the word from its pieces. A piece with no space between it and the one before runs+// on into that one's word ("wan", "ted" is "wanted"), sung until the later of the two ends; a piece of+// an unspaced script is a word of its own, joined to the one before. The line ends at `end`, or at its+// last word when that is later. nil when no piece has text.+SGKaraokeLine *SGKaraokePieceLine(NSArray<SGKaraokePiece *> *pieces, NSInteger start, NSInteger end);// Lines timed only by their starts, the words inside them estimated; a ♪ or empty text is a break.NSArray<SGKaraokeLine *> *SGKaraokeEstimatedLines(NSArray<NSNumber *> *starts, NSArray<NSString *> *texts);// Lines with no time at all, for lyrics that come as plain text; a ♪ or empty text is dropped.diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.h b/tweak/Sources/Shared/LyricsSources/LyricsSources.hindex e9acfa5e..8b5e39c4 100644--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.h+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.h@@ -160,6 +160,8 @@ void SGMusixmatchTranslations(NSString *trackID, NSString *language, void (^doneNSString *SGMusixmatchLineKey(NSString *text);// Copies of the lines with the translations matched in, in a new array; nil when none matched.NSArray<SGKaraokeLine *> *SGMusixmatchTranslatedLines(NSArray<SGKaraokeLine *> *lines, NSDictionary<NSString *, NSString *> *byLine);+// A richsync body, the JSON array its richsync_body holds, as word timed lines; nil when it has none.+SGLyricsResult *SGMusixmatchRichsyncResult(id body);extern SGLyricsAsk SGUnisonAsk;extern SGLyricsAsk SGNetEaseAsk;extern SGLyricsAsk SGLrcLibAsk;diff --git a/tweak/Sources/Shared/LyricsSources/Lyricsfile.m b/tweak/Sources/Shared/LyricsSources/Lyricsfile.mindex b4656986..f0e49255 100644--- a/tweak/Sources/Shared/LyricsSources/Lyricsfile.m+++ b/tweak/Sources/Shared/LyricsSources/Lyricsfile.m@@ -298,17 +298,16 @@ static NSInteger msOf(id value) {// Where a line without an end of its own, or of its last word, is taken to stop.static const NSInteger kTailMs = 1000;-// A word timed line, the segments of a spaced script run together into whole words as NetEase's are:-// a segment the spec writes without the space after it ("wan", "ted ") goes on into the next one.+// A word timed line. A segment the spec writes without the space after it ("wan", "ted ") goes on+// into the next one, and one written with a space in front starts a word of its own.static SGKaraokeLine *wordLine(NSArray *rawWords, NSInteger start, NSInteger end) {NSInteger lineEnd = end;if (lineEnd < 0) {NSDictionary *last = rawWords.lastObject;lineEnd = msOf(last[@"end_ms"]) >= 0 ? msOf(last[@"end_ms"]) : msOf(last[@"start_ms"]) + kTailMs;}- NSMutableArray<SGKaraokeWord *> *words = [NSMutableArray array];- SGKaraokeWord *open = nil;- BOOL spaced = YES;+ 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"];@@ -316,37 +315,15 @@ static SGKaraokeLine *wordLine(NSArray *rawWords, NSInteger start, NSInteger endif (![said isKindOfClass:NSString.class] || wordStart < 0) return nil;if (raw[@"end_ms"] && wordEnd < wordStart) return nil;if (wordEnd < 0) wordEnd = i + 1 < rawWords.count ? msOf(rawWords[i + 1][@"start_ms"]) : lineEnd;- wordEnd = MAX(wordEnd, wordStart + 1); // a word of no length still shows, for a moment- NSString *trimmed = [said stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];- if (said.length && [NSCharacterSet.whitespaceAndNewlineCharacterSet characterIsMember:[said characterAtIndex:0]]) {- open = nil;- spaced = YES;- }- BOOL unspaced = SGKaraokeUnspacedScript(trimmed);- if (trimmed.length && open && !unspaced) {- open.text = [open.text stringByAppendingString:trimmed];- open.end = MAX(open.end, wordEnd);- } else if (trimmed.length) {- SGKaraokeWord *word = [SGKaraokeWord new];- word.text = trimmed;- word.start = wordStart;- word.end = wordEnd;- word.joined = !spaced;- [words addObject:word];- open = unspaced ? nil : word;- spaced = NO;- }- if (!trimmed.length || [NSCharacterSet.whitespaceAndNewlineCharacterSet characterIsMember:[said characterAtIndex:said.length - 1]]) {- open = nil;- spaced = YES;- }+ SGKaraokePiece *piece = [SGKaraokePiece new];+ piece.text = [said stringByTrimmingCharactersInSet:space];+ piece.start = wordStart;+ piece.end = MAX(wordEnd, wordStart + 1); // a word of no length still shows, for a moment+ piece.spaceBefore = said.length && [space characterIsMember:[said characterAtIndex:0]];+ piece.spaceAfter = said.length && [space characterIsMember:[said characterAtIndex:said.length - 1]];+ [pieces addObject:piece];}- if (!words.count) return nil;- SGKaraokeLine *line = [SGKaraokeLine new];- line.words = words;- line.start = start;- line.end = MAX(lineEnd, words.lastObject.end);- return line;+ return SGKaraokePieceLine(pieces, start, lineEnd);}NSArray<SGKaraokeLine *> *SGLyricsfileLines(NSString *yaml) {diff --git a/tweak/Sources/Shared/LyricsSources/Musixmatch.m b/tweak/Sources/Shared/LyricsSources/Musixmatch.mindex 596f77e9..e958a950 100644--- a/tweak/Sources/Shared/LyricsSources/Musixmatch.m+++ b/tweak/Sources/Shared/LyricsSources/Musixmatch.m@@ -119,48 +119,29 @@ static void withToken(void (^use)(NSString *token)) {// o is from the line's start. A space entry ends the word before it; a word can come in more than// one entry ("Milion", "+", ","), so everything between two spaces is one word.static SGKaraokeLine *richsyncLine(NSDictionary *entry, NSInteger start, NSInteger end) {- NSMutableArray<SGKaraokeWord *> *words = [NSMutableArray array];- BOOL open = NO; // the word last added may still take further entries- BOOL spaced = YES; // a space has gone by since the last word, so the next one is not joined+ NSMutableArray<SGKaraokePiece *> *pieces = [NSMutableArray array];id parts = entry[@"l"];for (NSDictionary *part in [parts isKindOfClass:NSArray.class] ? parts : @[]) {id text = dig(part, @"c");if (![text isKindOfClass:NSString.class]) continue;- NSInteger at = start + msOf(part[@"o"]);- NSString *trimmed = [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];- SGKaraokeWord *last = words.lastObject;- if (!trimmed.length) {- last.end = MAX(at, last.start);- open = NO;- spaced = YES;- continue;- }- if (open && !SGKaraokeUnspacedScript(trimmed)) {- last.text = [last.text stringByAppendingString:trimmed];- continue;- }- // A syllable of an unspaced script stands as a word of its own. Musixmatch times each one,- // but sends no space to end it, so running them together is what left a Japanese or Chinese- // line lighting up whole instead of sweeping.- last.end = MAX(at, last.start);- SGKaraokeWord *word = [SGKaraokeWord new];- word.text = trimmed;- word.start = at;- word.end = MAX(end, at);- word.joined = !spaced;- [words addObject:word];- open = !SGKaraokeUnspacedScript(trimmed);- spaced = NO;+ SGKaraokePiece *piece = [SGKaraokePiece new];+ piece.text = [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];+ piece.start = start + msOf(part[@"o"]);+ [pieces addObject:piece];+ }+ // An entry has no end of its own: a word is sung until the next one starts, past any space between+ // them, and the last until the space after it or the line's end.+ NSInteger until = end;+ BOOL passed = NO; // a word or a space comes after this entry+ for (SGKaraokePiece *piece in pieces.reverseObjectEnumerator) {+ if (piece.text.length) piece.end = MAX(until, piece.start);+ if (piece.text.length || !passed) until = piece.start;+ passed = YES;}- if (!words.count) return nil;- SGKaraokeLine *line = [SGKaraokeLine new];- line.words = words;- line.start = start;- line.end = MAX(end, words.lastObject.end);- return line;+ return SGKaraokePieceLine(pieces, start, end);}-static SGLyricsResult *fromRichsync(id body) {+SGLyricsResult *SGMusixmatchRichsyncResult(id body) {if (![body isKindOfClass:NSArray.class]) return nil;NSMutableArray<NSNumber *> *starts = [NSMutableArray array];NSMutableArray<NSString *> *texts = [NSMutableArray array];@@ -231,7 +212,7 @@ static SGLyricsResult *fromCalls(NSDictionary *calls) {if (truthy(dig(calls, @"matcher.track.get/message/body/track/instrumental"))) return nil;id richsync = dig(calls, @"track.richsync.get/message/body/richsync");SGLyricsResult *lyrics = nil;- if (richsync && !truthy(dig(richsync, @"restricted"))) lyrics = fromRichsync(jsonOf(dig(richsync, @"richsync_body")));+ if (richsync && !truthy(dig(richsync, @"restricted"))) lyrics = SGMusixmatchRichsyncResult(jsonOf(dig(richsync, @"richsync_body")));if (lyrics) return lyrics;id list = dig(calls, @"track.subtitles.get/message/body/subtitle_list");id subtitle = [list isKindOfClass:NSArray.class] && [list count] ? dig([list firstObject], @"subtitle") : nil;diff --git a/tweak/Sources/Shared/LyricsSources/NetEase.m b/tweak/Sources/Shared/LyricsSources/NetEase.mindex bd883576..d58f3930 100644--- a/tweak/Sources/Shared/LyricsSources/NetEase.m+++ b/tweak/Sources/Shared/LyricsSources/NetEase.m@@ -47,43 +47,21 @@ NSArray<SGKaraokeLine *> *SGLyricsPieceLines(NSString *body, BOOL krc) {if (!head) continue;NSArray<NSTextCheckingResult *> *pieces = [piece matchesInString:row options:0 range:NSMakeRange(NSMaxRange(head.range), row.length - NSMaxRange(head.range))];NSInteger lineStart = [row substringWithRange:[head rangeAtIndex:1]].integerValue;- NSMutableArray<SGKaraokeWord *> *words = [NSMutableArray array];- SGKaraokeWord *open = nil;- BOOL spaced = YES; // a space has gone by, so the next word is not joined to the last+ NSMutableArray<SGKaraokePiece *> *timed = [NSMutableArray array];for (NSUInteger i = 0; i < pieces.count; i++) {NSUInteger from = NSMaxRange(pieces[i].range), to = i + 1 < pieces.count ? pieces[i + 1].range.location : row.length;NSString *raw = [row substringWithRange:NSMakeRange(from, to - from)];- NSString *text = [raw stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];- NSInteger start = [row substringWithRange:[pieces[i] rangeAtIndex:1]].integerValue + (krc ? lineStart : 0);+ SGKaraokePiece *piece = [SGKaraokePiece new];+ piece.text = [raw stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];+ piece.start = [row substringWithRange:[pieces[i] rangeAtIndex:1]].integerValue + (krc ? lineStart : 0);// A piece of no length is still shown, for a moment.- NSInteger end = start + MAX([row substringWithRange:[pieces[i] rangeAtIndex:2]].integerValue, 1);- // yrc times a Chinese or Japanese syllable a piece at a time and never spaces them, so- // each one is a word of its own; only a spaced script runs its pieces together.- BOOL unspaced = SGKaraokeUnspacedScript(text);- if (text.length && open && !unspaced) {- open.text = [open.text stringByAppendingString:text];- open.end = end;- } else if (text.length) {- SGKaraokeWord *word = [SGKaraokeWord new];- word.text = text;- word.start = start;- word.end = end;- word.joined = !spaced;- [words addObject:word];- open = unspaced ? nil : word;- spaced = NO;- }- if (raw.length > text.length || !text.length) {- open = nil;- spaced = YES;- }+ piece.end = piece.start + MAX([row substringWithRange:[pieces[i] rangeAtIndex:2]].integerValue, 1);+ // A space ends the word after the piece, even one in front of it.+ piece.spaceAfter = raw.length > piece.text.length;+ [timed addObject:piece];}- if (!words.count) continue;- SGKaraokeLine *line = [SGKaraokeLine new];- line.words = words;- line.start = lineStart;- line.end = MAX(lineStart + [row substringWithRange:[head rangeAtIndex:2]].integerValue, words.lastObject.end);- [lines addObject:line];+ SGKaraokeLine *line = SGKaraokePieceLine(timed, lineStart, lineStart + [row substringWithRange:[head rangeAtIndex:2]].integerValue);+ if (line) [lines addObject:line];}return lines.count ? lines : nil;}