From 0896861404d098be0ba68d221bdfb4ed420cbd1a Mon Sep 17 00:00:00 2001 From: avelytchko <919635+avelytchko@users.noreply.github.com> Date: Sat, 17 Jan 2026 17:32:48 +0100 Subject: [PATCH] Fix duplicate scrobbling when switching to radio streams - Clear current track data when track length is invalid - Add validation in on_playback_time() to prevent empty track scrobbling - Reset track state in on_playback_stop() to avoid stale data Fixes #4 --- foobar2000/foo_mac_scrobble/play_callback.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/foobar2000/foo_mac_scrobble/play_callback.cpp b/foobar2000/foo_mac_scrobble/play_callback.cpp index 909e3ee..f223337 100644 --- a/foobar2000/foo_mac_scrobble/play_callback.cpp +++ b/foobar2000/foo_mac_scrobble/play_callback.cpp @@ -61,6 +61,10 @@ class scrobble_callback : public play_callback_static if (!(m_length > 0.0 && std::isfinite(m_length))) { console::print("Last.fm Scrobbler: Track length invalid or missing, skipping."); + // Clear current track data to prevent re-scrobbling when switching to streams + m_current_track = LastfmApi::TrackInfo(); + m_scrobbled = false; + m_threshold = 0; return; } @@ -132,6 +136,10 @@ class scrobble_callback : public play_callback_static if (!cfg_enabled.get() || m_scrobbled || p_time < m_threshold) return; + // Don't scrobble if current track data is empty (e.g., after switching to radio streams) + if (m_current_track.artist.empty() || m_current_track.track.empty()) + return; + try { static_api_ptr_t playback_control; @@ -175,6 +183,8 @@ class scrobble_callback : public play_callback_static m_scrobbled = false; m_length = 0; m_threshold = 0; + // Clear current track data to prevent stale data from being used + m_current_track = LastfmApi::TrackInfo(); } void on_playback_pause(bool p_state) override