Skip to content

Commit

Permalink
fix: don't fail when essentia did not extract data
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoltzsche committed Aug 25, 2024
1 parent 5e0b566 commit e623168
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/mgoltzsche/beets-plugins:0.15.0
FROM ghcr.io/mgoltzsche/beets-plugins:0.18.1

# Install bats
USER root:root
Expand Down
8 changes: 5 additions & 3 deletions beetsplug/autogenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ def _item_genres(self, item, all, force, force_genre):
if not genre:
genre = item.get('genre')
source = item.get('genre_source')
orig_genre = genre
orig_source = source
if _filter_item(item, all, force):
if force_genre is not None:
source = force_genre and 'user' or None
Expand Down Expand Up @@ -273,9 +271,13 @@ def _fix_remix_genre(self, item, genre):
return genre, False

def _essentia_genre(self, item):
if not item.get('bpm'): # run essentia analysis if result not known yet
if not item.get('bpm') or not item.get('genre_rosamerica'):
# Run essentia analysis if result not known yet.
self._log.debug('Analyzing item using essentia: {}', item)
self._xtractor._run_analysis(item)
if 'genre_rosamerica' not in item:
# Essentia analysis may not provide data in some cases.
return None
# Use Essentia's mapped genre_rosamerica value
genre_rosamerica = item.genre_rosamerica
genre_rosamerica_probability = float(item.genre_rosamerica_probability)
Expand Down
11 changes: 10 additions & 1 deletion tests/e2e/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ tempConfigWithAutoEnabled() {
# EttoreTechnoChannel - Hector Couto- Amanece
beet ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=8CI2GjcCkuM
QUERY='title:Hector Couto- Amanece'
beet autogenre -f $QUERY
beet autogenre -f --no-lastgenre $QUERY
assertGenre "$QUERY" 'essentia | Electronic | Electronic, Hip Hop, House'
}

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


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

0 comments on commit e623168

Please sign in to comment.