Fix it so lastfm imports dont barf

This commit is contained in:
2023-04-06 15:39:13 -04:00
parent 2896225826
commit 9baf1069b6
3 changed files with 26 additions and 7 deletions

View File

@ -107,6 +107,7 @@ class LastFM:
# TOOD spin this out into a celery task over certain threshold of found scrobbles?
for scrobble in found_scrobbles:
logger.debug(f"Processing {scrobble}")
run_time = None
mbid = None
artist = None
@ -121,6 +122,10 @@ class LastFM:
logger.warn(
"LastFM barfed trying to get the track for {scrobble.track}"
)
except pylast.NetworkError as e:
logger.warn(
"LastFM barfed trying to get the track for {scrobble.track}"
)
if not artist:
logger.warn(f"Silly LastFM, no artist found for {scrobble}")

View File

@ -53,10 +53,18 @@ def lookup_album_from_mb(musicbrainz_id: str) -> dict:
def lookup_album_dict_from_mb(release_name: str, artist_name: str) -> dict:
musicbrainzngs.set_useragent("vrobbler", "0.3.0")
top_result = musicbrainzngs.search_releases(
release_name, artist=artist_name
)["release-list"][0]
score = int(top_result.get("ext:score"))
top_result = {}
try:
top_result = musicbrainzngs.search_releases(
release_name, artist=artist_name
)["release-list"][0]
except IndexError:
logger.info(
f"No release found on MB for {artist_name} and {release_name}"
)
score = int(top_result.get("ext:score", 0))
if score < 85:
logger.debug(
"Album lookup score below 85 threshold",

View File

@ -43,7 +43,13 @@ def get_or_create_album(
album = None
album_dict = lookup_album_dict_from_mb(name, artist_name=artist.name)
name = name or album_dict["title"]
name = name or album_dict.get("title", None)
if not name:
logger.debug(
f"Cannot get or create album by {artist} with no name ({name})"
)
return
album = Album.objects.filter(artists__in=[artist], name=name).first()
if not album and name:
@ -78,12 +84,12 @@ def get_or_create_album(
def get_or_create_track(
title: str,
artist: Artist,
album: Album,
album: Album = None,
mbid: str = None,
run_time_seconds=None,
) -> Track:
track = None
if not mbid:
if not mbid and album:
mbid = lookup_track_from_mb(
title,
artist.musicbrainz_id,