diff --git a/matcher/matcher/matcher/album.py b/matcher/matcher/matcher/album.py index 6e0fecd6..2dbd31db 100644 --- a/matcher/matcher/matcher/album.py +++ b/matcher/matcher/matcher/album.py @@ -65,6 +65,7 @@ def match_and_post_album(album_id: int, album_name: str): def match_album( album_id: int, album_name: str, artist_name: str | None, type: AlbumType ) -> tuple[ExternalMetadataDto | None, date | None, AlbumType | None, List[str]]: + need_genres = Context.get().settings.push_genres context = Context.get() release_date: date | None = None genres: List[str] = [] @@ -110,7 +111,11 @@ def match_album( or (not release_date and provider.has_feature(GetAlbumReleaseDateFeature)) or (not rating and provider.has_feature(GetAlbumRatingFeature)) or (not album_type and provider.has_feature(GetAlbumTypeFeature)) - or (len(genres) == 0 and provider.has_feature(GetAlbumGenresFeature)) + or ( + need_genres + and len(genres) == 0 + and provider.has_feature(GetAlbumGenresFeature) + ) ) if not is_useful: continue @@ -128,9 +133,11 @@ def match_album( description = provider.get_album_description(album) if not release_date: release_date = provider.get_album_release_date(album) - genres = genres + [ - g for g in provider.get_album_genres(album) or [] if g not in genres - ] + genres = genres + ( + [g for g in provider.get_album_genres(album) or [] if g not in genres] + if need_genres + else [] + ) if description and release_date and rating and genres: break return ( diff --git a/matcher/matcher/matcher/song.py b/matcher/matcher/matcher/song.py index e2999d8a..e39c03e5 100644 --- a/matcher/matcher/matcher/song.py +++ b/matcher/matcher/matcher/song.py @@ -117,9 +117,11 @@ def match_song( description = provider.get_song_description(song) if not lyrics: lyrics = provider.get_song_lyrics(song) - genres = genres + [ - g for g in provider.get_song_genres(song) or [] if g not in genres - ] + genres = genres + ( + [g for g in provider.get_song_genres(song) or [] if g not in genres] + if need_genres + else [] + ) if description and lyrics and genres: break return ( diff --git a/matcher/tests/matcher/album.py b/matcher/tests/matcher/album.py index 15def49d..f4f037dd 100644 --- a/matcher/tests/matcher/album.py +++ b/matcher/tests/matcher/album.py @@ -3,6 +3,7 @@ from matcher.matcher.album import match_album from matcher.providers.domain import AlbumType from tests.matcher.common import MatcherTestUtils +from matcher.context import Context class TestMatchAlbum(unittest.TestCase): @@ -120,7 +121,9 @@ def test_get_album2(self): self.assertEqual(allmusic.url, "https://www.allmusic.com/album/mw0004210541") def test_get_album_no_rating(self): - [matches, date, type, genres] = match_album(1, "AĆ©romusical", "Superbus", AlbumType.STUDIO) + [matches, date, type, genres] = match_album( + 1, "AĆ©romusical", "Superbus", AlbumType.STUDIO + ) # Rating self.assertIsNone(matches.rating) # Release date @@ -149,3 +152,15 @@ def test_get_album_no_rating(self): ### Allmusic [allmusic] = [p for p in matches.sources if "allmusic" in p.url] self.assertEqual(allmusic.url, "https://www.allmusic.com/album/mw0000770491") + + def test_get_album_ignore_genres(self): + # Setup + context = Context.get() + context.settings.push_genres = False + [matches, date, type, genres] = match_album( + 1, "Confessions on a Dancefloor", "Madonna", AlbumType.STUDIO + ) + # Teardown + context.settings.push_genres = True + # Genres + self.assertEqual(len(genres), 0)