Skip to content

lastgenre: Improve original fallback (better use of aliases and count) - #6890

Open
JOJ0 wants to merge 2 commits into
lastgenre_refactor_get_genrefrom
lastgenre_improve_original_fallback
Open

lastgenre: Improve original fallback (better use of aliases and count)#6890
JOJ0 wants to merge 2 commits into
lastgenre_refactor_get_genrefrom
lastgenre_improve_original_fallback

Conversation

@JOJ0

@JOJ0 JOJ0 commented Jul 30, 2026

Copy link
Copy Markdown
Member

Description

When _get_genre runs with force, whitelist and canonicalization enabled, as a last resort it tries to fall back to the original genres. Of course this stage normalizes, canonicalizes, does all the stuff it's supposed to when resolving the stage. That also includes reducing genres to the configured count. Now in that case that could reduce the list of genres and is not exactly what a fall back to what we had before should look like.

This PR changes the stage as follows:

We don't run through _try_resolve_stage instantly because we want to make sure the count setting doesn't kick out anything prematurely! We then apply whitelist checks and return if something valid is found.

The very last resort action is kept as we had it already: Use keep_genres (the lowercased originals) to canonicalize and hope that now we find a whitelisted parent genre.

Note: Requires #6474

To Do

  • Documentation. (Not required IMO)
  • Changelog.
  • Tests. (We might want to add some, need to check)

@github-actions github-actions Bot added the lastgenre lastgenre plugin label Jul 30, 2026
@github-actions

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@JOJ0
JOJ0 force-pushed the lastgenre_improve_original_fallback branch from dfef785 to a5f7d91 Compare July 30, 2026 05:53
@JOJ0
JOJ0 changed the base branch from master to lastgenre_refactor_get_genre July 30, 2026 05:54
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.67%. Comparing base (e2f60a5) to head (389148e).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                       Coverage Diff                        @@
##           lastgenre_refactor_get_genre    #6890      +/-   ##
================================================================
- Coverage                         75.67%   75.67%   -0.01%     
================================================================
  Files                               163      163              
  Lines                             21418    21418              
  Branches                           3385     3384       -1     
================================================================
- Hits                              16209    16208       -1     
- Misses                             4410     4411       +1     
  Partials                            799      799              
Files with missing lines Coverage Δ
beetsplug/lastgenre/__init__.py 81.59% <100.00%> (+0.34%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0
JOJ0 force-pushed the lastgenre_improve_original_fallback branch 2 times, most recently from c53cebb to 1906d93 Compare July 30, 2026 06:05
@JOJ0 JOJ0 mentioned this pull request Jul 30, 2026
3 tasks
@JOJ0
JOJ0 force-pushed the lastgenre_improve_original_fallback branch from 1906d93 to b9cfd57 Compare August 5, 2026 06:09
The discrepancy:

- Normalization might help to keep more whitelisted genres!
- But running through try_resolve_stage would be less code
- The difference being that the latter reduces existing genres to the
  configured count which is not really fitting with a "last resort
  fallback to original genres"

The here suggested solution:

- We don't run through try_resolve_stage instantly because we want to
  make sure the "count" setting doesnt kick out anything but we apply
  aliases before whitelist check.
@JOJ0
JOJ0 force-pushed the lastgenre_improve_original_fallback branch from b9cfd57 to 39927e7 Compare August 5, 2026 06:18
@JOJ0 JOJ0 changed the title lastgenre: improve original fallback lastgenre: Improve original fallback (better use of aliases) Aug 5, 2026
@JOJ0 JOJ0 changed the title lastgenre: Improve original fallback (better use of aliases) lastgenre: Improve original fallback (better use of aliases and count) Aug 5, 2026
@JOJ0
JOJ0 marked this pull request as ready for review August 5, 2026 06:41
Copilot AI lite review requested due to automatic review settings August 5, 2026 06:41
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

PR make lastgenre original-genre fallback better when force + keep_existing + whitelist (+ canonical) is on. Goal is: do alias normalize + whitelist check without _resolve_genres path that can apply count too early, then only do canonical-parent fallback as last resort.

Changes:

  • Change “original fallback” stage to alias-normalize originals, then run whitelist/ignore filtering directly (no _try_resolve_stage yet).
  • Keep existing canonicalized-parent fallback via _try_resolve_stage(...) when nothing survives whitelist after aliasing.
  • Update docstring to describe new fallback order.

Comment on lines +513 to +517
normalized = [
norm if norm != g.lower() else g
for g in genres
if (norm := normalize_genre(self._log, self.alias_patterns, g))
]
Comment thread beetsplug/lastgenre/__init__.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

beetsplug/lastgenre/init.py:517

  • grug see new logic to avoid count dropping good original genres before whitelist. grug want regression test so this not break later. add pytest case where force+keep_existing+whitelist+canonical and count=1, existing genres has non-whitelisted first then whitelisted later, and expect "original fallback" returns whitelisted one (not lost to early count).
        # We do not run through try_resolve_stage yet because count could drop
        # existing genres, but we still apply aliases before whitelist
        # filtering.
        normalized = [
            norm if norm != g.lower() else g
            for g in genres
            if (norm := normalize_genre(self._log, self.alias_patterns, g))
        ]

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lastgenre lastgenre plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants