Skip to content

Commit

Permalink
feat: allow to auto-detect genre on import
Browse files Browse the repository at this point in the history
Introducing the `auto` configuration option, corresponding to the lastgenre plugin's option with the same name.
  • Loading branch information
mgoltzsche committed May 28, 2024
1 parent 2fe6703 commit 1056526
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 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.14.0
FROM ghcr.io/mgoltzsche/beets-plugins:0.15.0

# Install bats
USER root:root
Expand Down
4 changes: 3 additions & 1 deletion beetsplug/autogenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def __init__(self):
self._separator = self._lastgenre_conf.get('separator') or ', '
self._remix_regex = re.compile(r'.+[^\w](remix|bootleg|remake)', re.IGNORECASE)
self._genre_tree = None
# TODO: add auto-detect support
# TODO: fix auto support - fix genres field mapping, see https://github.com/beetbox/mediafile/blob/master/mediafile.py#L1814
if self.config['auto'].get(bool):
self.import_stages = [self.imported]

def imported(self, session, task):
"""Event hook called when an import task finishes."""
Expand Down
1 change: 1 addition & 0 deletions beetsplug/autogenre/config_default.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
auto: false
pretend: false
all: false
force: false
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ assertGenre() {
)
}

tempConfigWithAutoEnabled() {
TMP_CONF=/tmp/beets-autogenre-test-config.yaml
cp -f /etc/beets/default-config.yaml $TMP_CONF
printf '\nautogenre:\n auto: true\n' >> $TMP_CONF
}

@test 'auto-detect song genre on import' {
# TODO: fix failing logic. fails with "sqlite3.OperationalError: no such column: genres"
# Tuba Skinny - Jubilee Stomp
tempConfigWithAutoEnabled
beet -c $TMP_CONF ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=jft3BVoxqjo
QUERY='Jubilee Stomp'
assertGenre "$QUERY" 'lastfm | Jazz | Jazz'
}

@test 'auto-detect album genre on import' {
# TODO: fix failing logic. fails with "sqlite3.OperationalError: no such column: genres"
# Miles Davis - Autumn Leaves
tempConfigWithAutoEnabled
beet -c $TMP_CONF ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=APKdKHIiNuE
QUERY='Miles Davis Autumn Leaves'
assertGenre "$QUERY" 'lastfm | Jazz | Jazz'
[ "`beet ls -a "$QUERY" -f '$genre'`" = 'Ragga Drum And Bass' ] || (echo 'Should set album genre!'; false)
}

@test 'get genre from last.fm' {
# Amadou & Mariam - Sénégal Fast Food
beet ytimport -q --quiet-fallback=asis https://www.youtube.com/watch?v=J43T8rEOg-I
Expand Down

0 comments on commit 1056526

Please sign in to comment.