Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from collections import defaultdict
from functools import cached_property, singledispatchmethod
from pathlib import Path
from typing import TYPE_CHECKING, Any, Protocol
from typing import TYPE_CHECKING, Any, Protocol, Unpack

import confuse
import yaml

from beets import config, library, plugins, ui
from beets import config, events, library, plugins, ui
from beets.library import Album, Item
from beets.util import plurality, unique_list
from beetsplug.lastgenre.utils import is_ignored, normalize_genre
Expand Down Expand Up @@ -138,6 +138,7 @@ def setup(self) -> None:
"""Setup plugin from config options"""
if self.config["auto"]:
self.import_stages = [self.imported]
self.register_listener("item_imported", self.item_imported)

self.whitelist: Whitelist = self._load_whitelist()
self.c14n_branches: CanonTree
Expand Down Expand Up @@ -826,4 +827,10 @@ def lastgenre_func(
return [lastgenre_cmd]

def imported(self, _: ImportSession, task: ImportTask) -> None:
self._process(task.album if task.is_album else task.item, write=False) # type: ignore[attr-defined]
if task.is_album:
Comment thread
JOJ0 marked this conversation as resolved.
Resolved
self._process(task.album, write=False)

def item_imported(
self, **kwargs: Unpack[events.ItemImportedEventArgs]
) -> None:
self._process(kwargs["item"], write=False)
Comment thread
JOJ0 marked this conversation as resolved.
Resolved
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ Bug fixes
instead of silently falling back to plain lyrics. :bug:`7070`
- :doc:`plugins/info`: Fix a :class:`TypeError` when printing list-valued tag
fields with non-string elements, such as ``synced_lyrics``. :bug:`7183`
- :doc:`plugins/lastgenre`: Fix lastgenre not triggering on singleton imports in
auto mode. :bug:`7190`

For plugin developers
~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 13 additions & 0 deletions test/plugins/test_lastgenre.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ def unexpected_store(*_, **__):
assert album.genres == ["Original Genre"]
assert album.items()[0].genres == ["Original Genre"]

def test_item_imported_processes_singleton(self):
item = self.create_item(
album="Singleton Album",
albumartist="Singleton Artist",
artist="Singleton Artist",
title="Singleton Track",
)

with patch.object(self.plugin, "_process") as process:
self.plugin.item_imported(lib=self.lib, item=item)

process.assert_called_once_with(item, write=False)

def _add_album_for_import(self) -> Album:
item = self.create_item(
album="Import Album",
Expand Down
Loading