Fix importing albums
This commit is contained in:
@ -43,24 +43,14 @@ def get_or_create_artist(name: str, mbid: str = None) -> Artist:
|
|||||||
|
|
||||||
def get_or_create_album(name: str, artist: Artist, mbid: str = None) -> Album:
|
def get_or_create_album(name: str, artist: Artist, mbid: str = None) -> Album:
|
||||||
album = None
|
album = None
|
||||||
album_created = False
|
album_dict = lookup_album_dict_from_mb(name, artist_name=artist.name)
|
||||||
albums = Album.objects.filter(name__iexact=name)
|
mbid = mbid or album_dict['mb_id']
|
||||||
if albums.count() == 1:
|
|
||||||
album = albums.first()
|
|
||||||
else:
|
|
||||||
for potential_album in albums:
|
|
||||||
if artist in album.artist_set.all():
|
|
||||||
album = potential_album
|
|
||||||
if not album:
|
|
||||||
album_created = True
|
|
||||||
album = Album.objects.create(name=name, musicbrainz_id=mbid)
|
|
||||||
album.save()
|
|
||||||
album.artists.add(artist)
|
|
||||||
|
|
||||||
if album_created or not mbid:
|
logger.debug(f'Looking up album {name} and mbid: {mbid}')
|
||||||
album_dict = lookup_album_dict_from_mb(
|
|
||||||
album.name, artist_name=artist.name
|
album = Album.objects.filter(musicbrainz_id=mbid).first()
|
||||||
)
|
if not album:
|
||||||
|
album = Album.objects.create(name=name, musicbrainz_id=mbid)
|
||||||
album.year = album_dict["year"]
|
album.year = album_dict["year"]
|
||||||
album.musicbrainz_id = album_dict["mb_id"]
|
album.musicbrainz_id = album_dict["mb_id"]
|
||||||
album.musicbrainz_releasegroup_id = album_dict["mb_group_id"]
|
album.musicbrainz_releasegroup_id = album_dict["mb_group_id"]
|
||||||
@ -75,6 +65,7 @@ def get_or_create_album(name: str, artist: Artist, mbid: str = None) -> Album:
|
|||||||
)
|
)
|
||||||
album.artists.add(artist)
|
album.artists.add(artist)
|
||||||
album.fetch_artwork()
|
album.fetch_artwork()
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user