diff --git a/vrobbler/apps/music/lastfm.py b/vrobbler/apps/music/lastfm.py index 900ce57..ec20977 100644 --- a/vrobbler/apps/music/lastfm.py +++ b/vrobbler/apps/music/lastfm.py @@ -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}") diff --git a/vrobbler/apps/music/musicbrainz.py b/vrobbler/apps/music/musicbrainz.py index 533f84c..e50ed39 100644 --- a/vrobbler/apps/music/musicbrainz.py +++ b/vrobbler/apps/music/musicbrainz.py @@ -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", diff --git a/vrobbler/apps/music/utils.py b/vrobbler/apps/music/utils.py index 118a0e7..377d2da 100644 --- a/vrobbler/apps/music/utils.py +++ b/vrobbler/apps/music/utils.py @@ -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,