[scrobbles] Add auto stopping
All checks were successful
build & deploy / test (push) Successful in 1m44s
build & deploy / deploy (push) Successful in 27s

This commit is contained in:
2026-03-14 13:19:18 -04:00
parent 1f67d4c0a6
commit 18d21e6651
3 changed files with 33 additions and 6 deletions

View File

@ -41,7 +41,11 @@ from profiles.utils import (
)
from puzzles.models import Puzzle
from scrobbles import dataclasses as logdata
from scrobbles.constants import LONG_PLAY_MEDIA, MEDIA_END_PADDING_SECONDS
from scrobbles.constants import (
LONG_PLAY_MEDIA,
MEDIA_END_PADDING_SECONDS,
AUTO_FINISH_MEDIA,
)
from scrobbles.importers.lastfm import LastFM
from scrobbles.notifications import ScrobbleNtfyNotification
from scrobbles.stats import build_charts
@ -1556,6 +1560,25 @@ class Scrobble(TimeStampedModel):
return beyond_completion
@property
def is_over_time(self) -> bool:
"""Has the scrobble overrun it's time?"""
elapsed_scrobble_seconds = (timezone.now() - self.timestamp).seconds
if elapsed_scrobble_seconds > self.media_obj.run_time_seconds:
return True
return False
def auto_finish(self) -> bool:
"""Check if media type should auto finish.
Return True if scrobble is finished, False if not.
"""
if self.is_over_time and self.media_type in AUTO_FINISH_MEDIA.values():
self.stop(force_finish=True)
return True
return False
def calculate_reading_stats(self, commit=True):
# --- Sort safely by numeric page_number ---
def safe_page_number(entry):