Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: four crash, watchdog and player layout fixes (#147)
annae033415411e9
diff --git a/harness/lyrics-sources/check.m b/harness/lyrics-sources/check.mindex 97f97f35..bc582d68 100644--- a/harness/lyrics-sources/check.m+++ b/harness/lyrics-sources/check.m@@ -424,6 +424,18 @@ int main(int argc, char **argv) {@{@"id": @5, @"trackName": @"a", @"artistName": @"b", @"syncedLyrics": @"", @"plainLyrics": @"y\nz"}];got = lrclibAnswer(query, nil);CHECK(got && !got.synced);+ // Null instrumental and null duration: a word-synced record with null instrumental still reads its+ // Lyricsfile, a known duration within slack beats a null duration, and when both have null duration+ // the fuller sheet wins.+ query.seconds = 200;+ found = @[@{@"id": @13, @"trackName": @"a", @"artistName": @"b", @"duration": NSNull.null, @"instrumental": NSNull.null, @"syncedLyrics": twoLines},+ @{@"id": @14, @"trackName": @"a", @"artistName": @"b", @"duration": @203, @"instrumental": NSNull.null, @"syncedLyrics": @"[00:01.00]a\n"}];+ got = lrclibAnswer(query, nil);+ CHECK(got.synced && got.karaokeLines.count == 1);+ found = @[@{@"id": @13, @"trackName": @"a", @"artistName": @"b", @"duration": NSNull.null, @"instrumental": NSNull.null, @"syncedLyrics": @"[00:01.00]a\n"},+ @{@"id": @14, @"trackName": @"a", @"artistName": @"b", @"duration": NSNull.null, @"instrumental": NSNull.null, @"syncedLyrics": twoLines}];+ got = lrclibAnswer(query, nil);+ CHECK(got.synced && got.karaokeLines.count == 2);for (int i = 1; i < argc; i++) checkLive(@(argv[i]));printf("lyrics-sources: all checks passed\n");diff --git a/harness/spicy-lyrics/check.m b/harness/spicy-lyrics/check.mindex 16c9bad8..61b6fac8 100644--- a/harness/spicy-lyrics/check.m+++ b/harness/spicy-lyrics/check.m@@ -128,7 +128,11 @@ int main(void) {CHECK(!line.karaokeLines[0].translation && [line.karaokeLines[1].translation isEqualToString:@"zwei"]);CHECK([line.provider isEqualToString:@"Spotify via Spicy Lyrics"]);CHECK([SGKaraokeLineText(parse(@"{\"Body\":{\"Type\":\"Line\",\"Content\":[{\"Text\":\"東京\",\"TransliteratedText\":\"Tokyo\","- "\"StartTime\":1,\"EndTime\":3}]}}").karaokeLines[0].pronunciation) isEqualToString:@"Tokyo"]);+ "\"StartTime\":1,\"EndTime\":3,\"OppositeAligned\":null}]}}").karaokeLines[0].pronunciation) isEqualToString:@"Tokyo"]);+ SGKaraokeLine *nulled = parse(@"{\"Body\":{\"Type\":\"Syllable\",\"Content\":[{\"OppositeAligned\":null,\"Lead\":{"+ "\"StartTime\":null,\"EndTime\":null,\"Syllables\":["+ "{\"Text\":\"ok\",\"StartTime\":1,\"EndTime\":2,\"IsPartOfWord\":null}]}}]}}").karaokeLines.firstObject;+ CHECK(nulled && nulled.start == 1000 && nulled.end == 2000);// With a language chosen, a translation the API names no language for is left out of both syncs.sg_language = @"es";diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex d49a895d..eb2f322c 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -84,6 +84,8 @@ BOOL SGRPlayerLyricsAvailable(void);BOOL SGRPlayerLyricsNone(void);// Whether the player is showing them.BOOL SGRPlayerLyricsOpen(void);+// Hides a control that does not fit or while the lines are alone; records it in sg_faded when it fits.+BOOL SGRPlayerLyricsFadeView(UIView *view, BOOL fits);// Shows them, or puts the cover back; does nothing when there are none to show.void SGRPlayerToggleLyrics(void);// Called by PlayerLyrics.x whenever either of those two changed, so the footer's lyrics glyph followsdiff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex a0c0d536..47a807a8 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -377,6 +377,20 @@ static NSArray<UIView *> *fadingViews(void) {return views;}+BOOL SGRPlayerLyricsFadeView(UIView *view, BOOL fits) {+ if (!view) return NO;+ if (!fits) {+ view.alpha = 0;+ [sg_faded removeObject:view];+ return YES;+ }+ if (!sg_alone) return NO;+ view.alpha = 0;+ if (!sg_faded) sg_faded = [NSHashTable weakObjectsHashTable];+ [sg_faded addObject:view];+ return YES;+}+static void fadeControls(BOOL faded) {if (!sg_faded) sg_faded = [NSHashTable weakObjectsHashTable];if (faded) {diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xindex 1cdd8dd8..8f60912c 100644--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -151,6 +151,7 @@ static UIColor *footColor(CGImageRef poster) {@end@implementation SGRPlayerMotionView {+ NSURL *_file;AVQueuePlayer *_player;AVPlayerLooper *_looper;UIView *_picture; // the clip over its foot, faded in as one@@ -159,6 +160,7 @@ static UIColor *footColor(CGImageRef poster) {CAGradientLayer *_clipMask, *_seamMask;CALayer *_foot; // the color of the poster's last rows, from the seam downCAGradientLayer *_dim; // black over the clip's top and from above the title down, as dark as the clip is bright+ AVAssetImageGenerator *_generator;NSMutableData *_luminances; // of the frames measured so farBOOL _lyricsUp;NSUInteger _blurTurn; // counts the lyrics' turns, so a fade cut short leaves the filter to the turn after it@@ -234,6 +236,10 @@ static UIBlurEffect *blurEffect(void) {- (void)dealloc {[NSNotificationCenter.defaultCenter removeObserver:self];+ [_generator cancelAllCGImageGeneration];+ [_looper disableLooping];+ [_player pause];+ _clip.player = nil;}- (void)setScreenHeight:(CGFloat)height {@@ -270,6 +276,13 @@ static UIBlurEffect *blurEffect(void) {}- (void)playFile:(NSURL *)file poster:(UIImage *)poster {+ if ([_file isEqual:file] && _still.contents == (__bridge id)poster.CGImage) {+ [self updateMotion];+ return;+ }+ _file = [file copy];+ [_looper disableLooping];+ [_player pause];_aspect = poster.size.height / poster.size.width;_foot.backgroundColor = footColor(poster.CGImage).CGColor;_still.contents = (__bridge id)poster.CGImage;@@ -285,6 +298,7 @@ static UIBlurEffect *blurEffect(void) {// The poster now, so the clip comes in already dimmed, and two later frames as they are read.- (void)measure:(NSURL *)file poster:(UIImage *)poster {+ [_generator cancelAllCGImageGeneration];_luminances = [NSMutableData data];addLuminances(poster.CGImage, _luminances);[CATransaction begin];@@ -292,6 +306,7 @@ static UIBlurEffect *blurEffect(void) {[self updateDim];[CATransaction commit];AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:[AVURLAsset assetWithURL:file]];+ _generator = generator;generator.appliesPreferredTrackTransform = YES;generator.maximumSize = CGSizeMake(64, 64);__weak SGRPlayerMotionView *weakSelf = self;@@ -537,9 +552,15 @@ BOOL SGRPlayerMotionShowing(void) {}static UIView *previewOf(NSURL *file, UIImage *poster) {- SGRPlayerMotionView *preview = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];+ static __weak SGRPlayerMotionView *sg_preview;+ SGRPlayerMotionView *preview = sg_preview;+ BOOL fresh = !preview;+ if (fresh) {+ preview = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];+ sg_preview = preview;+ }[preview playFile:file poster:poster];- [preview appear:NO then:^{}];+ if (fresh) [preview appear:NO then:^{}];return preview;}diff --git a/tweak/Sources/Redesigned/Player/PlayerVisualiser.m b/tweak/Sources/Redesigned/Player/PlayerVisualiser.mindex 891d1772..dcdb0bca 100644--- a/tweak/Sources/Redesigned/Player/PlayerVisualiser.m+++ b/tweak/Sources/Redesigned/Player/PlayerVisualiser.m@@ -194,6 +194,7 @@ static UIColor *lit(UIColor *color, CGFloat luminance) {}- (void)dealloc {+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(updateMotion) object:nil];[NSNotificationCenter.defaultCenter removeObserver:self];[_link invalidate];if (_reading) needReader(NO);@@ -469,7 +470,10 @@ BOOL SGRPlayerVisualiserShowing(void) {}UIView *SGRPlayerVisualiserPreview(void) {- return [[SGRVisualiserView alloc] initWithFrame:CGRectZero];+ static __weak SGRVisualiserView *sg_preview;+ SGRVisualiserView *preview = sg_preview ?: [[SGRVisualiserView alloc] initWithFrame:CGRectZero];+ sg_preview = preview;+ return preview;}// The hills from the top of the field to the foot of its bleed, standing on the screen's foot.diff --git a/tweak/Sources/Redesigned/Player/PlayerVolume.m b/tweak/Sources/Redesigned/Player/PlayerVolume.mindex 4c82cb9e..4d5be7ec 100644--- a/tweak/Sources/Redesigned/Player/PlayerVolume.m+++ b/tweak/Sources/Redesigned/Player/PlayerVolume.m@@ -356,7 +356,7 @@ static void settle(UIView *stack, UIView *row, BOOL moved, CGRect frame) {BOOL SGRPlayerPlaceVolume(UIView *stack, UIView *controls, UIView *row, CGFloat margin) {SGRVolumeRow *volume = objc_getAssociatedObject(stack, &kVolumeKey);if (!SGRPlayerVolumeOn() || !controls) {- if (volume) volume.alpha = 0;+ SGRPlayerLyricsFadeView(volume, NO);return NO;}if (!volume) {@@ -380,7 +380,7 @@ BOOL SGRPlayerPlaceVolume(UIView *stack, UIView *controls, UIView *row, CGFloatlogged = YES;SGLog(@"redesign player: no play button in %@, so no volume row", NSStringFromClass(controls.class));}- volume.alpha = 0;+ SGRPlayerLyricsFadeView(volume, NO);return NO;}CGFloat above = CGRectGetMaxY([play convertRect:play.bounds toView:stack]);@@ -393,8 +393,8 @@ BOOL SGRPlayerPlaceVolume(UIView *stack, UIView *controls, UIView *row, CGFloat// The lyrics fade the stack's views by their alpha and bring back only the ones they faded.// The track is 7pt of the row's 32: it fits with the glyphs' and buttons' own clearance around it.BOOL fits = room >= height * 0.6;- if (!fits) volume.alpha = 0;- else if (volume.alpha < 0.01 && controls.alpha > 0.99) volume.alpha = 1;+ BOOL faded = SGRPlayerLyricsFadeView(volume, fits);+ if (!faded && volume.alpha < 0.01 && controls.alpha > 0.99) volume.alpha = 1;return fits;}diff --git a/tweak/Sources/Shared/Haptics/MusicHaptics.x b/tweak/Sources/Shared/Haptics/MusicHaptics.xindex 74360b7f..55d4b229 100644--- a/tweak/Sources/Shared/Haptics/MusicHaptics.x+++ b/tweak/Sources/Shared/Haptics/MusicHaptics.x@@ -264,6 +264,26 @@ static float strength(void) {return (float)loadDouble(&sg_strengthBits);}+static BOOL handleEngineStopped(NSError *error) {+ BOOL interrupted = (error && (error.code == CHHapticErrorCodeEngineNotRunning ||+ error.code == CHHapticErrorCodeServerInterrupted));+ BOOL signaled = atomic_exchange(&sg_engineStopped, false);+ if (!interrupted && !signaled) return NO;+ sg_engineRunning = NO;+ sg_rumble = nil;+ sg_rumbling = NO;+ sg_quietSince = 0;+ return YES;+}++static void stopRumble(NSTimeInterval at) {+ sg_quietSince = 0;+ if (handleEngineStopped(nil) || !sg_rumbling) return;+ NSError *error = nil;+ if (![sg_rumble stopAtTime:at error:&error]) handleEngineStopped(error);+ sg_rumbling = NO;+}+static BOOL startEngine(void) {static BOOL supported, checked;static double retryAt;@@ -292,11 +312,7 @@ static BOOL startEngine(void) {SGLog(@"music haptics: the engine was reset");};}- if (atomic_exchange(&sg_engineStopped, false)) {- sg_engineRunning = NO;- sg_rumble = nil;- sg_rumbling = NO;- }+ handleEngineStopped(nil);if (sg_engineRunning) return YES;double now = hostSeconds(mach_absolute_time());if (now < retryAt) return NO;@@ -311,9 +327,8 @@ static BOOL startEngine(void) {}static void stopEngine(void) {- [sg_rumble stopAtTime:CHHapticTimeImmediate error:nil];+ stopRumble(CHHapticTimeImmediate);sg_rumble = nil;- sg_rumbling = NO;if (sg_engineRunning) [sg_engine stopWithCompletionHandler:nil];sg_engineRunning = NO;}@@ -355,7 +370,7 @@ static void playTap(const SGMusicEvent *event) {if (!player || ![player startAtTime:at error:&error]) {static int logged;if (logged++ < 3) SGLog(@"music haptics: a tap did not play: %@", error);- if (error.code == CHHapticErrorCodeEngineNotRunning || error.code == CHHapticErrorCodeServerInterrupted) atomic_store(&sg_engineStopped, true);+ handleEngineStopped(error);return;}sg_stats.taps++;@@ -380,13 +395,10 @@ static void playPreview(BOOL rumbles) {NSError *error = nil;CHHapticPattern *pattern = [[CHHapticPattern alloc] initWithEvents:events parameters:@[] error:&error];id<CHHapticPatternPlayer> player = pattern ? [sg_engine createPlayerWithPattern:pattern error:&error] : nil;- if (!player || ![player startAtTime:CHHapticTimeImmediate error:&error]) SGLog(@"music haptics: the preview did not play: %@", error);-}--static void stopRumble(NSTimeInterval at) {- if (!sg_rumbling) return;- [sg_rumble stopAtTime:at error:nil];- sg_rumbling = NO;+ if (!player || ![player startAtTime:CHHapticTimeImmediate error:&error]) {+ SGLog(@"music haptics: the preview did not play: %@", error);+ handleEngineStopped(error);+ }}static void playLevel(const SGMusicEvent *event) {@@ -420,6 +432,7 @@ static void playLevel(const SGMusicEvent *event) {if (!sg_rumble) {static int logged;if (logged++ < 3) SGLog(@"music haptics: no rumble: %@", error);+ handleEngineStopped(error);return;}}@@ -432,12 +445,13 @@ static void playLevel(const SGMusicEvent *event) {if (![sg_rumble startAtTime:at error:&error]) {static int logged;if (logged++ < 3) SGLog(@"music haptics: the rumble did not start: %@", error);+ handleEngineStopped(error);sg_rumble = nil;return;}sg_rumbling = YES;} else {- [sg_rumble sendParameters:controls atTime:at error:nil];+ if (![sg_rumble sendParameters:controls atTime:at error:&error]) handleEngineStopped(error);}sg_rumbleSentAt = heard;sg_rumbleSent = level;@@ -490,7 +504,7 @@ static void *playerLoop(void *unused) {}unsigned head = atomic_load(&sg_head), tail = atomic_load(&sg_tail);if (tail != head && startEngine()) {- for (; tail != head; tail++) {+ for (; tail != head && !handleEngineStopped(nil) && sg_engineRunning; tail++) {SGMusicEvent event = sg_ring[tail & (kRingSize - 1)];if (event.kind == SGMusicEventLevel) {if (rumbles) playLevel(&event);diff --git a/tweak/Sources/Shared/LyricsSources/BiniLyrics.m b/tweak/Sources/Shared/LyricsSources/BiniLyrics.mindex d0a6ac5f..e271070f 100644--- a/tweak/Sources/Shared/LyricsSources/BiniLyrics.m+++ b/tweak/Sources/Shared/LyricsSources/BiniLyrics.m@@ -23,8 +23,8 @@ static NSDictionary *bestOf(id results, NSInteger seconds) {if (![found isKindOfClass:NSDictionary.class] || ![found[@"lyricsUrl"] isKindOfClass:NSString.class]) continue;id duration = found[@"duration"];NSInteger length = [duration respondsToSelector:@selector(integerValue)] ? [duration integerValue] : 0;- NSInteger off = seconds > 0 && length > 0 ? labs(length - seconds) : 0;- if (off > kLengthSlack) continue;+ NSInteger off = seconds > 0 ? (length > 0 ? labs(length - seconds) : NSIntegerMax) : 0;+ if (length > 0 && off > kLengthSlack) continue;BOOL wordTimed = [found[@"timing_type"] isEqual:@"word"];if (best && !(wordTimed && !bestWordTimed) && (bestWordTimed != wordTimed || off >= bestOff)) continue;best = found;diff --git a/tweak/Sources/Shared/LyricsSources/LrcLib.m b/tweak/Sources/Shared/LyricsSources/LrcLib.mindex 74124260..f28cb7fa 100644--- a/tweak/Sources/Shared/LyricsSources/LrcLib.m+++ b/tweak/Sources/Shared/LyricsSources/LrcLib.m@@ -68,7 +68,7 @@ static NSArray<SGKaraokeLine *> *linesFromLRC(NSString *lrc) {// Without word sync a record's Lyricsfile only repeats its LRC's line times, so it is not read.// Whether a record has words to read: it says it times them, and it is not an instrumental.static BOOL timesWords(NSDictionary *record) {- return [record isKindOfClass:NSDictionary.class] && [record[@"hasWordSync"] isEqual:@YES] && ![record[@"instrumental"] boolValue];+ return [record isKindOfClass:NSDictionary.class] && [record[@"hasWordSync"] isEqual:@YES] && ![record[@"instrumental"] isEqual:@YES];}static SGLyricsResult *syncedResult(NSArray<SGKaraokeLine *> *lines) {@@ -106,7 +106,7 @@ SGLyricsResult *SGLyricsPlainResult(NSArray<NSString *> *rows) {static SGLyricsResult *resultFrom(NSDictionary *record, NSArray<SGKaraokeLine *> *wordLines) {if (![record isKindOfClass:NSDictionary.class]) return nil;SGLyricsResult *result = [SGLyricsResult new];- result.instrumental = [record[@"instrumental"] boolValue];+ result.instrumental = [record[@"instrumental"] isEqual:@YES];if (result.instrumental) return result;id synced = record[@"syncedLyrics"], plain = record[@"plainLyrics"];SGLyricsResult *worded = syncedResult(wordLines);@@ -144,11 +144,13 @@ static BOOL betterRecord(NSDictionary *record, NSDictionary *best, NSInteger secNSInteger length = lengthOf(record), wasLength = lengthOf(best);NSInteger off = length > 0 ? labs(length - seconds) : NSIntegerMax;NSInteger wasOff = wasLength > 0 ? labs(wasLength - seconds) : NSIntegerMax;- return off < wasOff;+ if (off != wasOff) return off < wasOff;}- NSString *text = record[@"syncedLyrics"] ?: record[@"plainLyrics"] ?: @"";- NSString *wasText = best[@"syncedLyrics"] ?: best[@"plainLyrics"] ?: @"";- return [text isKindOfClass:NSString.class] && (![wasText isKindOfClass:NSString.class] || text.length > wasText.length);+ id text = synced ? record[@"syncedLyrics"] : record[@"plainLyrics"];+ id wasText = wasSynced ? best[@"syncedLyrics"] : best[@"plainLyrics"];+ NSUInteger len = [text isKindOfClass:NSString.class] ? [text length] : 0;+ NSUInteger wasLen = [wasText isKindOfClass:NSString.class] ? [wasText length] : 0;+ return len > wasLen;}// The search ranks by its own lights, and its first hit is often another song of the artist's or thediff --git a/tweak/Sources/Shared/LyricsSources/Musixmatch.m b/tweak/Sources/Shared/LyricsSources/Musixmatch.mindex 500534d4..ba431b2c 100644--- a/tweak/Sources/Shared/LyricsSources/Musixmatch.m+++ b/tweak/Sources/Shared/LyricsSources/Musixmatch.m@@ -54,6 +54,10 @@ static BOOL truthy(id value) {return [value respondsToSelector:@selector(boolValue)] && [value boolValue];}+static NSInteger intOf(id value) {+ return [value respondsToSelector:@selector(integerValue)] ? [value integerValue] : 0;+}+static NSInteger msOf(id seconds) {return [seconds respondsToSelector:@selector(doubleValue)] ? (NSInteger)llround([seconds doubleValue] * 1000) : 0;}@@ -240,7 +244,7 @@ static SGLyricsResult *withTrack(SGLyricsResult *lyrics, id track) {if ([title isKindOfClass:NSString.class]) result.title = title;if ([artist isKindOfClass:NSString.class]) result.artist = artist;if ([album isKindOfClass:NSString.class]) result.album = album;- result.seconds = [track[@"track_length"] integerValue];+ result.seconds = intOf(track[@"track_length"]);result.instrumental = truthy(track[@"instrumental"]);return result;}@@ -261,7 +265,7 @@ static void ask(NSString *trackID, NSDictionary<NSString *, NSString *> *match,} mutableCopy];[query addEntriesFromDictionary:match];call(@"macro.subtitles.get", query, ^(NSDictionary *message) {- NSInteger status = [dig(message, @"header/status_code") integerValue];+ NSInteger status = intOf(dig(message, @"header/status_code"));if (status == 401 && renewToken) {SGLog(@"musixmatch: token no longer accepted (hint %@), asking for a new one", dig(message, @"header/hint"));[NSUserDefaults.standardUserDefaults removeObjectForKey:kTokenKey];@@ -358,7 +362,7 @@ static void translationPage(NSString *token, NSString *commontrack, NSString *co@"comment_format": @"text", @"part": @"user", @"translation_fields_set": @"minimal",@"page": @(page).stringValue, @"page_size": @(kTranslationPage).stringValue,}, ^(NSDictionary *message) {- NSInteger status = [dig(message, @"header/status_code") integerValue];+ NSInteger status = intOf(dig(message, @"header/status_code"));if (status != 200) {done(status);return;@@ -427,7 +431,7 @@ static void askTranslations(NSString *trackID, NSString *language, BOOL renewTokNSMutableDictionary<NSString *, NSString *> *query = [match mutableCopy];query[@"usertoken"] = token;call(@"matcher.track.get", query, ^(NSDictionary *message) {- NSInteger status = [dig(message, @"header/status_code") integerValue];+ NSInteger status = intOf(dig(message, @"header/status_code"));noteCommontrack(trackID, dig(message, @"body/track/commontrack_id"));NSString *commontrack = status == 200 ? sg_commontracks[trackID] : nil;if (commontrack) translate(commontrack);diff --git a/tweak/Sources/Shared/LyricsSources/NetEase.m b/tweak/Sources/Shared/LyricsSources/NetEase.mindex 610382d3..e081b327 100644--- a/tweak/Sources/Shared/LyricsSources/NetEase.m+++ b/tweak/Sources/Shared/LyricsSources/NetEase.m@@ -72,12 +72,18 @@ NSArray<SGKaraokeLine *> *SGLyricsPieceLines(NSString *body, BOOL krc) {return lines.count ? lines : nil;}-static void tryLyrics(NSArray<NSNumber *> *songs, NSUInteger index, void (^done)(NSArray<SGKaraokeLine *> *)) {+static NSString *stringIn(id value) {+ if ([value isKindOfClass:NSString.class]) return value;+ if ([value isKindOfClass:NSNumber.class]) return [value stringValue];+ return nil;+}++static void tryLyrics(NSArray<NSString *> *songs, NSUInteger index, void (^done)(NSArray<SGKaraokeLine *> *)) {if (index >= songs.count) {done(nil);return;}- get(@"song/lyric/v1", @{@"id": songs[index].stringValue, @"lv": @"1", @"yv": @"1", @"tv": @"-1"}, ^(NSDictionary *root) {+ get(@"song/lyric/v1", @{@"id": songs[index], @"lv": @"1", @"yv": @"1", @"tv": @"-1"}, ^(NSDictionary *root) {id yrc = [root[@"yrc"] isKindOfClass:NSDictionary.class] ? root[@"yrc"][@"lyric"] : nil;NSArray<SGKaraokeLine *> *lines = [yrc isKindOfClass:NSString.class] ? SGLyricsPieceLines(yrc, NO) : nil;if (lines) {@@ -113,7 +119,9 @@ SGLyricsAsk SGNetEaseAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *id songs = [root[@"result"] isKindOfClass:NSDictionary.class] ? root[@"result"][@"songs"] : nil;NSMutableArray<NSDictionary *> *fitting = [NSMutableArray array];for (NSDictionary *song in [songs isKindOfClass:NSArray.class] ? songs : @[]) {- if (![song isKindOfClass:NSDictionary.class] || labs(lengthOf(song) - seconds) > kLengthSlack) continue;+ if (![song isKindOfClass:NSDictionary.class] || !stringIn(song[@"id"]).length) continue;+ NSInteger length = lengthOf(song);+ if (length <= 0 || labs(length - seconds) > kLengthSlack) continue;id artists = song[@"artists"];for (NSDictionary *credited in [artists isKindOfClass:NSArray.class] ? artists : @[]) {NSString *name = [credited isKindOfClass:NSDictionary.class] && [credited[@"name"] isKindOfClass:NSString.class] ? [credited[@"name"] lowercaseString] : nil;@@ -126,7 +134,11 @@ SGLyricsAsk SGNetEaseAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResult *[fitting sortUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {return [@(labs(lengthOf(a) - seconds)) compare:@(labs(lengthOf(b) - seconds))];}];- NSArray *ids = [[fitting valueForKey:@"id"] subarrayWithRange:NSMakeRange(0, MIN(fitting.count, kTriedSongs))];+ NSMutableArray<NSString *> *ids = [NSMutableArray array];+ for (NSDictionary *song in fitting) {+ [ids addObject:stringIn(song[@"id"])];+ if (ids.count >= kTriedSongs) break;+ }if (!ids.count) SGLog(@"netease: no recording of %@ by %@ within %lds of %lds", title, lead, (long)kLengthSlack, (long)seconds);tryLyrics(ids, 0, answer);});diff --git a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.mindex 1706f975..954932da 100644--- a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m+++ b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m@@ -92,13 +92,14 @@ static SGKaraokeLine *syllableLine(NSDictionary *part, NSString *field) {word.end = MAX(ms(syllable[@"EndTime"]), word.start);word.joined = words.count && runsOn;[words addObject:word];- runsOn = [syllable[@"IsPartOfWord"] boolValue];+ runsOn = [syllable[@"IsPartOfWord"] isEqual:@YES];}if (!words.count) return nil;SGKaraokeLine *line = [SGKaraokeLine new];line.words = words;- line.start = part[@"StartTime"] ? ms(part[@"StartTime"]) : words.firstObject.start;- line.end = MAX(part[@"EndTime"] ? ms(part[@"EndTime"]) : words.lastObject.end, line.start);+ id start = part[@"StartTime"], end = part[@"EndTime"];+ line.start = [start respondsToSelector:@selector(doubleValue)] ? ms(start) : words.firstObject.start;+ line.end = MAX([end respondsToSelector:@selector(doubleValue)] ? ms(end) : words.lastObject.end, line.start);return line;}@@ -126,7 +127,7 @@ static NSArray<SGKaraokeLine *> *syllableLines(NSArray *content) {NSDictionary *lead = item[@"Lead"];SGKaraokeLine *line = syllableLine(lead, @"Text");if (!line) continue;- line.align = [item[@"OppositeAligned"] boolValue] ? SGKaraokeAlignTrailing : SGKaraokeAlignLeading;+ line.align = [item[@"OppositeAligned"] isEqual:@YES] ? SGKaraokeAlignTrailing : SGKaraokeAlignLeading;// A line can have several background phrases; the view has one backing line, so they share it,// and their translations join the lead's.NSMutableArray *backing = [NSMutableArray array];@@ -174,7 +175,7 @@ static NSArray<SGKaraokeLine *> *lineLines(NSArray *content) {NSArray<SGKaraokeLine *> *lines = SGKaraokeEstimatedLines(starts, texts);// Breaks were left out of kept, so the lines and kept pair up one to one.for (NSUInteger i = 0; i < lines.count && i < kept.count; i++) {- if ([kept[i][@"OppositeAligned"] boolValue]) lines[i].align = SGKaraokeAlignTrailing;+ if ([kept[i][@"OppositeAligned"] isEqual:@YES]) lines[i].align = SGKaraokeAlignTrailing;lines[i].pronunciation = SGLyricsPronunciation(nil, stringIn(kept[i], @"TransliteratedText"), lines[i]);lines[i].translation = translationOf(stringIn(kept[i], @"TranslatedText"), lines[i]);}