Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: long Thai lyrics lines wrap between their words
My-Name-Is-Jeff2898c0f4a941
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex d9207317..4f82dcfb 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -82,7 +82,7 @@ Shared:Gestures/ the double tap zones on the player: the grid, what each cell does, the recognizer (each look hooks it on)Lyrics/ the lyrics engine for the redesign's Apple Music style lyrics and the lock screen: lines read fromcolor-lyrics and the player's clock (KaraokeSource.x), words timed by estimate inside Spotify's line- times (KaraokeTiming.m), which line to name where two voices sing at once (the one that came in first,+ times (KaraokeTiming.m, which splits Thai, Lao, Khmer and Burmese at the system's dictionary words), which line to name where two voices sing at once (the one that came in first,for the lock screen and the Live Activity), and the Lyrics page's partsLyricsSources/ the sources lyrics come from, asked in the order the Lyrics page puts them in and merged into thebest answer (LyricsSources.m, the list to drag in LyricsSourcesPage.m): Apple Music's TTML fromdiff --git a/harness/lyrics-sources/README.md b/harness/lyrics-sources/README.mdindex 07291f6f..41716eed 100644--- a/harness/lyrics-sources/README.md+++ b/harness/lyrics-sources/README.md@@ -2,6 +2,9 @@`./build.sh` checks, on the Mac as a Mac Catalyst binary, with no simulator and no network:+- the word splitting in `Shared/Lyrics/KaraokeTiming.m`: long Thai, Lao, Khmer and Burmese lines with no+ spaces come apart at the dictionary's words, the pieces make up the line exactly, and Latin, Chinese and+ 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;- the QQ Music and KuGou asks against made-up search replies: titles, singers and lengths that do notdiff --git a/harness/lyrics-sources/check.m b/harness/lyrics-sources/check.mindex d640da6d..7e717033 100644--- a/harness/lyrics-sources/check.m+++ b/harness/lyrics-sources/check.m@@ -1,4 +1,5 @@-// Checks what is new in the lyrics sources without the phone or the network: KuGou's KRC unpacked+// Checks what is new in the lyrics sources and their words without the phone or the network: lines in+// Thai and the scripts like it split at the dictionary's words (KaraokeTiming.m), KuGou's KRC unpacked// and read (KuGou.m, through NetEase.m's parser), and the QQ Music and KuGou asks matching a track// against made-up search replies. The requests are answered here, by host. Any file named on the// command line is a real KuGou download or QQ lyrics reply, saved as JSON, and only its line count is@@ -44,6 +45,18 @@ static NSString *param(NSURL *url, NSString *name) {return nil;}+static NSArray<SGKaraokeWord *> *piecesOf(NSString *text) {+ return SGKaraokeStaticLines(@[text]).firstObject.words;+}++// The words of an unspaced token come back flush, so the line reads as it was written.+static void checkSplit(NSString *text, BOOL split) {+ NSArray<SGKaraokeWord *> *words = piecesOf(text);+ printf("%lu pieces: %s\n", (unsigned long)words.count, [[words valueForKey:@"text"] componentsJoinedByString:@"|"].UTF8String);+ CHECK([SGKaraokeLineText(SGKaraokeStaticLines(@[text]).firstObject) isEqualToString:text]);+ CHECK(!split || words.count > 1);+}+// KRC as KuGou packs it: "krc1", then the zlib of the text XORed with the key, all in base64.static NSString *packed(NSString *krc, NSString *magic) {NSData *text = [krc dataUsingEncoding:NSUTF8StringEncoding];@@ -82,6 +95,21 @@ static void checkLive(NSString *path) {int main(int argc, char **argv) {@autoreleasepool {+ // Thai, Lao, Khmer and Burmese, long lines with no space, and Thai among Latin and brackets.+ checkSplit(@"ฉันรักเธอมากกว่าสิ่งใดในโลกนี้และจะอยู่เคียงข้างเธอตลอดไป", YES);+ checkSplit(@"วันนี้อากาศดีมากเราไปเดินเล่นที่สวนสาธารณะด้วยกันไหมนะที่รัก", YES);+ checkSplit(@"Baby(ที่รัก)ฉันคิดถึงเธอทุกวันทุกคืนไม่เคยลืมเลย,ok?", YES);+ checkSplit(@"ฉันรักเธอ, เธอรักฉัน... (ด้วยหัวใจ)", YES);+ CHECK([piecesOf(@"(ด้วยหัวใจ)").firstObject.text isEqualToString:@"(ด้วย"]); // what comes before the first word stays with it+ checkSplit(@"ຂ້ອຍຮັກເຈົ້າຫຼາຍທີ່ສຸດໃນໂລກນີ້ແລະຈະຢູ່ນຳເຈົ້າຕະຫຼອດໄປ", NO);+ checkSplit(@"ខ្ញុំស្រលាញ់អ្នកខ្លាំងណាស់ហើយនឹងនៅជាមួយអ្នកជារៀងរហូត", NO);+ checkSplit(@"ကျွန်တော်မင်းကိုအရမ်းချစ်တယ်ထာဝရမင်းနဲ့အတူရှိနေမယ်", NO);+ CHECK(piecesOf(@"๏๚").count == 1); // Thai punctuation alone: no word, one piece+ CHECK(piecesOf(@"hello world").count == 2 && !piecesOf(@"hello world")[1].joined);+ CHECK(piecesOf(@"日本語の歌").count == 5 && piecesOf(@"日本語の歌")[4].joined);+ NSArray<SGKaraokeWord *> *thai = piecesOf(@"ฉันรักเธอมากกว่าสิ่งใดในโลกนี้");+ CHECK(!thai[0].joined && thai[1].joined);+// The keys the two catalogues are matched by.CHECK([SGLyricsMatchKey(@"晴天(Live版)") isEqualToString:SGLyricsMatchKey(@"晴天 (Live版)")]);CHECK([SGLyricsMatchKey(@"Hello, World!") isEqualToString:@"helloworld"]);diff --git a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m b/tweak/Sources/Shared/Lyrics/KaraokeTiming.mindex a95b93cc..bdf55bc7 100644--- a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m+++ b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m@@ -78,6 +78,22 @@ BOOL SGKaraokeUnspacedScript(NSString *text) {return text.length && [text rangeOfCharacterFromSet:unspacedScript()].location != NSNotFound;}+// 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.+static BOOL dictionaryScript(NSString *text) {+ static NSCharacterSet *set;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ NSMutableCharacterSet *building = [NSMutableCharacterSet new];+ [building addCharactersInRange:NSMakeRange(0x0E00, 0x100)]; // Thai and Lao+ [building addCharactersInRange:NSMakeRange(0x1000, 0xA0)]; // Myanmar+ [building addCharactersInRange:NSMakeRange(0x1780, 0x80)]; // Khmer+ set = [building copy];+ });+ return [text rangeOfCharacterFromSet:set].location != NSNotFound;+}+void SGKaraokeAlignVoices(NSArray<SGKaraokeLine *> *lines) {NSMutableArray<NSString *> *heard = [NSMutableArray array];for (SGKaraokeLine *line in lines) {@@ -113,8 +129,28 @@ static void appendPiece(NSMutableArray<SGKaraokeWord *> *pieces, NSString *text)[pieces addObject:word];}+// A token cut at the start of every word the system finds in it, so the pieces still make up the+// whole token: whatever comes between two words stays with the first, whatever comes before the+// first word with it.+static void appendWords(NSMutableArray<SGKaraokeWord *> *pieces, NSString *token) {+ NSMutableArray<NSNumber *> *cuts = [NSMutableArray arrayWithObject:@0];+ __block BOOL first = YES;+ [token enumerateSubstringsInRange:NSMakeRange(0, token.length)+ options:NSStringEnumerationByWords | NSStringEnumerationSubstringNotRequired+ usingBlock:^(NSString *word, NSRange range, NSRange enclosing, BOOL *stop) {+ if (!first && range.location > cuts.lastObject.unsignedIntegerValue) [cuts addObject:@(range.location)];+ first = NO;+ }];+ [cuts addObject:@(token.length)];+ for (NSUInteger i = 0; i + 1 < cuts.count; i++) {+ NSUInteger from = cuts[i].unsignedIntegerValue;+ appendPiece(pieces, [token substringWithRange:NSMakeRange(from, cuts[i + 1].unsignedIntegerValue - from)]);+ }+}+// The line split into what the sweep lights one at a time: words where the script spaces them, a-// syllable at a time where it does not, so a Japanese line sweeps instead of lighting up whole.+// syllable at a time where it does not, so a Japanese line sweeps instead of lighting up whole, and+// the dictionary's words in Thai and its neighbours, so a long line wraps between them.// Everything a token holds past its first piece is joined to the one before it.static NSArray<SGKaraokeWord *> *piecesOf(NSString *line) {NSMutableArray<SGKaraokeWord *> *pieces = [NSMutableArray array];@@ -122,7 +158,8 @@ static NSArray<SGKaraokeWord *> *piecesOf(NSString *line) {if (!token.length) continue;NSUInteger first = pieces.count;if (!SGKaraokeUnspacedScript(token)) {- appendPiece(pieces, token);+ if (dictionaryScript(token)) appendWords(pieces, token);+ else appendPiece(pieces, token);} else {// Latin letters or digits caught between two syllables stay together as one piece.NSMutableString *run = [NSMutableString string];