beets icon indicating copy to clipboard operation
beets copied to clipboard

lastgenre: Use albumartists field to improve last.fm results

Open JOJ0 opened this issue 4 months ago • 2 comments

Often last.fm does not find artist genres for delimiter-separated artist names (eg. "Artist One, Artist Two") or where multiple artists are combined with "concatenation words" like "and" , "+", "featuring" and so on.

This fix gathers each artist's last.fm genre separately by using Beets' mutli-valued albumartists field to improve the likeliness of finding genres in the artist genre fetching stage.

Refactoring was done along the existing genre fetching helper functions (fetch_album_genre, fetch_track_genre, ...):

  • last.fm can be asked for genre for these combinations of metadata:

    • albumartist/album
    • artist/track
    • artist
  • Instead of passing Album or Item objects directly to these helpers., generalize them and pass the (string) metadata directly.

  • Passing "what's to fetch" in the callers instead of hiding it in the methods also helps readability in _get_genre()

  • And reduces the requirement at hand for another additional method (or adaptation) to support "multi-albumartist genre fetching"

  • [x] ~Documentation~

  • [x] Changelog

  • [x] ~Tests~

JOJ0 avatar Aug 31 '25 19:08 JOJ0

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.

github-actions[bot] avatar Aug 31 '25 19:08 github-actions[bot]

Codecov Report

:x: Patch coverage is 27.77778% with 13 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 67.43%. Comparing base (f79c125) to head (138f77d). :white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/__init__.py 27.77% 12 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5981      +/-   ##
==========================================
- Coverage   67.46%   67.43%   -0.03%     
==========================================
  Files         136      136              
  Lines       18535    18541       +6     
  Branches     3130     3133       +3     
==========================================
- Hits        12504    12503       -1     
- Misses       5366     5373       +7     
  Partials      665      665              
Files with missing lines Coverage Δ
beetsplug/lastgenre/__init__.py 69.81% <27.77%> (-1.93%) :arrow_down:
:rocket: New features to boost your workflow:
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Aug 31 '25 19:08 codecov[bot]

I'd like to rerequest some eyes here @snejus @semohr @henry-oberholtzer

also i don't think it interferes much with https://github.com/beetbox/beets/pull/6169

JOJ0 avatar Dec 17 '25 20:12 JOJ0

This solves the issues I was having, thank you for this.

A minor note is that since it only tries to use the albumartists for the fetch_artist_genre, there could be a potential album match with fetch_album_genre for the individual artists (e.g. fetch_album_genre(obj.albumartists[0], obj.album)). Which might have more applicable tags than just falling back to the artists.

But I'm not sure how common that is, and the artist tags are plenty for my use case.

Nedra1998 avatar Dec 18 '25 00:12 Nedra1998

Looks great to me, for my part I think some type hints would be good to add to the fetch_album_ fields while we're at it.

thanks! will do!

JOJ0 avatar Dec 19 '25 13:12 JOJ0