diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-16 11:43:32 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-16 11:43:32 +0200 |
| commit | 04add15691578316ff3da5b5a07d05b314488370 (patch) | |
| tree | 458b1066001697faa75466d51c7dfd9008ccac16 /tests/scrobbler.rs | |
| parent | aesthetic changes (diff) | |
| download | rsplayer-04add15691578316ff3da5b5a07d05b314488370.tar.gz rsplayer-04add15691578316ff3da5b5a07d05b314488370.zip | |
Add scrobbling support (Last.fm + ListenBrainz) and rsp settings reload
- 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)
Diffstat (limited to '')
| -rw-r--r-- | tests/scrobbler.rs | 48 |
1 files changed, 23 insertions, 25 deletions
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() { | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | #[test] | 26 | #[test] |
| 27 | fn test_scrobbler_now_playing_no_api_key() { | 27 | fn test_scrobbler_now_playing_no_creds() { |
| 28 | let scrobbler = Scrobbler::new(None, None, None, None); | 28 | let scrobbler = Scrobbler::new(None, None, None, None); |
| 29 | scrobbler.now_playing("Artist", "Track", Some("Album")); | 29 | scrobbler.now_playing("Artist", "Track", Some("Album")); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | #[test] | 32 | #[test] |
| 33 | fn test_scrobbler_now_playing_with_api_key() { | 33 | fn test_scrobbler_now_playing_partial_lastfm() { |
| 34 | // Only api_key set — not enough to trigger Last.fm (needs secret + session_key too) | ||
| 34 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); | 35 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); |
| 35 | scrobbler.now_playing("Artist", "Track", Some("Album")); | 36 | scrobbler.now_playing("Artist", "Track", Some("Album")); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | #[test] | 39 | #[test] |
| 39 | fn test_scrobbler_scrobble_no_keys() { | 40 | fn test_scrobbler_now_playing_no_album() { |
| 40 | let scrobbler = Scrobbler::new(None, None, None, None); | ||
| 41 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); | ||
| 42 | } | ||
| 43 | |||
| 44 | #[test] | ||
| 45 | fn test_scrobbler_scrobble_with_lastfm() { | ||
| 46 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); | 41 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); |
| 47 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); | 42 | scrobbler.now_playing("Artist", "Track", None); |
| 48 | } | 43 | } |
| 49 | 44 | ||
| 50 | #[test] | 45 | #[test] |
| 51 | fn test_scrobbler_scrobble_with_listenbrainz() { | 46 | fn test_scrobbler_scrobble_no_creds() { |
| 52 | let scrobbler = Scrobbler::new(None, None, None, Some("token".to_string())); | 47 | let scrobbler = Scrobbler::new(None, None, None, None); |
| 53 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); | 48 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); |
| 54 | } | 49 | } |
| 55 | 50 | ||
| 56 | #[test] | 51 | #[test] |
| 57 | fn test_scrobbler_scrobble_with_both() { | 52 | fn test_scrobbler_scrobble_no_album() { |
| 58 | let scrobbler = Scrobbler::new( | 53 | let scrobbler = Scrobbler::new(None, None, None, None); |
| 59 | Some("api_key".to_string()), | 54 | scrobbler.scrobble("Artist", "Track", None, 1234567890); |
| 60 | None, | ||
| 61 | None, | ||
| 62 | Some("token".to_string()), | ||
| 63 | ); | ||
| 64 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); | ||
| 65 | } | 55 | } |
| 66 | 56 | ||
| 67 | #[test] | 57 | #[test] |
| 68 | fn test_scrobbler_now_playing_no_album() { | 58 | fn test_scrobbler_scrobble_partial_lastfm() { |
| 59 | // Only api_key set — not enough to trigger Last.fm | ||
| 69 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); | 60 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); |
| 70 | scrobbler.now_playing("Artist", "Track", None); | 61 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); |
| 71 | } | 62 | } |
| 72 | 63 | ||
| 73 | #[test] | 64 | #[test] |
| 74 | fn test_scrobbler_scrobble_no_album() { | 65 | fn test_scrobbler_skip_empty_credentials() { |
| 75 | let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); | 66 | // Empty strings should be treated as unset — no HTTP requests |
| 76 | scrobbler.scrobble("Artist", "Track", None, 1234567890); | 67 | let scrobbler = Scrobbler::new( |
| 68 | Some("".to_string()), | ||
| 69 | Some("".to_string()), | ||
| 70 | Some("".to_string()), | ||
| 71 | Some("".to_string()), | ||
| 72 | ); | ||
| 73 | scrobbler.now_playing("Artist", "Track", Some("Album")); | ||
| 74 | scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); | ||
| 77 | } | 75 | } |
