1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
use reqwest::Client;
#[allow(dead_code)]
pub struct Scrobbler {
pub lastfm_api_key: Option<String>,
pub lastfm_api_secret: Option<String>,
pub lastfm_session_key: Option<String>,
pub listenbrainz_token: Option<String>,
client: Client,
}
#[allow(dead_code)]
impl Scrobbler {
pub fn new(
lastfm_api_key: Option<String>,
lastfm_api_secret: Option<String>,
lastfm_session_key: Option<String>,
listenbrainz_token: Option<String>,
) -> Self {
Scrobbler {
lastfm_api_key,
lastfm_api_secret,
lastfm_session_key,
listenbrainz_token,
client: Client::new(),
}
}
pub fn now_playing(&self, artist: &str, track: &str, album: Option<&str>) {
if let Some(api_key) = &self.lastfm_api_key {
let _ = self.send_lastfm_now_playing(api_key, artist, track, album);
}
}
pub fn scrobble(&self, artist: &str, track: &str, album: Option<&str>, timestamp: u64) {
if let Some(api_key) = &self.lastfm_api_key {
let _ = self.send_lastfm_scrobble(api_key, artist, track, album, timestamp);
}
if let Some(token) = &self.listenbrainz_token {
let _ = self.send_listenbrainz_scrobble(token, artist, track, album, timestamp);
}
}
fn send_lastfm_now_playing(
&self,
_api_key: &str,
_artist: &str,
_track: &str,
_album: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
fn send_lastfm_scrobble(
&self,
_api_key: &str,
_artist: &str,
_track: &str,
_album: Option<&str>,
_timestamp: u64,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
fn send_listenbrainz_scrobble(
&self,
_token: &str,
_artist: &str,
_track: &str,
_album: Option<&str>,
_timestamp: u64,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
}
|