Skip to content

Commit

Permalink
fix: use top-level genre if none matched whitelist
Browse files Browse the repository at this point in the history
Also, use latest beets container and enable previously disabled e2e tests
  • Loading branch information
mgoltzsche committed Jan 27, 2024
1 parent c4d4d42 commit d4af4eb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 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.12.0
FROM ghcr.io/mgoltzsche/beets-plugins:0.13.1

# Install bats
USER root:root
Expand Down
9 changes: 5 additions & 4 deletions beetsplug/autogenre/genretree.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def is_genre(self, genre, parent):
return p and self.is_genre(p, parent) or False

def _canonicalize(self, genre):
if genre.lower() in self._whitelist:
return genre.lower()
parent = self._parentmap.get(genre.lower())
return parent and self._canonicalize(parent) or None
genre = genre.lower()
if genre in self._whitelist:
return genre
parent = self._parentmap.get(genre)
return parent and self._canonicalize(parent) or genre

def _tree2parentmap(tree, r={}, parent=None):
if isinstance(tree, str):
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/example-urls.txt

This file was deleted.

4 changes: 0 additions & 4 deletions tests/e2e/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ assertGenre() {
@test 'derive genre from album name' {
# Reggae Jungle Drum and Bass Mix #9 New 2022
beet ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=ZisHyhD0l_4
# TODO: remove skip after beets-container 0.12.1 upgrade
skip 'requires beets-container 0.12.1'
QUERY='album:Reggae Jungle Drum and Bass Mix #9 New 2022 Rudy, a message to you'
beet autogenre -fa $QUERY
assertGenre "$QUERY" 'title | Ragga Drum And Bass | Ragga Drum And Bass, Drum And Bass, Electronic'
Expand All @@ -63,8 +61,6 @@ assertGenre() {
}

@test 'reset manually specified genre' {
# TODO: remove skip after beets-container 0.12.1 upgrade
skip 'requires beets-container 0.12.1'
QUERY='album:Reggae Jungle Drum and Bass Mix #9 New 2022 Rudy, a message to you'
beet autogenre --genre= $QUERY
assertGenre "$QUERY" 'title | Ragga Drum And Bass | Ragga Drum And Bass, Drum And Bass, Electronic'
Expand Down
17 changes: 14 additions & 3 deletions tests/test_genretree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ def test_match(self):
'fancy genre 1',
{
'fancy genre 2': [
'sub genre',
'sub genre 1',
'genre alias',
{
'sub genre 2': [
'sub sub genre',
'sub sub genre 1',
'sub sub genre 2',
'sub sub genre 3',
Expand All @@ -26,9 +28,18 @@ def test_match(self):
],
},
},
{
'none-whitelisted genre': {
'none-whitelisted sub genre': [
'none-whitelisted sub sub genre',
],
},
},
]
genre_whitelist = [
'fancy genre 1',
'sub genre',
'sub sub genre',
'fancy genre 2',
'sub genre 1',
'sub sub genre 2',
Expand Down Expand Up @@ -95,9 +106,9 @@ def test_match(self):
'expected': 'fancy genre 1',
},
{
'name': 'match genre without whitelisted parent',
'input': 'sub sub genre 4 mix',
'expected': 'fancy genre 2',
'name': 'return top-level parent genre when no whitelisted matched',
'input': 'none-whitelisted sub sub genre mix',
'expected': 'none-whitelisted genre',
},
{
'name': 'do not match genre without brackets and remix suffix',
Expand Down

0 comments on commit d4af4eb

Please sign in to comment.