Commit graph

264 commits

Author SHA1 Message Date
Šarūnas Nejus
d486885af3
pyupgrade Python 3.10 2025-11-08 12:09:52 +00:00
J0J0 Todos
a8204f8cde lastgenre: -vvv tuning log helper, remove -d
Replace extended_debug config and CLI option with -vvv and add a helper
function.
2025-10-23 19:02:03 +02:00
Šarūnas Nejus
88011a7c65
Show genre change using show_model_changes 2025-10-15 11:14:26 +01:00
Šarūnas Nejus
0aac7315c3
lastgenre: refactor genre processing with singledispatch
Replace the log_and_pretend decorator with a more robust implementation
using singledispatchmethod. This simplifies the genre application logic
by consolidating logging and processing into dedicated methods.

Key changes:
- Remove log_and_pretend decorator in favor of explicit dispatch
- Add _fetch_and_log_genre method to centralize genre fetching and logging
- Log user-configured full object representation instead of specific
attributes
- Introduce _process singledispatchmethod with type-specific handlers
- Use LibModel type hint for broader compatibility
- Simplify command handler by removing duplicate album/item logic
- Replace manual genre application with try_sync for consistency
2025-10-15 09:55:52 +01:00
Šarūnas Nejus
ee289844ed
Add _process_album and _process_item methods 2025-10-15 09:55:52 +01:00
J0J0 Todos
1acec39525
lastgenre: Use apply methods during import 2025-10-15 09:52:32 +01:00
J0J0 Todos
8613b3573c
lastgenre: Refactor final genre apply
- Move item and genre apply to separate helper functions. Have one
  function for each to not overcomplicate implementation!
- Use a decorator log_and_pretend that logs and does the right thing
  depending on wheter --pretend was passed or not.
- Sets --force (internally) automatically if --pretend is given (this is
  a behavirol change needing discussion)
2025-10-15 09:52:32 +01:00
Alok Saboo
c7ee0e326c Add prefix to log messages for genre fetching in LastGenrePlugin 2025-09-21 07:07:14 +02:00
Alok Saboo
0be4cecf82 Update beetsplug/lastgenre/__init__.py
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-09-21 07:07:14 +02:00
Alok Saboo
5e6dd674a9 Update beetsplug/lastgenre/__init__.py
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-09-21 07:07:14 +02:00
Alok Saboo
84986dc42d Enhance lastgenre plugin: add item.try_write() for write operations and improve documentation clarity 2025-09-21 07:07:14 +02:00
Alok Saboo
a57ef2cb3b Add --pretend option to lastgenre plugin for previewing genre changes 2025-09-21 07:07:14 +02:00
J0J0 Todos
7a5cfa8f46 lastgerne: Update wl/tree load methods docstrings 2025-09-10 07:36:47 +02:00
J0J0 Todos
d2caed3971 lastgenre: Also log which whitelist file is loading 2025-09-10 07:36:47 +02:00
J0J0 Todos
6601cbf8c0 lastgenre: canonical/whitelist setting None load default files 2025-09-10 07:36:47 +02:00
J0J0 Todos
6bc30eaf18 lastgenre: Add docstrings to file load methods 2025-09-10 07:36:47 +02:00
J0J0 Todos
6da72beeb0 lastgenre: Add expanduser to whitelist/tree load 2025-09-10 07:36:47 +02:00
J0J0 Todos
81d342b79f lastgenre: Simplify default tree loading 2025-09-10 07:36:47 +02:00
J0J0 Todos
c54a54682f lastgenre: Use pathlib and simplify whitelist load
- Read the whole file using Path().read_text()
- Strip whitespace and lower() transform

Drawbacks:

- Normalization gets lost (normpath did that)
2025-09-10 07:36:47 +02:00
J0J0 Todos
fbd90b0507 lastgenre: Use pathlib for opening tree file
instead of syspath(normpath())

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-09-10 07:36:47 +02:00
J0J0 Todos
0cdb1224b9 lastgenre: Fix c14n load log msg format 2025-09-10 07:36:47 +02:00
J0J0 Todos
bbde63d87e lastgenre: Accept AI suggested use open() for tree file
instead of codecs.open(), which most probably is a relict of beets' Python2/3 compatibility area.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
2025-09-10 07:36:47 +02:00
J0J0 Todos
a98fa054fe lastgenre: Fix failing CI tests by using syspath
when loading c14n file.
2025-09-10 07:36:47 +02:00
J0J0 Todos
5ff88b46cf lastgenre: Fix another mypy error in c14n load
(that was only happening in CI and not by local poe check-types)
2025-09-10 07:36:47 +02:00
J0J0 Todos
8ae29e42bf lastgenre: Fix mypy errors in file load methods 2025-09-10 07:36:47 +02:00
J0J0 Todos
6ed17912b4 lastgenre: Fix _load_whitelist return type bytes 2025-09-10 07:36:47 +02:00
J0J0 Todos
bf903fc27d lastgenre: Move file loading to helpers
and add return types.
2025-09-10 07:36:47 +02:00
Šarūnas Nejus
d6b6ac3387
Replace logging f-strings with arguments 2025-08-30 23:10:21 +01:00
Šarūnas Nejus
d93ddf8dd4
Do not use explicit indices for logging args when not needed 2025-08-30 23:10:21 +01:00
Šarūnas Nejus
1c16b2b308
Replace string concatenation (' + ')
- Join hardcoded strings
- Replace concatenated variables with f-strings
2025-08-30 23:10:15 +01:00
J0J0 Todos
0dcf7fdc23 lastgenre: Remove leftover/unused REPLACE constant 2025-08-24 09:20:36 +02:00
J0J0 Todos
05a1a95ee9 lastgenre: Dedup combine/resolve/label/format code 2025-08-24 09:20:36 +02:00
J0J0 Todos
d8e90d8e54 lastgenre: Resolve combined genres in each stage
To ensure proper fallback to the next stage, in each stage we do a full
combine/resolve/log.

