Skip to main content

utils/lyrics/
request.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct LyricsServerAuth {
3    pub url: String,
4    pub token: Option<String>,
5    pub user_id: Option<String>,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct LyricsRequest {
10    pub artist: String,
11    pub title: String,
12    pub album: String,
13    pub duration: u64,
14    pub track_path: String,
15    pub server: Option<LyricsServerAuth>,
16    pub prefer_local: bool,
17    pub enable_musixmatch: bool,
18}
19
20impl LyricsRequest {
21    pub fn new(
22        artist: impl Into<String>,
23        title: impl Into<String>,
24        album: impl Into<String>,
25        duration: u64,
26        track_path: impl Into<String>,
27    ) -> Self {
28        Self {
29            artist: artist.into(),
30            title: title.into(),
31            album: album.into(),
32            duration,
33            track_path: track_path.into(),
34            server: None,
35            prefer_local: false,
36            enable_musixmatch: false,
37        }
38    }
39
40    pub fn with_server(
41        mut self,
42        url: Option<&str>,
43        token: Option<&str>,
44        user_id: Option<&str>,
45    ) -> Self {
46        self.server = url.map(|url| LyricsServerAuth {
47            url: url.to_string(),
48            token: token.map(ToString::to_string),
49            user_id: user_id.map(ToString::to_string),
50        });
51        self
52    }
53
54    pub fn prefer_local(mut self, value: bool) -> Self {
55        self.prefer_local = value;
56        self
57    }
58
59    pub fn enable_musixmatch(mut self, value: bool) -> Self {
60        self.enable_musixmatch = value;
61        self
62    }
63
64    pub(crate) fn cache_key(&self) -> String {
65        super::lyrics_cache_key(
66            &self.artist,
67            &self.title,
68            &self.album,
69            self.duration,
70            &self.track_path,
71            self.enable_musixmatch,
72        )
73    }
74}