beets icon indicating copy to clipboard operation
beets copied to clipboard

Simplify tagging

Open snejus opened this issue 1 month ago • 2 comments

Refactor item tagging and fix several underlying issues.

Fixes

  • Synchronise all artist list fields. Notably, artist_sort / artists_sort and artist_credit / artists_credit fields have not been synchronised.
  • Fix overwrite_null configuration which was previously ignored for fields defined in autotag/__init__.py::SPECIAL_FIELDS.

Updates

  • Move metadata application logic into Match objects: add Match.apply_metadata, AlbumMatch.apply_metadata, AlbumMatch.apply_album_metadata, and TrackMatch.apply_metadata; callers now use those methods instead of legacy free functions.
  • Remove legacy functions from beets.autotag.__init__ (apply_item_metadata, apply_album_metadata, apply_metadata) and related globals (SPECIAL_FIELDS, log), and export only core types (AlbumInfo, AlbumMatch, TrackInfo, TrackMatch, Proposal, Recommendation, tag_album, tag_item).
  • Add structured metadata facilities to Info and subclasses:
    • Info.type class property and nullable_fields for per-type 'overwrite_null' config.
    • Info.raw_data and Info.item_data computed properties to apply artist_credit rules, filter nulls, and map media-specific field names.
    • AlbumInfo and TrackInfo extend raw_data/item_data behavior to handle album/track specifics (date zeroing, tracktotal, mb_releasetrackid, per-disc numbering).
  • Introduce TrackInfo.merge_with_album to merge track-level data with album-level fallback for a final item payload.
  • Move correct_list_fields to hooks.py and update it to keep unmapped / non-media single/list fields in sync (artist <-> artists, albumtype <-> albumtypes, etc.).
  • Wire changes through the codebase:
    • Pass Item objects into TrackMatch in match.tag_item to enable item-level metadata application.
    • Replace calls to removed autotag apply functions with Match.apply_metadata invocations in beets/importer/tasks.py, beetsplug/bpsync.py, and beetsplug/mbsync.py.
    • Update importer logic to set album artist fallbacks for albumartists / mb_albumartistids when missing.
  • Add and update tests:
    • New test/autotag/test_hooks.py and test/autotag/test_match.py to validate new data mapping, list field synchronization, overwrite behavior, and assignment logic.

snejus avatar Nov 15 '25 16:11 snejus

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 Nov 15 '25 16:11 github-actions[bot]

Codecov Report

:x: Patch coverage is 95.45455% with 5 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 68.26%. Comparing base (60b4a38) to head (cf31d00). :warning: Report is 1 commits behind head on master. :white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/autotag/hooks.py 97.70% 1 Missing and 1 partial :warning:
beetsplug/bpsync.py 50.00% 2 Missing :warning:
beets/importer/tasks.py 92.30% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6165   +/-   ##
=======================================
  Coverage   68.26%   68.26%           
=======================================
  Files         138      138           
  Lines       18791    18766   -25     
  Branches     3167     3158    -9     
=======================================
- Hits        12827    12811   -16     
+ Misses       5290     5286    -4     
+ Partials      674      669    -5     
Files with missing lines Coverage Δ
beets/autotag/__init__.py 72.72% <ø> (-14.89%) :arrow_down:
beets/autotag/match.py 76.92% <100.00%> (ø)
beetsplug/mbsync.py 82.05% <100.00%> (+0.23%) :arrow_up:
beets/importer/tasks.py 90.83% <92.30%> (-0.06%) :arrow_down:
beets/autotag/hooks.py 98.97% <97.70%> (-1.03%) :arrow_down:
beetsplug/bpsync.py 19.04% <50.00%> (+0.97%) :arrow_up:
: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 Nov 15 '25 16:11 codecov[bot]

@semohr @henry-oberholtzer @JOJ0 would be happy to have your eyes over this as I think this is a significant piece of work making autotagging somewhat simpler (hopefully!).

snejus avatar Dec 17 '25 11:12 snejus

@semohr @henry-oberholtzer @JOJ0 would be happy to have your eyes over this as I think this is a significant piece of work making autotagging somewhat simpler (hopefully!).

I'll try to find some time after first wave of xmadness is over

JOJ0 avatar Dec 17 '25 21:12 JOJ0