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