Fix lastfm importing
This commit is contained in:
@ -11,15 +11,21 @@ logger = logging.getLogger(__name__)
|
||||
from music.models import Artist, Album, Track
|
||||
|
||||
|
||||
def get_or_create_artist(name: str) -> Artist:
|
||||
artist, artist_created = Artist.objects.get_or_create(name=name)
|
||||
if artist_created:
|
||||
def get_or_create_artist(name: str, mbid: str = None) -> Artist:
|
||||
if mbid:
|
||||
artist, artist_created = Artist.objects.get_or_create(
|
||||
name=name, musicbrainz_id=mbid
|
||||
)
|
||||
else:
|
||||
artist, artist_created = Artist.objects.get_or_create(name=name)
|
||||
|
||||
if not mbid:
|
||||
artist.musicbrainz_id = lookup_artist_id_from_mb(artist.name)
|
||||
artist.save(update_fields=["musicbrainz_id"])
|
||||
return artist
|
||||
|
||||
|
||||
def get_or_create_album(name: str, artist: Artist) -> Album:
|
||||
def get_or_create_album(name: str, artist: Artist, mbid: str = None) -> Album:
|
||||
album = None
|
||||
album_created = False
|
||||
albums = Album.objects.filter(name__iexact=name)
|
||||
@ -31,11 +37,11 @@ def get_or_create_album(name: str, artist: Artist) -> Album:
|
||||
album = potential_album
|
||||
if not album:
|
||||
album_created = True
|
||||
album = Album.objects.create(name=name)
|
||||
album = Album.objects.create(name=name, musicbrainz_id=mbid)
|
||||
album.save()
|
||||
album.artists.add(artist)
|
||||
|
||||
if album_created:
|
||||
if album_created or not mbid:
|
||||
album_dict = lookup_album_dict_from_mb(
|
||||
album.name, artist_name=artist.name
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user