Introducing a new way to review your PRs.

Read the announcement

metrolistgroup / metrolist

Material Design YouTube Music client for Android, iOS and desktop

View on GitHub

19 documents · Updated Nov 4, 2026

docs / external-content-services

External content and AI services

Metrolist uses external services to add lyrics and language features to music metadata. Lyrics translation accepts a user-selected provider, sends non-empty lyric lines to that provider, and returns results to the lyric view while keeping the original line structure.

Service roles

The service layer separates general AI translation from dedicated translation. AI providers use a chat-style interface for translation, romanization, and transcription. DeepL provides a separate translation path with its own language and formality rules. This keeps provider choice independent from the lyric screen that displays the result. (app/…/OpenRouterService.kt• L33-112, app/…/DeepLService.kt• L18-33)

Service roleUser valueResult shape
AI providerTranslates lyrics or changes their written formOne output line for each input line
DeepL providerProvides dedicated language translationOne output line for each input line
Custom endpointLets the user use a compatible chat serviceThe same line-based translation result

AI provider choices

The settings page presents several hosted AI services and a custom endpoint option. The selected provider supplies the endpoint and model context, while the API client uses a shared chat request shape for the providers that support it. (app/…/AiSettings.kt• L77-103)

References: app/…/AiSettings.kt• L77-103 app/…/OpenRouterService.kt• L43-77

Dedicated translation service

DeepL is handled as a separate service because it does not use the AI chat flow. The client sends each lyric line as a separate text item and preserves formatting. Its formality choice changes the tone of the result where the target language supports it. (app/…/DeepLService.kt• L26-72)

References: app/…/DeepLService.kt• L18-72 app/…/AiSettings.kt• L532-565

Translation flow

The translation flow connects the lyric view, provider settings, external service, and local lyric record. It filters blank lines before the request and maps returned lines back to the original lyric positions so display timing and layout remain tied to the source lyrics. (app/…/LyricsTranslationHelper.kt• L168-218)

This diagram shows how a user request becomes visible and saved lyric translations.

flowchart LR
    A[Lyrics view] --> B[Translation helper]
    B --> C{Selected service}
    C -->|AI provider| D[Chat translation client]
    C -->|DeepL| E[Dedicated translation client]
    D --> F[Line-based result]
    E --> F
    F --> G[Update lyric lines]
    F --> H[Save translation with language and mode]

Translation modes

AI translation supports two user-facing modes. Literal mode translates meaning and aims to keep the lyric flow. Transcribed mode represents pronunciation in the target script instead of translating meaning. The target language applies to both the request and the saved result. (app/…/AiSettings.kt• L249-280, app/…/OpenRouterService.kt• L136-197)

References: app/…/AiSettings.kt• L312-343 app/…/OpenRouterService.kt• L136-197

Lyric result persistence

A completed translation is held in the lyric view for immediate display and may be saved with the song. The saved record includes the target language and mode. The view loads a saved result only when those values match the current request, which prevents an old translation from appearing under a new setting. (app/…/LyricsTranslationHelper.kt• L129-165, app/…/LyricsEntity.kt• L12-23)

References: app/…/LyricsTranslationHelper.kt• L129-165 app/…/LyricsTranslationHelper.kt• L368-423 app/…/LyricsEntity.kt• L12-23

Streaming behavior

Streaming lets supported AI services return translation text while the request is still running. The app accumulates the incoming event data, shows partial lines when it can identify them, and performs a final line parse before it marks the translation complete. (app/…/OpenRouterStreamingService.kt• L37-122, app/…/LyricsTranslationHelper.kt• L287-346)

The stream has three meaningful outcomes:

  • Content updates the visible partial translation.
  • Complete carries the parsed line list.
  • Error stops the flow and exposes an error state.

The non-streaming path remains available for custom services or when streaming is disabled. DeepL always uses its direct request path. (app/…/LyricsTranslationHelper.kt• L277-359)

References: app/…/OpenRouterStreamingService.kt• L75-135 app/…/LyricsTranslationHelper.kt• L277-359

Configuration boundaries

The settings screen stores provider choice, credentials, endpoint, model, target language, translation mode, and optional prompt text as user preferences. Provider selection changes which credential and request path are used. DeepL uses its own key and formality setting. (app/…/AiSettings.kt• L64-75, app/…/PreferenceKeys.kt• L445-467)

Setting groupPurposeApplies to
Provider and API keySelects the service and authorizes requestsAI or DeepL flow
Endpoint and modelSelects the chat destination and modelAI flow
Target languageSets the output language or scriptBoth flows
Translation modeSelects meaning translation or pronunciation transcriptionAI flow
System promptAdjusts the AI instruction while keeping the line contractAI flow
DeepL formalitySets the supported writing toneDeepL flow

Request contract

The AI request asks for a structured object whose lines array matches the input line count. The response parser accepts the structured form and pads or trims results to protect the line-by-line mapping used by the lyric view. (app/…/OpenRouterService.kt• L114-134, app/…/OpenRouterService.kt• L287-322)

References: app/…/OpenRouterService.kt• L114-134 app/…/OpenRouterService.kt• L287-322 app/…/DeepLService.kt• L106-123

User feature integration

The lyric screens start translation only when lyrics are visible and the selected service has a key. They observe shared translation status, cancel work when the screen leaves composition, and clear displayed results when the user removes translations. (app/…/OriginalLyrics.kt• L362-421, app/…/ExperimentalLyrics.kt• L232-295)

This design keeps external requests tied to a visible user feature rather than to general catalog loading. A failed request changes the translation status and leaves the original lyrics available. (app/…/LyricsTranslationHelper.kt• L424-448)

References: app/…/OriginalLyrics.kt• L362-421 app/…/ExperimentalLyrics.kt• L232-295 app/…/LyricsTranslationHelper.kt• L424-448

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep provider names and endpoint choices aligned between AiSettings and the request routing in LyricsTranslationHelper.
  • Keep the lines response contract aligned across normal requests, streaming events, and the DeepL result mapper.
  • Keep translationLanguage and translationMode checks aligned with the settings passed into the lyric views.
  • Keep the lyric database schema aligned with the saved translation metadata so cached results cannot match the wrong request.

Important failure modes

TriggerConsequenceGuard
Required service key is blankNo external request starts and the user sees a key errorThe lyric flow checks the effective provider key before translation
Provider returns malformed or incomplete line dataSome lines can be missing or misalignedStructured parsing trims or pads the result to the expected count
Streaming endpoint emits an error or ends without a resultPartial text is not saved as a completed translationThe stream emits Error unless final parsing succeeds
Saved language or mode differs from current settingsA stale translation must not be shownDatabase loading requires both metadata values to match
Lyric screen leaves composition during a requestA late result could update an inactive screenThe helper cancels the job and checks composition state

Key files

FileWhy to read it
app/…/LyricsTranslationHelper.ktMain coordinator for provider selection, caching, UI state, persistence, and error handling
app/…/OpenRouterService.ktDefines the AI request and response contract for non-streaming work
app/…/OpenRouterStreamingService.ktDefines progressive AI response handling
app/…/DeepLService.ktDefines the dedicated translation path
app/…/AiSettings.ktShows the user-facing provider and translation configuration
app/…/LyricsEntity.ktDefines the saved lyric translation fields
app/…/OriginalLyrics.ktShows how translation connects to the main lyric feature
app/…/ExperimentalLyrics.ktShows the same service contract in the alternate lyric experience