Skip to content

Commit

Permalink
fix(plaxt): scrobble as "media.resume" if paused
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyXiang committed Mar 9, 2022
1 parent 9c7ab8d commit 72d3d1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions handler/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
const (
sessionUnplayed sessionStatus = iota
sessionPlaying
sessionPaused
sessionStopped
sessionWatched
)
35 changes: 16 additions & 19 deletions handler/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 72d3d1f

Please sign in to comment.