diff --git a/vrobbler/apps/scrobbles/migrations/0029_remove_scrobble_video_game_minutes_played_and_more.py b/vrobbler/apps/scrobbles/migrations/0029_remove_scrobble_video_game_minutes_played_and_more.py new file mode 100644 index 0000000..f629344 --- /dev/null +++ b/vrobbler/apps/scrobbles/migrations/0029_remove_scrobble_video_game_minutes_played_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.5 on 2023-03-06 15:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("scrobbles", "0028_scrobble_video_game_minutes_played"), + ] + + operations = [ + migrations.RemoveField( + model_name="scrobble", + name="video_game_minutes_played", + ), + migrations.AddField( + model_name="scrobble", + name="long_play_seconds", + field=models.BigIntegerField(blank=True, null=True), + ), + ] diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 88278dd..14fb055 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -418,7 +418,7 @@ class Scrobble(TimeStampedModel): # Fields for keeping track long content like books and games book_pages_read = models.IntegerField(**BNULL) - video_game_minutes_played = models.IntegerField(**BNULL) + long_play_seconds = models.BigIntegerField(**BNULL) long_play_complete = models.BooleanField(**BNULL) def save(self, *args, **kwargs): @@ -601,7 +601,7 @@ class Scrobble(TimeStampedModel): "Syncing long play media playback time to elapsed time since start" ) now = timezone.now() - updated_playback = (now - self.timestamp).seconds / 60 + updated_playback = (now - self.timestamp).seconds media_filter = models.Q(video_game=self.video_game) if class_name == "Book": @@ -612,20 +612,21 @@ class Scrobble(TimeStampedModel): played_to_completion=True, long_play_complete=False, ).last() - self.video_game_minutes_played = int(updated_playback) + self.long_play_seconds = int(updated_playback) if last_scrobble: - self.video_game_minutes_played = ( + self.long_play_seconds = ( int(last_scrobble.playback_position) + updated_playback ) self.playback_position = int(updated_playback) + self.playback_position_ticks = int(updated_playback) * 1000 self.played_to_completion = True self.save( update_fields=[ "playback_position", "playback_position_ticks", "played_to_completion", - "video_game_minutes_played", + "long_play_seconds", ] ) return diff --git a/vrobbler/apps/videogames/templatetags/naturalduration.py b/vrobbler/apps/videogames/templatetags/naturalduration.py index 6c7a98b..76e2ab3 100644 --- a/vrobbler/apps/videogames/templatetags/naturalduration.py +++ b/vrobbler/apps/videogames/templatetags/naturalduration.py @@ -6,8 +6,9 @@ register = template.Library() @register.filter def natural_duration(value): value = int(value) - hours = int(value / 60) - minutes = value - (hours * 60) + total_minutes = int(value / 60) + hours = int(total_minutes / 60) + minutes = total_minutes - (hours * 60) value_str = "" if minutes: value_str = f"{minutes} minutes"