From 04add15691578316ff3da5b5a07d05b314488370 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 16 May 2026 11:43:32 +0200 Subject: Add scrobbling support (Last.fm + ListenBrainz) and rsp settings reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Full Last.fm API implementation with MD5 signing (track.updateNowPlaying, track.scrobble) - Full ListenBrainz API implementation (/1/submit-listens for playing_now and single) - ScrobbleState in daemon tracking track, start time, and unix timestamp per play - Scrobble threshold: ≥30s play AND (≥half duration OR ≥4 min) - Duration extraction from symphonia codec params into AudioMetadata and Track - Token validation at daemon startup and on config change - ListenBrainz token valid (user: Salmonium) command to re-read config from disk (avoids token in shell history) - Desktop notifications for token validation results - Empty-credential filtering (empty string = no-op) --- tests/scrobbler.rs | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'tests/scrobbler.rs') diff --git a/tests/scrobbler.rs b/tests/scrobbler.rs index f326250..5453748 100644 --- a/tests/scrobbler.rs +++ b/tests/scrobbler.rs @@ -24,54 +24,52 @@ fn test_scrobbler_new_with_none() { } #[test] -fn test_scrobbler_now_playing_no_api_key() { +fn test_scrobbler_now_playing_no_creds() { let scrobbler = Scrobbler::new(None, None, None, None); scrobbler.now_playing("Artist", "Track", Some("Album")); } #[test] -fn test_scrobbler_now_playing_with_api_key() { +fn test_scrobbler_now_playing_partial_lastfm() { + // Only api_key set — not enough to trigger Last.fm (needs secret + session_key too) let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); scrobbler.now_playing("Artist", "Track", Some("Album")); } #[test] -fn test_scrobbler_scrobble_no_keys() { - let scrobbler = Scrobbler::new(None, None, None, None); - scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); -} - -#[test] -fn test_scrobbler_scrobble_with_lastfm() { +fn test_scrobbler_now_playing_no_album() { let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); - scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); + scrobbler.now_playing("Artist", "Track", None); } #[test] -fn test_scrobbler_scrobble_with_listenbrainz() { - let scrobbler = Scrobbler::new(None, None, None, Some("token".to_string())); +fn test_scrobbler_scrobble_no_creds() { + let scrobbler = Scrobbler::new(None, None, None, None); scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); } #[test] -fn test_scrobbler_scrobble_with_both() { - let scrobbler = Scrobbler::new( - Some("api_key".to_string()), - None, - None, - Some("token".to_string()), - ); - scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); +fn test_scrobbler_scrobble_no_album() { + let scrobbler = Scrobbler::new(None, None, None, None); + scrobbler.scrobble("Artist", "Track", None, 1234567890); } #[test] -fn test_scrobbler_now_playing_no_album() { +fn test_scrobbler_scrobble_partial_lastfm() { + // Only api_key set — not enough to trigger Last.fm let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); - scrobbler.now_playing("Artist", "Track", None); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); } #[test] -fn test_scrobbler_scrobble_no_album() { - let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); - scrobbler.scrobble("Artist", "Track", None, 1234567890); +fn test_scrobbler_skip_empty_credentials() { + // Empty strings should be treated as unset — no HTTP requests + let scrobbler = Scrobbler::new( + Some("".to_string()), + Some("".to_string()), + Some("".to_string()), + Some("".to_string()), + ); + scrobbler.now_playing("Artist", "Track", Some("Album")); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); } -- cgit v1.2.3