Skip to content

Commit

Permalink
lastgenre: Fix track-level handling and streamline logging (#5582)
Browse files Browse the repository at this point in the history
- Fix `lastgenre -A` in combination with config option `source: track`
(_Tracks inherited the album's genre even when this option was set_)
  - Now, When an album-level genre is set already, single tracks don't
fall back to the album's genre and request their own last.fm genre.

- Fix log-level and message wording being slightly different for
`source:` track, album, artist genre
  - Now log messages follow the same wording, level and structure
throughout.
  • Loading branch information
JOJ0 authored Jan 9, 2025
2 parents 801bac5 + 55c0f7a commit bcc91ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
34 changes: 24 additions & 10 deletions beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,14 @@ def lastgenre_func(lib, opts, args):
for album in lib.albums(ui.decargs(args)):
album.genre, src = self._get_genre(album)
self._log.info(
"genre for album {0} ({1}): {0.genre}", album, src
'genre for album "{0.album}" ({1}): {0.genre}',
album,
src,
)
album.store()
if "track" in self.sources:
album.store(inherit=False)
else:
album.store()

for item in album.items():
# If we're using track-level sources, also look up each
Expand All @@ -420,7 +425,7 @@ def lastgenre_func(lib, opts, args):
item.genre, src = self._get_genre(item)
item.store()
self._log.info(
"genre for track {0} ({1}): {0.genre}",
'genre for track "{0.title}" ({1}): {0.genre}',
item,
src,
)
Expand All @@ -432,10 +437,10 @@ def lastgenre_func(lib, opts, args):
# an album
for item in lib.items(ui.decargs(args)):
item.genre, src = self._get_genre(item)
self._log.debug(
"added last.fm item genre ({0}): {1}", src, item.genre
)
item.store()
self._log.info(
"genre for track {0.title} ({1}): {0.genre}", item, src
)

lastgenre_cmd.func = lastgenre_func
return [lastgenre_cmd]
Expand All @@ -446,23 +451,32 @@ def imported(self, session, task):
album = task.album
album.genre, src = self._get_genre(album)
self._log.debug(
"added last.fm album genre ({0}): {1}", src, album.genre
'genre for album "{0.album}" ({1}): {0.genre}', album, src
)
album.store()

# If we're using track-level sources, store the album genre only,
# then also look up individual track genres.
if "track" in self.sources:
album.store(inherit=False)
for item in album.items():
item.genre, src = self._get_genre(item)
self._log.debug(
"added last.fm item genre ({0}): {1}", src, item.genre
'genre for track "{0.title}" ({1}): {0.genre}',
item,
src,
)
item.store()
# Store the album genre and inherit to tracks.
else:
album.store()

else:
item = task.item
item.genre, src = self._get_genre(item)
self._log.debug(
"added last.fm item genre ({0}): {1}", src, item.genre
'genre for track "{0.title}" ({1}): {0.genre}',
item,
src,
)
item.store()

Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Bug fixes:
* :ref:`query-sort`: Fix a bug that would raise an exception when sorting on
a non-string field that is not populated in all items.
:bug:`5512`
* :doc:`plugins/lastgenre`: Fix track-level genre handling. Now when an album-level
genre is set already, single tracks don't fall back to the album's genre and
request their own last.fm genre. Also log messages regarding what's been
tagged are now more polished.
:bug:`5582`

For packagers:

Expand Down

0 comments on commit bcc91ff

Please sign in to comment.