lrclib packageο
Submodulesο
lrclib.api moduleο
API for lrclib
- class lrclib.api.LrcLibAPI(user_agent: str, base_url: str | None = None, session: Session | None = None)[source]ο
Bases:
objectCreate a new LrcLibAPI instance. You can optionally pass a custom base URL and a custom requests session.
Note
setting user_agent is not required, but it is recommended by LRCLIB.
- Parameters:
user_agent (str) β User agent to use for the requests
base_url (str, optional) β Base URL to use for the requests
session (requests.Session, optional) β Requests session to use for the requests
- Raises:
UserWarning β If user_agent is not set
Examples
See the π₯Fetching lyrics using the API section for usage examples.
- get_lyrics(track_name: str, artist_name: str, album_name: str, duration: int, cached: bool = False) Lyrics[source]ο
Get lyrics from LRCLIB by track name, artist name, album name and duration.
Note
All parameters are required except cached.
- Parameters:
track_name (str) β Track name
artist_name (str) β Artist name
album_name (str) β Album name
duration (int) β Duration of the track in seconds
cached (bool, optional) β Whether to get cached lyrics or not, defaults to False
- Return type:
- Raises:
NotFoundError β If no lyrics are found
APIError β If the request fails
- get_lyrics_by_id(lrclib_id: str | int) Lyrics[source]ο
Get lyrics from LRCLIB by ID.
- Parameters:
lrclib_id (str | int) β ID of the lyrics
- Return type:
- Raises:
NotFoundError β If no lyrics are found
APIError β If the request fails
- publish_lyrics(track_name: str, artist_name: str, album_name: str, duration: int, plain_lyrics: str | None = None, synced_lyrics: str | None = None, publish_token: str | None = None) Dict[str, Any][source]ο
Publish lyrics to LRCLIB. All parameters are required.
Note
If no lyrics are provided, the track will be marked as instrumental.
- Parameters:
track_name (str) β Track name
artist_name (str) β Artist name
album_name (str) β Album name
duration (int) β Duration of the track in seconds
plain_lyrics (str, optional) β Plain lyrics
synced_lyrics (str, optional) β Synced lyrics
publish_token (str, optional) β Publish token to use for publishing lyrics, if not provided, a new one will be generated
- Returns:
Response from the API
- Return type:
Dict[str, Any]
- Raises:
IncorrectPublishTokenError β If the publish token is incorrect
APIError β If the request fails
- request_challenge() CryptographicChallenge[source]ο
Generate a pair of prefix and target strings for the cryptographic challenge. Each challenge has an expiration time of 5 minutes.
The challengeβs solution is a nonce, which can be used to create a Publish Token for submitting lyrics to LRCLIB.
- Return type:
See also
publish_lyricsSubmit lyrics to LRCLIB directly without using the request_challenge method
cryptographic_challenge_solverUse one of the available solvers to solve the challenge
- Raises:
APIError β If the request fails
- search_lyrics(query: str | None = None, track_name: str | None = None, artist_name: str | None = None, album_name: str | None = None) SearchResult[source]ο
Search lyrics on LRCLIB by query, track name, artist name and/or album name.
Note
Either query or track_name is required.
- Parameters:
query (str, optional) β Search query
track_name (str, optional) β Track name
artist_name (str, optional) β Artist name
album_name (str, optional) β Album name
- Return type:
- Raises:
APIError β If the request fails
lrclib.cryptographic_challenge_solver moduleο
A module that provides a class to solve a cryptographic challenge.
- class lrclib.cryptographic_challenge_solver.CryptoChallengeSolver[source]ο
Bases:
objectClass for solving cryptographic challenges.
- static solve(prefix: str, target_hex: str, num_threads: int = 1)[source]ο
Solve the cryptographic challenge.
- Parameters:
prefix (str) β The prefix string of the challenge.
target_hex (str) β The target hash in hexadecimal format.
num_threads (int) β The number of threads to use for solving the challenge.
- Returns:
nonce β The nonce that satisfies the target hash.
- Return type:
str
- class lrclib.cryptographic_challenge_solver.Solution(prefix: str, target_hex: str, nonce: int | None = None)[source]ο
Bases:
objectClass for storing the solution of a cryptographic challenge.
- property is_solved: boolο
Check if the challenge is solved.
- nonce: int | None = Noneο
The nonce that satisfies the target hash.
- prefix: strο
The prefix string of the challenge.
- target_hex: strο
The target hash in hexadecimal format.
lrclib.exceptions moduleο
Exceptions for the LRC API.
- exception lrclib.exceptions.APIError(response: Response)[source]ο
Bases:
RequestExceptionBase class for API errors.
- exception lrclib.exceptions.IncorrectPublishTokenError(response: Response)[source]ο
Bases:
APIErrorRaised when the publish token is incorrect.
- exception lrclib.exceptions.NotFoundError(response: Response)[source]ο
Bases:
APIErrorRaised when a resource is not found.
lrclib.models moduleο
Models for api.py
- class lrclib.models.CryptographicChallenge(prefix: str, target: str)[source]ο
Bases:
BaseModel[CryptographicChallenge]Cryptographic Challenge
- prefix: strο
- target: strο
- class lrclib.models.ErrorResponse(status_code: int, error: str, message: str)[source]ο
Bases:
BaseModel[ErrorResponse]Response sent when an error occurs on the server
- error: strο
- message: strο
- status_code: intο
- class lrclib.models.Lyrics(id: int, name: str, track_name: str, artist_name: str, album_name: str, duration: int, instrumental: bool, plain_lyrics: str | None = None, synced_lyrics: str | None = None, lang: str | None = None, isrc: str | None = None, spotify_id: str | None = None, release_date: datetime | None = None)[source]ο
-
Lyrics object with full information
- album_name: strο
- artist_name: strο
- duration: intο
- id: intο
- instrumental: boolο
if the lyrics are instrumental
- isrc: str | None = Noneο
- lang: str | None = Noneο
- name: strο
- plain_lyrics: str | None = Noneο
- release_date: datetime | None = Noneο
- spotify_id: str | None = Noneο
- synced_lyrics: str | None = Noneο
- track_name: strο
- class lrclib.models.LyricsMinimal(id: int, name: str, track_name: str, artist_name: str, album_name: str, duration: int, instrumental: bool, plain_lyrics: str | None = None, synced_lyrics: str | None = None)[source]ο
Bases:
BaseModel[LyricsMinimal]Lyrics object with minimal information
- album_name: strο
- artist_name: strο
- duration: intο
- id: intο
- instrumental: boolο
- name: strο
- plain_lyrics: str | None = Noneο
- synced_lyrics: str | None = Noneο
- track_name: strο
- class lrclib.models.SearchResult(data: List[LyricsMinimal])[source]ο
Bases:
List[LyricsMinimal]list of LyricsMinimal objects
- classmethod from_list(data: List[Dict[str, Any]]) SearchResult[source]ο
Create a SearchResult object from a list of dictionaries
Module contentsο
LrcLib - A Python library for interacting with the LrcLib.net API.
- class lrclib.LrcLibAPI(user_agent: str, base_url: str | None = None, session: Session | None = None)[source]ο
Bases:
objectCreate a new LrcLibAPI instance. You can optionally pass a custom base URL and a custom requests session.
Note
setting user_agent is not required, but it is recommended by LRCLIB.
- Parameters:
user_agent (str) β User agent to use for the requests
base_url (str, optional) β Base URL to use for the requests
session (requests.Session, optional) β Requests session to use for the requests
- Raises:
UserWarning β If user_agent is not set
Examples
See the π₯Fetching lyrics using the API section for usage examples.
- get_lyrics(track_name: str, artist_name: str, album_name: str, duration: int, cached: bool = False) Lyrics[source]ο
Get lyrics from LRCLIB by track name, artist name, album name and duration.
Note
All parameters are required except cached.
- Parameters:
track_name (str) β Track name
artist_name (str) β Artist name
album_name (str) β Album name
duration (int) β Duration of the track in seconds
cached (bool, optional) β Whether to get cached lyrics or not, defaults to False
- Return type:
- Raises:
NotFoundError β If no lyrics are found
APIError β If the request fails
- get_lyrics_by_id(lrclib_id: str | int) Lyrics[source]ο
Get lyrics from LRCLIB by ID.
- Parameters:
lrclib_id (str | int) β ID of the lyrics
- Return type:
- Raises:
NotFoundError β If no lyrics are found
APIError β If the request fails
- publish_lyrics(track_name: str, artist_name: str, album_name: str, duration: int, plain_lyrics: str | None = None, synced_lyrics: str | None = None, publish_token: str | None = None) Dict[str, Any][source]ο
Publish lyrics to LRCLIB. All parameters are required.
Note
If no lyrics are provided, the track will be marked as instrumental.
- Parameters:
track_name (str) β Track name
artist_name (str) β Artist name
album_name (str) β Album name
duration (int) β Duration of the track in seconds
plain_lyrics (str, optional) β Plain lyrics
synced_lyrics (str, optional) β Synced lyrics
publish_token (str, optional) β Publish token to use for publishing lyrics, if not provided, a new one will be generated
- Returns:
Response from the API
- Return type:
Dict[str, Any]
- Raises:
IncorrectPublishTokenError β If the publish token is incorrect
APIError β If the request fails
- request_challenge() CryptographicChallenge[source]ο
Generate a pair of prefix and target strings for the cryptographic challenge. Each challenge has an expiration time of 5 minutes.
The challengeβs solution is a nonce, which can be used to create a Publish Token for submitting lyrics to LRCLIB.
- Return type:
See also
publish_lyricsSubmit lyrics to LRCLIB directly without using the request_challenge method
cryptographic_challenge_solverUse one of the available solvers to solve the challenge
- Raises:
APIError β If the request fails
- search_lyrics(query: str | None = None, track_name: str | None = None, artist_name: str | None = None, album_name: str | None = None) SearchResult[source]ο
Search lyrics on LRCLIB by query, track name, artist name and/or album name.
Note
Either query or track_name is required.
- Parameters:
query (str, optional) β Search query
track_name (str, optional) β Track name
artist_name (str, optional) β Artist name
album_name (str, optional) β Album name
- Return type:
- Raises:
APIError β If the request fails