Skip to content

Commit fe28957

Browse files
authored
Lyrics: Resurrect translations and refactor ReST and command line handling (#5485)
🎵 The Refactoring Blues 🎵 by [Claude](https://claude.ai) Verse 1: Got those lyrics plugin blues Cleaning up some messy code Moving classes, fixing views Making changes down the road Chorus: We're refactoring tonight Making the codebase clean and bright Translation's got a brand new home And ReST files found their own Verse 2: Added Microsoft Translate Keeping tokens safe and sound Config options up-to-date Better structure all around Bridge: Path operations simplified Groups of artists, neat and tied Error handling's looking fine Comments clear along each line Verse 3: RestFiles in their own class now Cleaning imports, showing how Better typing makes it clear What should go and what stays here Final Chorus: We're refactoring tonight Making the codebase clean and bright Translation's got a brand new home And our code can stand alone! — inspired by _the diff_ --- ### Technical Changes - Replaced deprecated and broken Bing translations by Microsoft Translator API - Isolated all functionality in the `Translator` class. - Updated translation settings configuration. - Added support for synced lyrics from LRCLib. - Added support for preserving existing translations to help users to manage their characters quota. - Added error handling and logging - Added tests - Created RestFiles class for ReST document handling - Simplified path operations using pathlib - Added tests - Improved command line options handling #### Caching of translations The plugin will not re-translate lyrics if translations already exist, see ```fish $ beet -v lyrics albumartist::Sel karta -f ... lyrics: LyricsPlugin: Fetching lyrics for Sel - Saulės Miestas lyrics: LRCLib: Fetching JSON from https://lrclib.net/api/get lyrics: LyricsPlugin: 🟢 Found lyrics: 32275 | 1996 / Neįvertinta Karta: Sel - Saulės Miestas lyrics: Translator: Posting data to https://api.cognitive.microsofttranslator.com/translate lyrics: Translator: 🟢 Translated lyrics to EN $ beet -v lyrics albumartist::Sel karta -f ... lyrics: LyricsPlugin: Fetching lyrics for Sel - Saulės Miestas lyrics: LRCLib: Fetching JSON from https://lrclib.net/api/get lyrics: LyricsPlugin: 🟢 Found lyrics: 32275 | 1996 / Neįvertinta Karta: Sel - Saulės Miestas lyrics: Translator: 🔵 Translations already exist ```
2 parents c315487 + 4da72cb commit fe28957

File tree

6 files changed

+529
-246
lines changed

6 files changed

+529
-246
lines changed

beetsplug/_typing.py

+20
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,23 @@ class Pagemap(TypedDict):
113113
"""Pagemap data with a single meta tags dict in a list."""
114114

115115
metatags: list[JSONDict]
116+
117+
118+
class TranslatorAPI:
119+
class Language(TypedDict):
120+
"""Language data returned by the translator API."""
121+
122+
language: str
123+
score: float
124+
125+
class Translation(TypedDict):
126+
"""Translation data returned by the translator API."""
127+
128+
text: str
129+
to: str
130+
131+
class Response(TypedDict):
132+
"""Response from the translator API."""
133+
134+
detectedLanguage: TranslatorAPI.Language
135+
translations: list[TranslatorAPI.Translation]

0 commit comments

Comments
 (0)