Skip to content

Commit 3388bd1

Browse files
committed
fix(plaxt): update session data whenever it is changed
1 parent c681a1c commit 3388bd1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

handler/plex.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func (c *PlexClient) ScrobbleToPlaxt(notification plex.PlaySessionStateNotificat
187187
return
188188
}
189189
var session sessionData
190+
sessionChanged := false
190191
if c.getPlayerSession(notification.SessionKey) {
191192
session = c.sessions[notification.SessionKey]
192193
} else {
@@ -201,7 +202,7 @@ func (c *PlexClient) ScrobbleToPlaxt(notification plex.PlaySessionStateNotificat
201202
}
202203

203204
var externalGuids []plexhooks.ExternalGuid
204-
if session.status == sessionUnplayed && strings.HasPrefix(session.metadata.GUID, "plex://") {
205+
if session.guids == nil {
205206
metadata := c.getMetadata(notification.RatingKey)
206207
if metadata == nil {
207208
return
@@ -214,6 +215,7 @@ func (c *PlexClient) ScrobbleToPlaxt(notification plex.PlaySessionStateNotificat
214215
})
215216
}
216217
session.guids = externalGuids
218+
sessionChanged = true
217219
} else {
218220
externalGuids = session.guids
219221
}
@@ -244,10 +246,13 @@ func (c *PlexClient) ScrobbleToPlaxt(notification plex.PlaySessionStateNotificat
244246
return
245247
} else if event == "media.scrobble" {
246248
session.status = sessionWatched
247-
c.sessions[notification.SessionKey] = session
249+
sessionChanged = true
248250
go clearCachedMetadata()
249251
} else if session.status == sessionUnplayed {
250252
session.status = sessionPlaying
253+
sessionChanged = true
254+
}
255+
if sessionChanged {
251256
c.sessions[notification.SessionKey] = session
252257
}
253258

@@ -336,6 +341,7 @@ func (c *PlexClient) getPlayerSession(sessionKey string) (isFound bool) {
336341
if _, ok := c.sessions[session.SessionKey]; !ok {
337342
c.sessions[session.SessionKey] = sessionData{
338343
metadata: session,
344+
guids: nil,
339345
status: sessionUnplayed,
340346
}
341347
}

0 commit comments

Comments
 (0)