Add rudimentary manual scrobbling
This commit is contained in:
@ -42,24 +42,27 @@ class Scrobble(TimeStampedModel):
|
||||
|
||||
@property
|
||||
def percent_played(self) -> int:
|
||||
if (
|
||||
self.playback_position_ticks
|
||||
and self.media_obj.run_time_ticks
|
||||
and self.source != 'Mopidy'
|
||||
):
|
||||
return int(
|
||||
(self.playback_position_ticks / self.media_obj.run_time_ticks)
|
||||
* 100
|
||||
)
|
||||
# If we don't have media_obj.run_time_ticks, let's guess from created time
|
||||
now = timezone.now()
|
||||
playback_duration = (now - self.created).seconds
|
||||
if playback_duration and self.media_obj.run_time:
|
||||
return int(
|
||||
(playback_duration / int(self.media_obj.run_time)) * 100
|
||||
)
|
||||
playback_ticks = None
|
||||
percent_played = 100
|
||||
|
||||
return 0
|
||||
if not self.media_obj.run_time_ticks:
|
||||
logger.warning(
|
||||
f"{self} has no run_time_ticks value, cannot show percent played"
|
||||
)
|
||||
return percent_played
|
||||
|
||||
playback_ticks = self.playback_position_ticks
|
||||
if not playback_ticks:
|
||||
logger.info(
|
||||
"No playback_position_ticks, estimating based on creation time"
|
||||
)
|
||||
playback_ticks = (timezone.now() - self.timestamp).seconds * 1000
|
||||
|
||||
percent = int((playback_ticks / self.media_obj.run_time_ticks) * 100)
|
||||
|
||||
if percent > 100:
|
||||
percent = 100
|
||||
return percent
|
||||
|
||||
@property
|
||||
def media_obj(self):
|
||||
|
||||
Reference in New Issue
Block a user