[scrobbles] Move scrobble_log to log

This commit is contained in:
2024-05-05 22:08:52 -04:00
parent 1b5ffd2a3c
commit 113f200eb7
4 changed files with 26 additions and 9 deletions

View File

@ -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",
),
]

View File

@ -521,7 +521,7 @@ class Scrobble(TimeStampedModel):
# Metadata # Metadata
source = models.CharField(max_length=255, **BNULL) source = models.CharField(max_length=255, **BNULL)
scrobble_log = models.JSONField(**BNULL) log = models.JSONField(**BNULL)
timezone = models.CharField(max_length=50, **BNULL) timezone = models.CharField(max_length=50, **BNULL)
# Fields for keeping track of book data # Fields for keeping track of book data
@ -992,10 +992,10 @@ class Scrobble(TimeStampedModel):
if existing_locations := location.in_proximity(named=True): if existing_locations := location.in_proximity(named=True):
existing_location = existing_locations.first() existing_location = existing_locations.first()
scrobble.scrobble_log[ scrobble.log[
pendulum.now().timestamp pendulum.now().timestamp
] = f"Location {location.id} too close to this scrobble" ] = f"Location {location.id} too close to this scrobble"
scrobble.save(update_fields=["scrobble_log"]) scrobble.save(update_fields=["log"])
logger.info( logger.info(
f"[scrobbling] finished - found existing named location", f"[scrobbling] finished - found existing named location",
extra={ extra={
@ -1074,7 +1074,7 @@ class Scrobble(TimeStampedModel):
cls, cls,
scrobble_data: dict, scrobble_data: dict,
) -> "Scrobble": ) -> "Scrobble":
scrobble_data["scrobble_log"] = {} scrobble_data["log"] = {}
scrobble = cls.objects.create( scrobble = cls.objects.create(
**scrobble_data, **scrobble_data,
) )

View File

@ -141,7 +141,7 @@ def build_scrobble_dict(data_dict: dict, user_id: int) -> dict:
"timestamp": parse(data_dict.get("UtcTimestamp")), "timestamp": parse(data_dict.get("UtcTimestamp")),
"playback_position_seconds": playback_seconds, "playback_position_seconds": playback_seconds,
"source": data_dict.get("ClientName", "Vrobbler"), "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, "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")] provider = LOCATION_PROVIDERS[data_dict.get("prov")]
scrobble.scrobble_log["update"] = { scrobble.log[data_dict.get("time")] = {
"timestamp": data_dict.get("time"),
"position_provider": provider, "position_provider": provider,
} }
if scrobble.timestamp: if scrobble.timestamp:
@ -371,7 +370,7 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble:
timezone.now() - scrobble.timestamp timezone.now() - scrobble.timestamp
).seconds ).seconds
scrobble.save(update_fields=["scrobble_log", "playback_position_seconds"]) scrobble.save(update_fields=["log", "playback_position_seconds"])
logger.info( logger.info(
"[webhook] gpslogger scrobble request received", "[webhook] gpslogger scrobble request received",
extra={ extra={

View File

@ -75,7 +75,7 @@ def process_audioscrobbler_tsv_file(file_path, user_id, user_tz=None):
user_id=user_id, user_id=user_id,
timestamp=timestamp, timestamp=timestamp,
source=source, source=source,
scrobble_log={"rockbox_info": rockbox_info} log={"rockbox_info": rockbox_info}
track=track, track=track,
played_to_completion=True, played_to_completion=True,
in_progress=False, in_progress=False,