From 113f200eb7c66034f26d078abfbcb822a08a0b10 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 5 May 2024 22:08:52 -0400 Subject: [PATCH] [scrobbles] Move scrobble_log to log --- .../0055_rename_scrobble_log_scrobble_log.py | 18 ++++++++++++++++++ vrobbler/apps/scrobbles/models.py | 8 ++++---- vrobbler/apps/scrobbles/scrobblers.py | 7 +++---- vrobbler/apps/scrobbles/tsv.py | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 vrobbler/apps/scrobbles/migrations/0055_rename_scrobble_log_scrobble_log.py diff --git a/vrobbler/apps/scrobbles/migrations/0055_rename_scrobble_log_scrobble_log.py b/vrobbler/apps/scrobbles/migrations/0055_rename_scrobble_log_scrobble_log.py new file mode 100644 index 0000000..abec897 --- /dev/null +++ b/vrobbler/apps/scrobbles/migrations/0055_rename_scrobble_log_scrobble_log.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-05-06 02:08 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("scrobbles", "0054_remove_scrobble_notes_and_more"), + ] + + operations = [ + migrations.RenameField( + model_name="scrobble", + old_name="scrobble_log", + new_name="log", + ), + ] diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 0873e4a..76ca74f 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -521,7 +521,7 @@ class Scrobble(TimeStampedModel): # Metadata source = models.CharField(max_length=255, **BNULL) - scrobble_log = models.JSONField(**BNULL) + log = models.JSONField(**BNULL) timezone = models.CharField(max_length=50, **BNULL) # Fields for keeping track of book data @@ -992,10 +992,10 @@ class Scrobble(TimeStampedModel): if existing_locations := location.in_proximity(named=True): existing_location = existing_locations.first() - scrobble.scrobble_log[ + scrobble.log[ pendulum.now().timestamp ] = f"Location {location.id} too close to this scrobble" - scrobble.save(update_fields=["scrobble_log"]) + scrobble.save(update_fields=["log"]) logger.info( f"[scrobbling] finished - found existing named location", extra={ @@ -1074,7 +1074,7 @@ class Scrobble(TimeStampedModel): cls, scrobble_data: dict, ) -> "Scrobble": - scrobble_data["scrobble_log"] = {} + scrobble_data["log"] = {} scrobble = cls.objects.create( **scrobble_data, ) diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index 62bb3c2..0c88d16 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -141,7 +141,7 @@ def build_scrobble_dict(data_dict: dict, user_id: int) -> dict: "timestamp": parse(data_dict.get("UtcTimestamp")), "playback_position_seconds": playback_seconds, "source": data_dict.get("ClientName", "Vrobbler"), - "scrobble_log": {"media_source_id": data_dict.get("MediaSourceId")}, + "log": {"media_source_id": data_dict.get("MediaSourceId")}, "jellyfin_status": jellyfin_status, } @@ -362,8 +362,7 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble: provider = LOCATION_PROVIDERS[data_dict.get("prov")] - scrobble.scrobble_log["update"] = { - "timestamp": data_dict.get("time"), + scrobble.log[data_dict.get("time")] = { "position_provider": provider, } if scrobble.timestamp: @@ -371,7 +370,7 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble: timezone.now() - scrobble.timestamp ).seconds - scrobble.save(update_fields=["scrobble_log", "playback_position_seconds"]) + scrobble.save(update_fields=["log", "playback_position_seconds"]) logger.info( "[webhook] gpslogger scrobble request received", extra={ diff --git a/vrobbler/apps/scrobbles/tsv.py b/vrobbler/apps/scrobbles/tsv.py index 4f557f6..73c9917 100644 --- a/vrobbler/apps/scrobbles/tsv.py +++ b/vrobbler/apps/scrobbles/tsv.py @@ -75,7 +75,7 @@ def process_audioscrobbler_tsv_file(file_path, user_id, user_tz=None): user_id=user_id, timestamp=timestamp, source=source, - scrobble_log={"rockbox_info": rockbox_info} + log={"rockbox_info": rockbox_info} track=track, played_to_completion=True, in_progress=False,