Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lyrics: Resurrect translations and refactor ReST and command line handling #5485

Open
wants to merge 4 commits into
base: lyrics-general-improvements
Choose a base branch
from

Conversation

snejus
Copy link
Member

@snejus snejus commented Oct 27, 2024

🎵 The Refactoring Blues 🎵 by Claude

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

$ 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

@snejus snejus self-assigned this Oct 27, 2024
@snejus snejus requested review from bal-e, JOJ0 and Serene-Arc October 27, 2024 00:08
@snejus snejus force-pushed the lyrics-translations branch 3 times, most recently from 5ec1cf8 to 99de0b1 Compare October 29, 2024 21:14
@snejus snejus force-pushed the lyrics-general-improvements branch from cb559f0 to 95c954a Compare October 30, 2024 19:24
@snejus snejus force-pushed the lyrics-translations branch 2 times, most recently from abc5aef to 55a79ec Compare October 30, 2024 21:37
@snejus snejus force-pushed the lyrics-general-improvements branch from 95c954a to ebf136f Compare November 22, 2024 07:45
@snejus snejus force-pushed the lyrics-translations branch from 55a79ec to 2c4406b Compare November 22, 2024 07:50
@snejus snejus force-pushed the lyrics-general-improvements branch from ebf136f to 09c0b9f Compare December 7, 2024 16:59
@snejus snejus force-pushed the lyrics-translations branch from 2c4406b to 13034c9 Compare December 7, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant