Browse Source

[tsv] Try fixing our lookup when titla and MB id are none

Colin Powell 8 months ago
parent
commit
68a6d58339
2 changed files with 18 additions and 5 deletions
  1. 14 5
      vrobbler/apps/music/utils.py
  2. 4 0
      vrobbler/apps/scrobbles/tsv.py

+ 14 - 5
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()
 

+ 4 - 0
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")