Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: switches for the on-device translators, and no translation that repeats its line
My-Name-Is-Jeffb807baa7491c
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 41dc0d9b..ff3ec1a7 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -160,7 +160,7 @@ Shared:NaturalLanguage, both languages downloaded in the Translate app or the item says where to) and by AppleIntelligence's model (iOS 26 where it is on and speaks the language; permissive guardrails for changingthe user's own text, 12 lines a session, greedy and capped at 60 tokens a line, exactly one string a line by a generation schema; Translate retried once, as its first ask can fail while it loads), both in- OnDeviceTranslation.swift, the frameworks weak linked; and by an AI translator on the user's own key, picked on the Lyrics page (SGKeyAITranslator): Gemini, an OpenAI-compatible server (chat completions; OpenAI's unless a server URL is given, such as OpenRouter's or an Ollama on the network, which Spotify's ATS allows for local addresses) or Anthropic (the Messages API). Each provider is one entry of LyricsTranslation.m's table: its Keychain slot (one key each, never in the settings, so an export never has one), its model presets (the cheapest first; OpenAI-compatible has none and needs a model), its request and its reply's reader. The answer's shape is forced where the API can (Gemini a bare array, the others {"lines": [...]} by a strict schema), the reader takes either, and a 400 that names an optional field (Gemini's thinking level, OpenAI's schema or reasoning effort, Anthropic's output_config) is asked once more without them. The prompt is shared (Vitrine's with {language} and {count}, editable in a sheet, SGKeyAIPrompt) and the provider adds its sentence on the answer's shape; the model (spotifyglass.lyrics.<id>.model) and the server are read at each ask and checked as they are read, and the log names the provider, the model, the host and the prompt's SHA-256 prefix, never the key. Temperature is not offered: Anthropic's API turns it down and OpenAI's reasoning models take only the default. The menu item says where the lyrics go. The translate items show for every song with Translate any song on (SGKeyLyricsTranslateEverySong, off), else only for a song NaturalLanguage finds in another language than the Lyrics page's (or the iPhone's): one distinct line in five it is at least 80% sure of, or two in another script (a verse in Hangul among English), not the whole song's guess (short lines sway that: Havana reads as Dutch), so songs half in English count and a repeated chorus weighs as one line; Translate on iPhone translates from the language most of those lines are in and leaves lines already in the target as they are. Apple Intelligence's lines show and are saved a batch at a time, only lines without a translation are sent, and a batch it turns down is skipped (asking again sends only those lines). Every finished translation is kept by SavedTranslations.m in Caches/Vitrine/Translations, one JSON file a song and language with each line's text to its translation under "lines" and who made it and when ("by", "model", "made"; a file from before has the lines alone and reads as Unknown), the newest 200, synced when the song's lines are shown: each line knows whether its translation was made here (SGKaraokeLine.translationMade), and a made one with nothing saved is taken off, so the Lyrics page's Saved translations row deletes them at once, posting SGLyricsTranslationsDidChangeNotification as Translate any song does for the open lyrics to sync and redraw. The translate menu names who made a saved translation and when, and for one an AI made (or no one known) offers Delete This Translation, which removes the song's file and the launch's answer for it, so asking again sends the song. Gemini's reply read and checked on the Mac+ OnDeviceTranslation.swift, the frameworks weak linked; and by an AI translator on the user's own key, picked on the Lyrics page (SGKeyAITranslator): Gemini, an OpenAI-compatible server (chat completions; OpenAI's unless a server URL is given, such as OpenRouter's or an Ollama on the network, which Spotify's ATS allows for local addresses) or Anthropic (the Messages API). Each provider is one entry of LyricsTranslation.m's table: its Keychain slot (one key each, never in the settings, so an export never has one), its model presets (the cheapest first; OpenAI-compatible has none and needs a model), its request and its reply's reader. The answer's shape is forced where the API can (Gemini a bare array, the others {"lines": [...]} by a strict schema), the reader takes either, and a 400 that names an optional field (Gemini's thinking level, OpenAI's schema or reasoning effort, Anthropic's output_config) is asked once more without them. The prompt is shared (Vitrine's with {language} and {count}, editable in a sheet, SGKeyAIPrompt) and the provider adds its sentence on the answer's shape; the model (spotifyglass.lyrics.<id>.model) and the server are read at each ask and checked as they are read, and the log names the provider, the model, the host and the prompt's SHA-256 prefix, never the key. Temperature is not offered: Anthropic's API turns it down and OpenAI's reasoning models take only the default. The menu item says where the lyrics go. Translate on iPhone and Apple Intelligence each have a switch that leaves them out of the menu (SGKeyLyricsTranslateOnDevice, SGKeyLyricsAppleIntelligence, both on). A translation that reads the same as its line (SGLyricsBareText) is not drawn under it, and the line still counts as translated. The translate items show for every song with Translate any song on (SGKeyLyricsTranslateEverySong, off), else only for a song NaturalLanguage finds in another language than the Lyrics page's (or the iPhone's): one distinct line in five it is at least 80% sure of, or two in another script (a verse in Hangul among English), not the whole song's guess (short lines sway that: Havana reads as Dutch), so songs half in English count and a repeated chorus weighs as one line; Translate on iPhone translates from the language most of those lines are in and leaves lines already in the target as they are. Apple Intelligence's lines show and are saved a batch at a time, only lines without a translation are sent, and a batch it turns down is skipped (asking again sends only those lines). Every finished translation is kept by SavedTranslations.m in Caches/Vitrine/Translations, one JSON file a song and language with each line's text to its translation under "lines" and who made it and when ("by", "model", "made"; a file from before has the lines alone and reads as Unknown), the newest 200, synced when the song's lines are shown: each line knows whether its translation was made here (SGKaraokeLine.translationMade), and a made one with nothing saved is taken off, so the Lyrics page's Saved translations row deletes them at once, posting SGLyricsTranslationsDidChangeNotification as Translate any song does for the open lyrics to sync and redraw. The translate menu names who made a saved translation and when, and for one an AI made (or no one known) offers Delete This Translation, which removes the song's file and the launch's answer for it, so asking again sends the song. Gemini's reply read and checked on the Macagainst harness/lyrics-translation/LockScreenLyrics/ the line being sung in the system's now playing, and on iOS 26 the lyrics as the lock screen'sfull-screen artwork (LyricsArtwork.x): a new artwork ID per line, its 3:4 H.264 clip (the line and thediff --git a/harness/lyrics-translation/check.m b/harness/lyrics-translation/check.mindex f6de16a4..a71a0a56 100644--- a/harness/lyrics-translation/check.m+++ b/harness/lyrics-translation/check.m@@ -16,6 +16,7 @@ SGLyricsResult *SGLyricsPlainResult(NSArray<NSString *> *rows) { return nil; }NSString *SGLyricsTranslationLanguage(void) { return nil; }SGModRow *SGStatActionRow(NSString *t, NSString *s, NSString *(^v)(void), void (^a)(void)) { return nil; }SGModRow *SGOptionRow(NSString *t, NSString *s, NSString *k) { return nil; }+SGModRow *SGSwitchRow(NSString *t, NSString *s, NSString *k) { return nil; }id SGKaraokeTrackFor(NSString *trackID) { return nil; }UIViewController *SGTopController(void) { return nil; }SGModRow *SGMenuRow(NSString *t, NSArray<NSString *> *c, NSString *(^v)(void), void (^ch)(NSInteger)) { return nil; }diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex 9f9dfcf0..176c749a 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -120,8 +120,8 @@ static UIViewController *lyricsPage(void) {SGSwitchRow(@"Hide the controls", @"A few seconds after the last touch, the lyrics take the whole player", SGRKeyLyricsAutoHide),SGSwitchRow(@"Landscape lyrics", @"Turn the phone with the lyrics open", SGRKeyLyricsLandscape)]),timing,- SGSection(@"Translation", [[@[SGLyricsTranslationLanguageRow(), SGTranslateEverySongRow()] arrayByAddingObjectsFromArray:SGAITranslatorRows()]- arrayByAddingObject:SGSavedTranslationsRow()]),+ SGSection(@"Translation", [[[@[SGLyricsTranslationLanguageRow(), SGTranslateEverySongRow()] arrayByAddingObjectsFromArray:SGOnDeviceTranslatorRows()]+ arrayByAddingObjectsFromArray:SGAITranslatorRows()] arrayByAddingObject:SGSavedTranslationsRow()]),SGSection(nil, @[SGLyricsMeaningsRow()]),]];} else {diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mindex 79355972..36ae8f95 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -611,6 +611,9 @@ static SGRKaraokeLayout *layOut(SGKaraokeLine *line, CGFloat width, SGRKaraokeStlayout.translation = layout.romanised = CGRectNull;NSArray<SGKaraokeWord *> *spoken = style.pronunciation ? line.pronunciation.words : nil;NSString *translation = style.translation ? line.translation : nil;+ // A translator hands back a line already in the language as it was; the line says it once. It stays+ // translated, so it is not asked again.+ if (translation.length && [SGLyricsBareText(translation) isEqualToString:SGLyricsBareText(SGKaraokeLineText(line))]) translation = nil;// A source's own pronunciation, hidden, still reads better than the transform's.if (style.romanised && !spoken.count) {layout.romanisedText = line.pronunciation ? SGKaraokeLineText(line.pronunciation)@@ -1925,8 +1928,8 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {// A translator is offered only for a song in another language than the one it would translate into,// and the translators are asked after (an AI translator's key is a Keychain read).BOOL wanted = _lines && !_sample && (_foreign || SGHidden(SGKeyLyricsTranslateEverySong)) && _untranslated;- BOOL onDevice = wanted && SGOnDeviceTranslation.translationAvailable;- BOOL intelligence = wanted && [SGOnDeviceTranslation appleIntelligenceAvailable:language];+ BOOL onDevice = wanted && SGFlag(SGKeyLyricsTranslateOnDevice, YES) && SGOnDeviceTranslation.translationAvailable;+ BOOL intelligence = wanted && SGFlag(SGKeyLyricsAppleIntelligence, YES) && [SGOnDeviceTranslation appleIntelligenceAvailable:language];BOOL ai = wanted && SGAITranslatorReady();BOOL translatable = ai || onDevice || intelligence;BOOL offered = _lines && !_sample && (_hasSpoken || _hasTranslation || translatable);diff --git a/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.h b/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.hindex 225b4e5e..ac96451d 100644--- a/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.h+++ b/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.h@@ -14,6 +14,11 @@ extern NSNotificationName const SGLyricsTranslationsDidChangeNotification;#define SGKeyLyricsTranslateEverySong @"spotifyglass.lyrics.translateEverySong"SGModRow *SGTranslateEverySongRow(void);+// Off: the translate menu leaves out Apple's Translate, or Apple Intelligence. Both on until switched off.+#define SGKeyLyricsTranslateOnDevice @"spotifyglass.lyrics.translateOnDevice"+#define SGKeyLyricsAppleIntelligence @"spotifyglass.lyrics.appleIntelligence"+NSArray<SGModRow *> *SGOnDeviceTranslatorRows(void);+// The AI translator: a provider's id (gemini, openai, anthropic; unset: gemini), the prompt every provider gets// (unset: Vitrine's), and per provider spotifyglass.lyrics.<id>.model. An OpenAI-compatible server (unset: OpenAI's)// is kept in the Keychain beside its key, not here. All read at each translation.diff --git a/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.m b/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.mindex 39915ca4..5e74b3dd 100644--- a/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.m+++ b/tweak/Sources/Shared/LyricsTranslation/LyricsTranslation.m@@ -512,6 +512,13 @@ static void translatorChanged(void) {[NSNotificationCenter.defaultCenter postNotificationName:SGLyricsTranslationsDidChangeNotification object:nil];}+NSArray<SGModRow *> *SGOnDeviceTranslatorRows(void) {+ SGModRow *onDevice = SGSwitchRow(@"Translate on iPhone", @"Apple's Translate in the lyrics' translate menu", SGKeyLyricsTranslateOnDevice);+ SGModRow *intelligence = SGSwitchRow(@"Apple Intelligence", @"Apple Intelligence in the lyrics' translate menu", SGKeyLyricsAppleIntelligence);+ onDevice.changed = intelligence.changed = ^(BOOL on) { translatorChanged(); };+ return @[onDevice, intelligence];+}+void SGAIForgetKeys(void) {// One delete per provider's own service, every account in it (key and server), never another app's items.for (NSUInteger i = 0; i < kProviderCount; i++) {