From 1ee8fc589ad609b25a0be082112b67e42c3afaba Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Mon, 27 Mar 2023 20:19:03 -0400 Subject: [PATCH] Actually fix the VA bug --- todos.org | 6 +++++- vrobbler/apps/music/models.py | 12 +++++------- vrobbler/apps/music/utils.py | 34 +++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/todos.org b/todos.org index ec004ca..c931121 100644 --- a/todos.org +++ b/todos.org @@ -16,7 +16,11 @@ other scrobblers which may have different definitions of when a scrobble finishes or started. ** TODO Fix bug in Jellyfin scrobbles that spam more scrobbles after completion :scrobbling:videos:bug: ** TODO Fix bug in podcast scrobbling where a second scrobble is created after completion :scrobbling:podcasts:bug: -** TODO Fix bug with Various Artist albums being labeled with first artist as album artist :scrobbling:bug:music: +** DONE Fix bug with Various Artist albums being labeled with first artist as album artist :scrobbling:bug:music: +CLOSED: [2023-03-27 Mon 20:18] +:LOGBOOK: +CLOCK: [2023-03-26 Sun 22:01]--[2023-03-27 Mon 01:07] => 3:06 +:END: ** DONE Fix bug with weekly aggregator being blank on Sundays :aggregators:music:bug: CLOSED: [2023-03-26 Sun 13:52] ** DONE Fix KoReader scrobbling to use pages rather than time of last read :scrobbling:books:improvement: diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index c05af46..d907fd7 100644 --- a/vrobbler/apps/music/models.py +++ b/vrobbler/apps/music/models.py @@ -180,13 +180,11 @@ class Album(TimeStampedModel): from music.utils import get_or_create_various_artists multiple_artists = self.artists.count() > 1 - if not self.album_artist: - if multiple_artists: - self.album_artist = get_or_create_various_artists() - else: - self.album_artist = self.artists.first() - - self.save(update_fields=["album_artist"]) + if multiple_artists: + self.album_artist = get_or_create_various_artists() + else: + self.album_artist = self.artists.first() + self.save(update_fields=["album_artist"]) def scrape_allmusic(self, force=False) -> None: if not self.allmusic_id or force: diff --git a/vrobbler/apps/music/utils.py b/vrobbler/apps/music/utils.py index 86e929a..c10cd8a 100644 --- a/vrobbler/apps/music/utils.py +++ b/vrobbler/apps/music/utils.py @@ -55,22 +55,26 @@ def get_or_create_album( if not album and name: mbid = mbid or album_dict["mb_id"] - album = Album.objects.create(name=name, musicbrainz_id=mbid) - album.year = album_dict["year"] - album.musicbrainz_releasegroup_id = album_dict["mb_group_id"] - album.musicbrainz_albumartist_id = artist.musicbrainz_id - album.save( - update_fields=[ - "musicbrainz_id", - "year", - "musicbrainz_releasegroup_id", - "musicbrainz_albumartist_id", - ] + album, album_created = Album.objects.get_or_create( + name=name, musicbrainz_id=mbid ) - album.artists.add(artist) - album.fetch_artwork() - album.fix_album_artist() - album.scrape_allmusic() + if album_created: + album.year = album_dict["year"] + album.musicbrainz_releasegroup_id = album_dict["mb_group_id"] + album.musicbrainz_albumartist_id = artist.musicbrainz_id + album.save( + update_fields=[ + "musicbrainz_id", + "year", + "musicbrainz_releasegroup_id", + "musicbrainz_albumartist_id", + ] + ) + album.artists.add(artist) + album.fetch_artwork() + album.scrape_allmusic() + album.fix_album_artist() + if not album: logger.warn(f"No album found for {name} and {mbid}")