From 72d3d1f34adda69dc0e7ae8e9a2a2527bc0f4275 Mon Sep 17 00:00:00 2001 From: Roy Xiang Date: Wed, 9 Mar 2022 14:32:59 +0800 Subject: [PATCH] fix(plaxt): scrobble as "media.resume" if paused --- handler/const.go | 1 + handler/plex.go | 35 ++++++++++++++++------------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/handler/const.go b/handler/const.go index fb30e1e..29d29cb 100644 --- a/handler/const.go +++ b/handler/const.go @@ -46,6 +46,7 @@ const ( const ( sessionUnplayed sessionStatus = iota sessionPlaying + sessionPaused sessionStopped sessionWatched ) diff --git a/handler/plex.go b/handler/plex.go index da68a86..43bd665 100644 --- a/handler/plex.go +++ b/handler/plex.go @@ -106,7 +106,10 @@ func (a sessionData) Check(b sessionData) (bool, bool) { return true, true } if a.progress != b.progress { - return true, false + if a.status == sessionPlaying { + return true, false + } + return true, true } if a.lastEvent != b.lastEvent { return true, false @@ -318,38 +321,32 @@ func (c *PlexClient) syncTimelineWithPlaxt(r *http.Request, user *plexUser) { } var event string + var threshold int switch state { case "playing": - if session.status == sessionPlaying { - if progress >= 100 { - event = webhookEventScrobble - } else { - event = webhookEventResume - } - } else { + threshold = 100 + if session.status == sessionUnplayed || session.status == sessionStopped { event = webhookEventPlay - } - case "paused": - if progress >= watchedThreshold && session.status == sessionPlaying { - event = webhookEventScrobble } else { - event = webhookEventPause + event = webhookEventResume } + case "paused": + threshold = watchedThreshold + event = webhookEventPause case "stopped": - if progress >= watchedThreshold && session.status == sessionPlaying { - event = webhookEventScrobble - } else { - event = webhookEventStop - } + threshold = watchedThreshold + event = webhookEventStop } if event == "" { return + } else if progress >= threshold { + event = webhookEventScrobble } switch event { case webhookEventPlay, webhookEventResume: session.status = sessionPlaying case webhookEventPause: - session.status = sessionStopped + session.status = sessionPaused case webhookEventStop: session.status = sessionStopped go clearCachedMetadata(ratingKey, user.Id)