Skip to content

Commit 201677a

Browse files
authored
lastgenre: Plugin tuning log (-vvv) (#6007)
2 parents 043581e + 4b1e505 commit 201677a

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

beetsplug/lastgenre/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def __init__(self):
106106
"separator": ", ",
107107
"prefer_specific": False,
108108
"title_case": True,
109-
"extended_debug": False,
110109
"pretend": False,
111110
}
112111
)
@@ -162,6 +161,11 @@ def _load_c14n_tree(self) -> tuple[list[list[str]], bool]:
162161
flatten_tree(genres_tree, [], c14n_branches)
163162
return c14n_branches, canonicalize
164163

164+
def _tunelog(self, msg, *args, **kwargs):
165+
"""Log tuning messages at DEBUG level when verbosity level is high enough."""
166+
if config["verbose"].as_number() >= 3:
167+
self._log.debug(msg, *args, **kwargs)
168+
165169
@property
166170
def sources(self) -> tuple[str, ...]:
167171
"""A tuple of allowed genre sources. May contain 'track',
@@ -293,8 +297,7 @@ def _last_lookup(self, entity, method, *args):
293297
self._genre_cache[key] = self.fetch_genre(method(*args))
294298

295299
genre = self._genre_cache[key]
296-
if self.config["extended_debug"]:
297-
self._log.debug("last.fm (unfiltered) {} tags: {}", entity, genre)
300+
self._tunelog("last.fm (unfiltered) {} tags: {}", entity, genre)
298301
return genre
299302

300303
def fetch_album_genre(self, obj):
@@ -554,13 +557,6 @@ def commands(self):
554557
dest="album",
555558
help="match albums instead of items (default)",
556559
)
557-
lastgenre_cmd.parser.add_option(
558-
"-d",
559-
"--debug",
560-
action="store_true",
561-
dest="extended_debug",
562-
help="extended last.fm debug logging",
563-
)
564560
lastgenre_cmd.parser.set_defaults(album=True)
565561

566562
def lastgenre_func(lib, opts, args):

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ New features:
1414
album artist are the same in ftintitle.
1515
- :doc:`plugins/play`: Added `$playlist` marker to precisely edit the playlist
1616
filepath into the command calling the player program.
17+
- :doc:`plugins/lastgenre`: For tuning plugin settings ``-vvv`` can be passed
18+
to receive extra verbose logging around last.fm results and how they are
19+
resolved. The ``extended_debug`` config setting and ``--debug`` option
20+
have been removed.
1721

1822
Bug fixes:
1923

docs/plugins/lastgenre.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ file. The available options are:
197197
internal whitelist, or ``no`` to consider all genres valid. Default: ``yes``.
198198
- **title_case**: Convert the new tags to TitleCase before saving. Default:
199199
``yes``.
200-
- **extended_debug**: Add additional debug logging messages that show what
201-
last.fm tags were fetched for tracks, albums and artists. This is done before
202-
any canonicalization and whitelist filtering is applied. It's useful for
203-
tuning the plugin's settings and understanding how it works, but it can be
204-
quite verbose. Default: ``no``.
205200

206201
Running Manually
207202
----------------
@@ -219,3 +214,13 @@ or store any changes.
219214

220215
To disable automatic genre fetching on import, set the ``auto`` config option to
221216
false.
217+
218+
Tuning Logs
219+
-----------
220+
221+
To enable tuning logs, run ``beet -vvv lastgenre ...`` or ``beet -vvv import
222+
...``. This enables additional messages at the ``DEBUG`` log level, showing for
223+
example what data was received from last.fm at each stage of genre fetching
224+
(artist, album, and track levels) before any canonicalization or whitelist
225+
filtering is applied. Tuning logs are useful for adjusting the plugin’s settings
226+
and understanding its behavior, though they can be quite verbose.

0 commit comments

Comments
 (0)