Fix it so lastfm imports dont barf
This commit is contained in:
@ -107,6 +107,7 @@ class LastFM:
|
|||||||
# TOOD spin this out into a celery task over certain threshold of found scrobbles?
|
# TOOD spin this out into a celery task over certain threshold of found scrobbles?
|
||||||
|
|
||||||
for scrobble in found_scrobbles:
|
for scrobble in found_scrobbles:
|
||||||
|
logger.debug(f"Processing {scrobble}")
|
||||||
run_time = None
|
run_time = None
|
||||||
mbid = None
|
mbid = None
|
||||||
artist = None
|
artist = None
|
||||||
@ -121,6 +122,10 @@ class LastFM:
|
|||||||
logger.warn(
|
logger.warn(
|
||||||
"LastFM barfed trying to get the track for {scrobble.track}"
|
"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:
|
if not artist:
|
||||||
logger.warn(f"Silly LastFM, no artist found for {scrobble}")
|
logger.warn(f"Silly LastFM, no artist found for {scrobble}")
|
||||||
|
|||||||
@ -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:
|
def lookup_album_dict_from_mb(release_name: str, artist_name: str) -> dict:
|
||||||
musicbrainzngs.set_useragent("vrobbler", "0.3.0")
|
musicbrainzngs.set_useragent("vrobbler", "0.3.0")
|
||||||
|
|
||||||
top_result = musicbrainzngs.search_releases(
|
top_result = {}
|
||||||
release_name, artist=artist_name
|
|
||||||
)["release-list"][0]
|
try:
|
||||||
score = int(top_result.get("ext:score"))
|
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:
|
if score < 85:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Album lookup score below 85 threshold",
|
"Album lookup score below 85 threshold",
|
||||||
|
|||||||
@ -43,7 +43,13 @@ def get_or_create_album(
|
|||||||
album = None
|
album = None
|
||||||
album_dict = lookup_album_dict_from_mb(name, artist_name=artist.name)
|
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()
|
album = Album.objects.filter(artists__in=[artist], name=name).first()
|
||||||
|
|
||||||
if not album and name:
|
if not album and name:
|
||||||
@ -78,12 +84,12 @@ def get_or_create_album(
|
|||||||
def get_or_create_track(
|
def get_or_create_track(
|
||||||
title: str,
|
title: str,
|
||||||
artist: Artist,
|
artist: Artist,
|
||||||
album: Album,
|
album: Album = None,
|
||||||
mbid: str = None,
|
mbid: str = None,
|
||||||
run_time_seconds=None,
|
run_time_seconds=None,
|
||||||
) -> Track:
|
) -> Track:
|
||||||
track = None
|
track = None
|
||||||
if not mbid:
|
if not mbid and album:
|
||||||
mbid = lookup_track_from_mb(
|
mbid = lookup_track_from_mb(
|
||||||
title,
|
title,
|
||||||
artist.musicbrainz_id,
|
artist.musicbrainz_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user