Also we directly return if have satisfied results. As a bonus this
improves readability.

Some duplicate code on the label magic though...
2025-08-24 09:20:36 +02:00
J0J0 Todos
fa8b5d7495 lastgenre: Fix canonicalization of non-valid genres
- Remove "early whitelist check", since it breaks canonicalization of
  actually unwanted genres (not whitelisted) resolving "up" to parent
  genres.
- Remove the filter_valid_genres method entirely and get back to inline
  list comprehensions. The caveat is that None genres are not catched
  that way (see below, should be one of the last functions that finally
  returns lists only)
- Along the way, fix _last_lookup's rearly return to empty list instead
  of None.
2025-08-24 09:20:36 +02:00
Šarūnas Nejus
816d06f160
Fix plugin types 2025-07-16 14:06:34 +01:00
Šarūnas Nejus
7cada1c9f8
Remove no-op decargs 2025-07-08 11:37:33 +01:00
J0J0 Todos
eb83491788 lastgenre: Fix "original fallback" conditions
This was not thought through clearly before. It now behaves as follows
which I suppose is least surprising to a user:

- force is on, keep_existing is on, but the whitelist is DISABLED
- no stage found anything on last.fm
- fall back to the original genre

If in this example the whitelist would be ENABLED, the behaviour
changes: Only if the existing genre passes the whitelist test the
original is kept.
2025-04-09 22:52:07 +02:00
J0J0 Todos
f4d22a83b5 lastgenre: Catch NoneType errors in _fitler_valid_genres 2025-04-09 22:52:07 +02:00
J0J0 Todos
702ddf493e lastgenre: Early validate genres, new debug option
- Revert/fix last.fm fetcher methods to validate genres.

  - In past versions (<=2.2) _resolve_genres which included whitelist
    checks ran instantly after fetching last.fm tags which made sure the
    next stage is hit when nothing worthwhile was found (e.g fallback
    album -> artist).

  - Bring back this behavior but don't run a full _resolve_genres but a
    quick valid (whitelist) check only!

- Introduce an extended config/CLI option that allows to really log what
  each stage fetches (prior to validation/whitelist filtering).

  - Since this potentially is verbose especially with VA albums (a lot
    of artist tag fetches) for performance and debug log clutter reasons
    this is disabled by default.

- Clarify final last.fm tags debug log message to "valid last.fm genres"
2025-04-09 22:52:07 +02:00
J0J0 Todos
c57e5a1fb8 lastgenre: Tiny fix in early no-force return 2025-04-09 22:52:07 +02:00
J0J0 Todos
edd366e766 lastgenre: Fix album not falling back to artist stage
which was the usual behaviour in lastgenre ever since and it should be
kept that way. Also refactor "if track" to use a similar notation for
overall code readability.
2025-04-09 22:52:07 +02:00
J0J0 Todos
2b276e07f1 lastgenre: Log unconfigured fallback 2025-04-09 22:52:07 +02:00
J0J0 Todos
e20cf7f20b lastgenre: Rework combine, stringify, count reduction
- Rename method from _combine_genres() to _combine_resolve_and_log() to
  make clear that it not only combines new and old genres but also
  resolves them (which in this plugin's wording means "do the magic" of
  canonicalizationm, whitelist checking and reducing to a configured
  genre count).

- Clarify in _resolve docstring that a possible outcome might be all
  genres being removed.

- Add an additional log message telling which existing genres are taken
  into account BEFORE "the magic happens".

- Rename _to_delimited_genre_string() to _format_and_stringify()

- Move count reduction logic to _resolve_genres()

- Fix and rename a test
2025-04-09 22:52:07 +02:00
J0J0 Todos
3291aa03e7 lastgenre: Describe in docstring what _resolve_genres does 2025-04-09 22:52:07 +02:00
J0J0 Todos
15f4b2ac29 lastgenre: Place to_delim. func near _get_genre
and the other helpers.
2025-04-09 22:52:07 +02:00
J0J0 Todos
eba3dc15fd lastgenre: Final label only if required in _get_genre() 2025-04-09 22:52:07 +02:00
J0J0 Todos
94f78ae70f lastgenre: Prevent returning empty genre list
As reported in #5649 when new last.fm genres were found, they still might
get kicked out by the whitelist check in _resolve_genres(). This might
lead to _combine_genres() returning an empty list.

The desired outcome though is that since still nothing worthwhile was
found, the next stage should be entered - which in this case is,
returning with the configured fallback genre (or the default fallback
None).

The any() check makes sure this is the case and moving out the
string conversion from _combine_genres() makes this code slightly more
readable.
2025-04-09 22:52:07 +02:00
J0J0 Todos
9d4653f92f Final lastgenre docstring nitpicks
and a tiny docs fix.
2025-01-23 09:04:06 +01:00
J0J0 Todos
2708be257d Final nitpicks on lastgenre --help wording 2025-01-23 08:32:10 +01:00
J0J0 Todos
2f40b315f4 Add lastgenre --no-force, reword help 2025-01-22 18:39:36 +01:00