From a9aa5a6741b35538122f868c3573fbf08e913c4d Mon Sep 17 00:00:00 2001 From: jcorporation Date: Fri, 24 Aug 2018 11:19:59 +0100 Subject: [PATCH] Fix: handle duplicate idle player events for playCount updates --- src/mpd_client.c | 3 ++- src/mpd_client.h | 2 ++ src/mympd.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index 4e953bc..350512d 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -562,9 +562,10 @@ void mympd_parse_idle(struct mg_mgr *s, int idle_bitmask) { break; case MPD_IDLE_PLAYER: len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.last_song_id, &mpd.queue_version, &mpd.queue_length); - if (config.stickers && mpd.song_id != mpd.last_song_id) { + if (config.stickers && mpd.song_id != mpd.last_song_id && mpd.last_update_sticker_song_id != mpd.song_id) { mympd_count_song_id(mpd.song_id, "playCount", 1); mympd_last_played_song_id(mpd.song_id); + mpd.last_update_sticker_song_id = mpd.song_id; } break; case MPD_IDLE_MIXER: diff --git a/src/mpd_client.h b/src/mpd_client.h index e6f7263..729dc15 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -127,6 +127,8 @@ struct t_mpd { unsigned queue_version; unsigned queue_length; int timeout; + + int last_update_sticker_song_id; } mpd; typedef struct { diff --git a/src/mympd.c b/src/mympd.c index 67a92b0..9cc043e 100644 --- a/src/mympd.c +++ b/src/mympd.c @@ -183,6 +183,8 @@ int main(int argc, char **argv) { config.mixramp = true; mpd.timeout = 3000; + mpd.last_update_sticker_song_id = -1; + mpd.last_song_id = -1; if (argc == 2) { printf("Parsing config file: %s\n", argv[1]);