LibreLyrics LibreLyrics

API Reference

Complete reference for every public class, method, and data model in LibreLyrics.

LibreLyrics

Main orchestrator. Loads plugins, manages configuration, and dispatches URL-based fetch requests to the matching provider.

class LibreLyrics(config=None, verbose=False)

ParamTypeDescription
configdict | NoneOptional pre-loaded configuration dictionary. If None, loads from the default config file.
verboseboolEnable verbose (DEBUG-level) logging.

fetch(url: str) → LyricsResponse

Fetch lyrics for a single track URL. Finds the first matching plugin and returns the result with automatic retry.

ParamTypeDescription
urlstrTrack URL to fetch lyrics from.

Raises: NoMatchingModuleError, LyricsNotFound

fetch_batch(url: str) → list[LyricsResponse]

Fetch lyrics for an album or playlist URL. Automatically dispatches to the appropriate batch method based on declared capabilities.

ParamTypeDescription
urlstrAlbum or playlist URL.

Raises: NoMatchingModuleError

list_plugins() → list[type[LyricsModule]]

Return a list of all loaded plugin classes.

config : dict (property)

The raw configuration dictionary (read-only access).

LyricsResponse

Standardised response dataclass returned by every plugin's fetch(). All timing values are in milliseconds.

FieldTypeDescription
titlestrTrack title.
artiststrArtist name.
lyricslist[LyricsLine]List of lyric lines.
sourcestrPlugin name that provided the lyrics.
albumstr | NoneAlbum name, if available.
syncedboolWhether lyrics have line-level timing.
rich_syncedboolWhether lyrics have word-level timing.
duration_msint | NoneTrack duration in milliseconds.
metadatadictArbitrary extra metadata (track_number, explicit, etc.).

to_lrc(include_metadata=True, enhanced=False) → str

Format lyrics as LRC file content.

ParamTypeDescription
include_metadataboolInclude [ti:], [ar:], [al:] tags.
enhancedboolUse Enhanced LRC with word-level timestamps.

Example Output (Standard LRC)

[ti:Bohemian Rhapsody]
[al:A Night at the Opera]
[ar:Queen]
[length:05:54.83]
[00:00.00] Is this the real life?
[00:04.10] Is this just fantasy?

LyricsLine

A single line of lyrics. Frozen dataclass.

FieldTypeDescription
textstrLine text (the actual lyric words).
start_msint | NoneStart timestamp in ms. None for unsynced.
end_msint | NoneEnd timestamp in ms. Available for rich synced lyrics.
wordstuple[LyricsWord, ...] | NoneWord-level timing for karaoke-style display.

LyricsWord

A single word with timing. Frozen dataclass.

FieldTypeDescription
wordstrThe word text.
start_msintStart timestamp in ms.
end_msintEnd timestamp in ms.

LyricsType

Enum of lyrics formats a module can provide.

MemberDescription
PLAINUnsynced lyrics — just text, no timestamps.
SYNCEDLine-synced lyrics — one timestamp per line.
RICH_SYNCEDWord-synced lyrics — timestamp per word, karaoke-style.

ModuleCapability

Flag enum of capabilities a module can declare. Used by the orchestrator for dispatch.

FlagDescription
SINGLE_TRACKCan fetch lyrics for a single track.
ALBUMCan fetch all tracks in an album.
PLAYLISTCan fetch all tracks in a playlist.
SEARCHCan search for tracks by metadata.

ConfigManager

Manages loading, saving, merging and plugin-specific config slicing.

class ConfigManager(config=None, config_path=None)

ParamTypeDescription
configdict | NonePre-loaded config. If None, loads from disk.
config_pathPath | NoneCustom config file path. Defaults to platform path.

get(key, default=None) → Any

Get a config value by key.

set(key, value)

Set a config value.

save()

Write the current config to disk (creates parent dirs automatically).

for_plugin(plugin_cls) → dict

Return the merged config for a specific plugin (plugin defaults + stored overrides).

merge_plugin_defaults(plugins) → bool

Merge default_config() from every loaded plugin into the plugins section. Returns True if something changed.

raw : dict (property)

Direct access to the underlying config dictionary.

Standalone Helpers

get_config_path() → Path

Returns the platform-specific config file path:
Windows: %APPDATA%\librelyrics\config.json
Linux/macOS: ~/.config/librelyrics/config.json

get_default_config() → dict

Return the default config dictionary (see Configuration for all keys).

Exceptions

All exceptions inherit from LibreLyricsError.

LibreLyricsError
├── PluginError
│   ├── PluginLoadError
│   ├── PluginAPIVersionError
│   └── NoMatchingModuleError
├── ConfigurationError
│   └── CorruptedConfig
└── ProviderError
    ├── NotValidSp_Dc
    ├── NoSongPlaying
    ├── TOTPGenerationException
    ├── LyricsNotFound
    └── RateLimitError
ExceptionWhen Raised
PluginLoadErrorA plugin module failed to import.
PluginAPIVersionErrorPlugin declares an incompatible API version.
NoMatchingModuleErrorNo plugin regex matches the provided URL.
ConfigurationErrorConfig is invalid or missing required values.
CorruptedConfigConfig JSON cannot be parsed.
LyricsNotFoundProvider has no lyrics for the requested track.
RateLimitErrorHTTP 429 — triggers automatic retry back-off.

Helper Functions

Standalone utility functions in librelyrics.core.

save_lyrics(lyrics: str, path: str)

Write lyrics content to a file, creating parent directories automatically.

download_lyrics(librelyrics, url, folder=None) → tuple[list[str], list[str]]

Download lyrics for a URL (track, album, or playlist). Returns (successful_tracks, failed_tracks).

rename_using_format(template: str, data: dict) → str

Format a filename template using variable placeholders. Invalid filename characters are stripped.