소스 검색

Add fallback duration tracking for Mopidy

Unlike Jellyfin, Mopidy's webhook only gives us a start and stopped call
to determine when a track should be scrobbled.  This means we don't have
continous updating of playback ticks.

This commit adds a fallback when ticks are not there to use the track
duration and time since the scrobble was created. That said, this is not
perfect. If you pause the track and start again, the progress will get
very out of whack. But thankfully, Mopidy only sends us audio, and it's
rare that audio tracks are paused repeatedly and started again before
finishing a scrobble. So hopefully this shouldn't happen very often.
Colin Powell 2 년 전
부모
커밋
1ec4333856
1개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      vrobbler/apps/scrobbles/models.py

+ 15 - 0
vrobbler/apps/scrobbles/models.py

@@ -42,6 +42,12 @@ class Scrobble(TimeStampedModel):
                 (self.playback_position_ticks / self.media_run_time_ticks)
                 * 100
             )
+        # If we don't have media_run_time_ticks, let's guess from created time
+        now = timezone.now()
+        playback_duration = (now - self.created).seconds
+        if playback_duration and self.track.run_time:
+            return int((playback_duration / int(self.track.run_time)) * 100)
+
         return 0
 
     @property
@@ -97,6 +103,15 @@ class Scrobble(TimeStampedModel):
             .order_by('-modified')
             .first()
         )
+        # Check if playback_position_ticks has changed from this scrobble
+        scrobble_changed = (
+            scrobble
+            and scrobble.playback_position_ticks
+            != jellyfin_data['playback_position_ticks']
+        )
+        if not scrobble_changed:
+            logger.info('Scrobble playback has not changed, not scrobbling')
+            return
 
         # Backoff is how long until we consider this a new scrobble
         backoff = timezone.now() + timedelta(minutes=VIDEO_BACKOFF)