Track paused state
MODIFY
plex_trakt_sync/commands/watch.py
plex_trakt_sync/commands/watch.py
@@ -25,9 +25,13 @@ def __call__(self, message):
self.scrobble(tm, percent, item["state"])
def scrobble(self, tm, percent, state):
- if state == "stopped" and tm in self.play_state:
+ if state == "stopped":
+ if tm not in self.play_state:
+ scrobbler = self.trakt.scrobble(tm, 0)
+ self.trakt.scrobbler_stop(scrobbler)
+ else:
scrobbler = self.play_state[tm]
- self.trakt.scrobbler_stop(scrobbler, percent)
+ self.trakt.scrobbler_stop(scrobbler)
del self.play_state[tm]
if state == "playing":
@@ -38,6 +42,15 @@ def scrobble(self, tm, percent, state):
scrobbler = self.play_state[tm]
self.trakt.scrobbler_update(scrobbler, percent)
+ if state == "paused":
+ if tm not in self.play_state:
+ scrobbler = self.trakt.scrobble(tm, 0)
+ self.play_state[tm] = scrobbler
+ self.trakt.scrobbler_pause(scrobbler)
+ else:
+ scrobbler = self.play_state[tm]
+ self.trakt.scrobbler_pause(scrobbler)
+
def filter_media(self, message):
for item in self.filter_playing(message):
pm = self.plex.fetch_item(item["ratingKey"])
@@ -67,8 +80,7 @@ def filter_playing(self, message):
for item in message["PlaySessionStateNotification"]:
state = item["state"]
print(f"State: {state}")
- # "playing", 'buffering', 'stopped'
- if state not in ["playing", "stopped"]:
+ if state not in ["playing", "stopped", "paused"]:
continue
yield item

Track paused state