lrclib_api_rs/
types.rs

1use serde::{Deserialize, Serialize};
2use strum::EnumIs;
3
4// Define response structs based on API sample responses.
5#[derive(Debug, Deserialize, Serialize, Default)]
6#[serde(rename_all = "camelCase")]
7pub struct LyricsData {
8    /// lyrics id in LRCLib database
9    pub id: u64,
10    /// maybe deprecated fallback of track_name
11    pub name: String,
12    /// Title of the track
13    pub track_name: String,
14    /// Track's artist name
15    pub artist_name: String,
16    /// Track's album name
17    pub album_name: Option<String>,
18    /// duration in seconds
19    pub duration: Option<f64>,
20    /// instrumental means both plain_lyrics and synced_lyrics are empty.
21    pub instrumental: bool,
22    /// plain lyrics without timestamp
23    pub plain_lyrics: Option<String>,
24    /// synced lyrics as standard LRC
25    pub synced_lyrics: Option<String>,
26}
27
28/// check comments on LyricsData.
29#[derive(Debug, Deserialize, Serialize, Default)]
30#[serde(rename_all = "camelCase")]
31pub struct LyricsPublishData {
32    pub track_name: String,
33    pub artist_name: String,
34    pub album_name: String,
35    pub duration: f64,
36    pub plain_lyrics: String,
37    pub synced_lyrics: String,
38}
39
40#[derive(Debug, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub struct ErrorResponse {
43    pub status_code: u32,
44    pub name: String,
45    pub message: String,
46}
47
48// Enum for wrapping successful and error responses for the /api/get endpoint.
49#[derive(Debug, Deserialize, EnumIs)]
50#[serde(untagged)]
51pub enum GetLyricsResponse {
52    Success(LyricsData),
53    Error(ErrorResponse),
54}
55
56// Enum for wrapping success and error responses for the /api/publish endpoint.
57#[derive(Debug, Deserialize, EnumIs)]
58#[serde(untagged)]
59pub enum PublishResponse {
60    Created,              // Represents a successful publish (201 Created).
61    Error(ErrorResponse), // Error response
62}
63
64#[derive(Debug, Deserialize)]
65#[serde(rename_all = "camelCase")]
66pub struct PublishChallenge {
67    pub prefix: String,
68    pub target: String,
69}