From 0db5bbe36c3908a98311ea37e090f90605a576c7 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 17 Feb 2023 14:05:06 -0500 Subject: [PATCH] Fix users not being added to tsv and lastfm imports --- vrobbler/apps/scrobbles/lastfm.py | 3 ++- vrobbler/apps/scrobbles/models.py | 2 +- vrobbler/apps/scrobbles/tsv.py | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vrobbler/apps/scrobbles/lastfm.py b/vrobbler/apps/scrobbles/lastfm.py index 64d5043..5d36977 100644 --- a/vrobbler/apps/scrobbles/lastfm.py +++ b/vrobbler/apps/scrobbles/lastfm.py @@ -90,7 +90,7 @@ class LastFM: return created @staticmethod - def undo_lastfm_import(process_log, dryrun=True): + def undo_lastfm_import(process_log, dryrun=False): """Given a newline separated list of scrobbles, delete them""" from scrobbles.models import Scrobble @@ -155,6 +155,7 @@ class LastFM: logger.info(f"{artist},{scrobble.track.title},{timestamp}") scrobbles.append( { + "user": self.vrobbler_user, "artist": artist, "album": scrobble.album, "title": scrobble.track.title, diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 4473445..2c10147 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -48,7 +48,7 @@ class AudioScrobblerTSVImport(TimeStampedModel): if self.user: tz = self.user.profile.tzinfo scrobbles = process_audioscrobbler_tsv_file( - self.tsv_file.path, user_tz=tz + self.tsv_file.path, self.user.id, user_tz=tz ) self.process_log = "" if scrobbles: diff --git a/vrobbler/apps/scrobbles/tsv.py b/vrobbler/apps/scrobbles/tsv.py index 990e650..7a66b62 100644 --- a/vrobbler/apps/scrobbles/tsv.py +++ b/vrobbler/apps/scrobbles/tsv.py @@ -13,7 +13,7 @@ from music.utils import ( logger = logging.getLogger(__name__) -def process_audioscrobbler_tsv_file(file_path, user_tz=None): +def process_audioscrobbler_tsv_file(file_path, user_id, user_tz=None): """Takes a path to a file of TSV data and imports it as past scrobbles""" new_scrobbles = [] if not user_tz: @@ -55,6 +55,7 @@ def process_audioscrobbler_tsv_file(file_path, user_tz=None): ) new_scrobble = Scrobble( + user_id=user_id, timestamp=timestamp, source=source, source_id=source_id, @@ -79,7 +80,7 @@ def process_audioscrobbler_tsv_file(file_path, user_tz=None): return created -def undo_audioscrobbler_tsv_import(process_log, dryrun=True): +def undo_audioscrobbler_tsv_import(process_log, dryrun=False): """Accepts the log from a TSV import and removes the scrobbles""" if not process_log: logger.warning("No lines in process log found to undo")