Skip to content

Commit e623168

Browse files
committed
fix: don't fail when essentia did not extract data
1 parent 5e0b566 commit e623168

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/mgoltzsche/beets-plugins:0.15.0
1+
FROM ghcr.io/mgoltzsche/beets-plugins:0.18.1
22

33
# Install bats
44
USER root:root

beetsplug/autogenre/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ def _item_genres(self, item, all, force, force_genre):
203203
if not genre:
204204
genre = item.get('genre')
205205
source = item.get('genre_source')
206-
orig_genre = genre
207-
orig_source = source
208206
if _filter_item(item, all, force):
209207
if force_genre is not None:
210208
source = force_genre and 'user' or None
@@ -273,9 +271,13 @@ def _fix_remix_genre(self, item, genre):
273271
return genre, False
274272

275273
def _essentia_genre(self, item):
276-
if not item.get('bpm'): # run essentia analysis if result not known yet
274+
if not item.get('bpm') or not item.get('genre_rosamerica'):
275+
# Run essentia analysis if result not known yet.
277276
self._log.debug('Analyzing item using essentia: {}', item)
278277
self._xtractor._run_analysis(item)
278+
if 'genre_rosamerica' not in item:
279+
# Essentia analysis may not provide data in some cases.
280+
return None
279281
# Use Essentia's mapped genre_rosamerica value
280282
genre_rosamerica = item.genre_rosamerica
281283
genre_rosamerica_probability = float(item.genre_rosamerica_probability)

tests/e2e/tests.bats

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,19 @@ tempConfigWithAutoEnabled() {
9191
# EttoreTechnoChannel - Hector Couto- Amanece
9292
beet ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=8CI2GjcCkuM
9393
QUERY='title:Hector Couto- Amanece'
94-
beet autogenre -f $QUERY
94+
beet autogenre -f --no-lastgenre $QUERY
9595
assertGenre "$QUERY" 'essentia | Electronic | Electronic, Hip Hop, House'
9696
}
9797

98+
@test "don't fail when essentia analysis did not provide data" {
99+
# Amadou & Mariam feat. K'naan - Africa
100+
beet ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=WJ-rI2i9VGE
101+
QUERY='artist:Amadou title:Africa'
102+
beet autogenre -f --no-lastgenre $QUERY
103+
assertGenre "$QUERY" ''
104+
# TODO: implement fallback to using the most common genre of other tracks of the same artist
105+
}
106+
98107

99108
@test 'specify genre manually' {
100109
ALBUM='Reggae Jungle Drum and Bass Mix #9 New 2022'

0 commit comments

Comments
 (0)