Skip to content

Conversation

JOJ0
Copy link
Member

@JOJ0 JOJ0 commented Aug 31, 2025

Often last.fm does not have artist genres for delimiter-separated artist names (eg. "Artist One, Artist Two"). This splits out by (the configured) delimiter and gathers each artist's last.fm genre.

FIXME: It would be cool if a configured list of artist name separators would be used instead of a hard-coded one.

Description

Fixes #X.

To Do

  • Documentation.
  • Changelog.
  • Tests.

Summary by Sourcery

Enhance album genre lookup to handle multi-artist album artists by splitting the albumartist string on configured and common separators, then aggregating each sub-artist’s genres from Last.fm.

New Features:

  • Split multi-artist albumartist strings on a configurable delimiter and common separators to fetch each artist’s genre.
  • Introduce fetch_split_album_artist_genre helper method to query Last.fm per split artist.

Enhancements:

  • Define a regex pattern of common separators (e.g., feat., &, x, +, and others) for detecting and splitting multi-artist names.

Copy link
Contributor

sourcery-ai bot commented Aug 31, 2025

Reviewer's Guide

Introduces splitting logic for multi-artist album names: a new helper method fetch_split_album_artist_genre wraps the existing API lookup, and _try_resolve_stage is extended to detect configured separators, split the albumartist string, and aggregate each artist’s genre.

Sequence diagram for multi-artist album genre fetching

sequenceDiagram
    participant Plugin as LastGenrePlugin
    participant Album as Album
    participant LastFM as LASTFM
    Plugin->>Album: Get albumartist
    Plugin->>Plugin: Check for separators in albumartist
    alt Separators found
        Plugin->>Plugin: Split albumartist into individual artists
        loop For each split artist
            Plugin->>LastFM: get_artist(split_artist)
            LastFM-->>Plugin: Return genre
            Plugin->>Plugin: Aggregate genre
        end
    else No separators found
        Plugin->>LastFM: get_artist(albumartist)
        LastFM-->>Plugin: Return genre
    end
    Plugin->>Album: Assign aggregated genre(s)
Loading

Class diagram for updated LastGenrePlugin methods

classDiagram
    class LastGenrePlugin {
        +fetch_album_artist_genre(obj)
        +fetch_split_album_artist_genre(split_artist)
        +fetch_artist_genre(item)
        +_try_resolve_stage(stage_label, keep_genres, new_genres)
    }
    LastGenrePlugin : fetch_split_album_artist_genre(split_artist)
    LastGenrePlugin : _try_resolve_stage(stage_label, keep_genres, new_genres)
    LastGenrePlugin : fetch_album_artist_genre(obj)
    LastGenrePlugin : fetch_artist_genre(item)
    LastGenrePlugin --> LASTFM : get_artist(artist_name)
Loading

File-Level Changes

Change Details Files
Add fetch_split_album_artist_genre helper for single-artist lookups
  • Define fetch_split_album_artist_genre method with docstring
  • Use existing _last_lookup API call to fetch genre for a given artist name
beetsplug/lastgenre/__init__.py
Enhance _try_resolve_stage to handle multi-artist album names
  • Log a debug message when no album artist genre is found
  • Define a list of regex-escaped separators (configurable delimiter plus common connectors)
  • Detect presence of any separator in the albumartist string and log splitting event
  • Build a combined regex pattern and split the albumartist string on all separators
  • Iterate over each trimmed artist segment, fetch its genre with the new helper, and append to new_genres
beetsplug/lastgenre/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

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_multi_artist_fix branch from 86e07aa to 2a27349 Compare August 31, 2025 19:52
Copy link

codecov bot commented Aug 31, 2025

Codecov Report

❌ Patch coverage is 22.50000% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.38%. Comparing base (55667fa) to head (314a914).
⚠️ Report is 28 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/__init__.py 22.50% 29 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5981      +/-   ##
==========================================
- Coverage   66.50%   66.38%   -0.13%     
==========================================
  Files         117      117              
  Lines       18123    18141      +18     
  Branches     3071     3081      +10     
==========================================
- Hits        12052    12042      -10     
- Misses       5415     5444      +29     
+ Partials      656      655       -1     
Files with missing lines Coverage Δ
beetsplug/lastgenre/__init__.py 53.39% <22.50%> (-4.85%) ⬇️

... and 2 files 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 changed the title lastgenre: Fix multi-artist-albums lastgenre: Fix fetching albumartist genre for multi-artist albums Aug 31, 2025
@JOJ0 JOJ0 changed the title lastgenre: Fix fetching albumartist genre for multi-artist albums lastgenre: Fix fetching artist genre for multi-artist albums Aug 31, 2025
@JOJ0 JOJ0 force-pushed the lastgenre_multi_artist_fix branch from 2a27349 to 29fac0d Compare September 4, 2025 04:37
Often last.fm does not have artist genres for delimiter-separated artist
names (eg. "Artist One, Artist Two"). This splits out by (the
configured) delimiter and gathers each artist's last.fm genre.

FIXME: It would be cool if a configured list of artist name separators
would be used instead of a hard-coded one.
@JOJ0 JOJ0 force-pushed the lastgenre_multi_artist_fix branch 2 times, most recently from c7fec68 to 58463f0 Compare September 9, 2025 05:35
- Move albumartist splitting to separator method
- Default separators without whitespace, handle in method
- Use word boundaries for alnum seps and no boundaries for symbols
before trying any string splitting, log accordingly.
@JOJ0 JOJ0 force-pushed the lastgenre_multi_artist_fix branch from 58463f0 to 314a914 Compare September 11, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant