[scrobbles] Add auto stopping
This commit is contained in:
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user