From 68a6d58339dcffdead4cd19d0a6ab48513074736 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Mon, 4 Nov 2024 10:13:42 -0500 Subject: [PATCH] [tsv] Try fixing our lookup when titla and MB id are none --- vrobbler/apps/music/utils.py | 19 ++++++++++++++----- vrobbler/apps/scrobbles/tsv.py | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/vrobbler/apps/music/utils.py b/vrobbler/apps/music/utils.py index ddad175..202350d 100644 --- a/vrobbler/apps/music/utils.py +++ b/vrobbler/apps/music/utils.py @@ -111,11 +111,13 @@ def get_or_create_track(post_data: dict, post_keys: dict) -> Track: artist_name, mbid=artist_mb_id, ) - album = get_or_create_album( - album_title, - artist=artist, - mbid=album_mb_id, - ) + album = None + if album_mb_id: + album = get_or_create_album( + album_title, + artist=artist, + mbid=album_mb_id, + ) track = None if not track_mb_id and album: @@ -128,6 +130,13 @@ def get_or_create_track(post_data: dict, post_keys: dict) -> Track: except TypeError: pass + if not track_title and not track_mb_id: + logger.info( + "Cannot find track without either title or MB ID", + extra={"post_data": post_data}, + ) + return + if track_mb_id: track = Track.objects.filter(musicbrainz_id=track_mb_id).first() diff --git a/vrobbler/apps/scrobbles/tsv.py b/vrobbler/apps/scrobbles/tsv.py index 218bf68..1338511 100644 --- a/vrobbler/apps/scrobbles/tsv.py +++ b/vrobbler/apps/scrobbles/tsv.py @@ -67,6 +67,10 @@ def process_audioscrobbler_tsv_file(file_path, user_id, user_tz=None): "RUN_TIME": "run_time_seconds", }, ) + if not track: + logger.info(f"Skipping track {track} because not found") + continue + # TODO Set all this up as constants if row[AsTsvColumn["COMPLETE"].value] == "S": logger.info(f"Skipping track {track} because not finished")