Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lastgenre: Fix track-level handling and streamline logging #5582

Merged
merged 6 commits into from
Jan 9, 2025
Merged
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
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
Loading