Skip to content

lastgenre: Refactor _get_genre#6474

Draft
JOJ0 wants to merge 16 commits intolastgenre_aliasesfrom
lastgenre_refactor_get_genre
Draft

lastgenre: Refactor _get_genre#6474
JOJ0 wants to merge 16 commits intolastgenre_aliasesfrom
lastgenre_refactor_get_genre

Conversation

@JOJ0
Copy link
Copy Markdown
Member

@JOJ0 JOJ0 commented Mar 30, 2026

Description

The monolithic _get_genre method was broken down into the following private instance methods:

  • Core Helpers:
    • _try_resolve_stage: Handles the canonicalization and logging of genres for a specific stage.
    • _fallback_stage: Provides the configured fallback genre.
  • Lookup Stages:
    • _handle_existing_genres: Manages the initial check for pre-existing genres and the cleanup_existing logic.
    • _get_track_genre_stage: Fetches and resolves track-level genres.
    • _get_album_genre_stage: Fetches and resolves album-level genres.
    • _get_artist_genre_stage: Fetches and resolves artist-level genres, including multi-valued album artists and "Various Artists" logic.
    • _get_va_genre_stage: specifically handles the plurality logic for "Various Artists" albums.
  • Fallbacks:
    • _get_original_fallback: Handles the "keep_existing" logic that attempts to use/canonicalize originally present genres if no new ones are found.

To Do

  • Documentation
  • Changelog
  • Tests (_get_genre was already well covered and the signature of the method was kept)

JOJ0 added 14 commits March 19, 2026 23:01
- Test file format (valid and error cases)
- Test regex pattern matching (_is_ignored)
- Test _resolve_genres: ignored genres filtered
- Test _resolve_genres: c14n ancestry walk blocked for ignored tags
- Test _resolve_genres: without whitelist, oldest ancestor is kept
- Test _resolve_genres: whithout whitelist, ignored oldest ancestor is
  removed
- Prevents wrong last.fm genres based on a per artist (or global) list of regex
  patterns that should be ignored.
  - Genre _ignoring_ happens in two places: Right after fetching the
    last.fm genre and in _resolve_genres.
  - As a fallback literal string matching can be used instead of
    supplying a regex pattern
- Includes docs for the new feature.
@JOJ0 JOJ0 requested a review from a team as a code owner March 30, 2026 17:17
@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 changed the base branch from master to lastgenre_aliases March 30, 2026 17:20
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 81.15942% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.99%. Comparing base (1943b14) to head (89cf4e5).
⚠️ Report is 110 commits behind head on lastgenre_aliases.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/__init__.py 78.57% 23 Missing and 13 partials ⚠️
beetsplug/lastgenre/client.py 80.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           lastgenre_aliases    #6474      +/-   ##
=====================================================
+ Coverage              69.73%   69.99%   +0.25%     
=====================================================
  Files                    145      146       +1     
  Lines                  18534    18661     +127     
  Branches                3023     3054      +31     
=====================================================
+ Hits                   12924    13061     +137     
+ Misses                  4976     4958      -18     
- Partials                 634      642       +8     
Files with missing lines Coverage Δ
beetsplug/lastgenre/utils.py 100.00% <100.00%> (ø)
beetsplug/lastgenre/client.py 67.85% <80.00%> (+14.66%) ⬆️
beetsplug/lastgenre/__init__.py 84.21% <78.57%> (+8.66%) ⬆️

... 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 marked this pull request as draft March 30, 2026 20:05
@JOJ0 JOJ0 mentioned this pull request Apr 3, 2026
3 tasks
@JOJ0 JOJ0 force-pushed the lastgenre_aliases branch from f4b9436 to e32a77f Compare April 3, 2026 18:17
@JOJ0 JOJ0 added the plugin Pull requests that are plugins related label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin Pull requests that are plugins related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant