Skip to content

Add extra_tags support to Discogs plugin#6433

Open
jdoe29103 wants to merge 10 commits intobeetbox:masterfrom
jdoe29103:master
Open

Add extra_tags support to Discogs plugin#6433
jdoe29103 wants to merge 10 commits intobeetbox:masterfrom
jdoe29103:master

Conversation

@jdoe29103
Copy link

Description

Fixes #6412.

This is my first time submitting a PR for an open source project so please point out any mistakes!

Summary

  • Add discogs.extra_tags configuration option to narrow Discogs search queries using existing tag values.
  • Map supported tags (barcode, catalognum, country, label, media, year) to corresponding Discogs search parameters.
  • Update Discogs plugin documentation and tests to cover the new behavior.

Details

The Discogs plugin now mirrors musicbrainz.extra_tags by allowing users to specify additional tags that should be used when building Discogs search filters.

  • New config option: discogs.extra_tags (default: []).
  • Supported tags and their Discogs search parameters:
    • barcodebarcode
    • catalognumcatno (whitespace removed)
    • countrycountry
    • labellabel
    • mediaformat
    • yearyear
  • Tags alias and tracks are recognized but intentionally ignored for Discogs, since the Discogs API does not provide direct equivalents for these MusicBrainz-specific fields.

When extra_tags are configured, the plugin uses beets.util.plurality over the items in the import session to select the most common value for each configured tag and adds the corresponding Discogs filter.

Testing

  • Added unit tests in test/plugins/test_discogs.py to verify:
    • Default search filters remain unchanged when extra_tags is not set.
    • discogs.extra_tags: [label, catalognum] results in label and catno filters populated from library items (with catalog number whitespace stripped).
  • Ran:
    • pytest test/plugins/test_discogs.py
    • pytest test/plugins/test_musicbrainz.py

(...)

To Do

  • Documentation.
  • Changelog.
  • Tests.

@jdoe29103 jdoe29103 requested a review from a team as a code owner March 9, 2026 21:09
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.54%. Comparing base (80d08ed) to head (624b257).
⚠️ Report is 35 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/discogs/__init__.py 73.91% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6433      +/-   ##
==========================================
+ Coverage   69.42%   69.54%   +0.11%     
==========================================
  Files         141      141              
  Lines       18452    18495      +43     
  Branches     3020     3026       +6     
==========================================
+ Hits        12811    12862      +51     
+ Misses       5004     4996       -8     
  Partials      637      637              
Files with missing lines Coverage Δ
beetsplug/discogs/__init__.py 66.87% <73.91%> (+1.51%) ⬆️

... and 6 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.

@jdoe29103 jdoe29103 changed the title Add extra_tags support to Discogs plugin Add extra_tags support to Discogs plugin Mar 9, 2026
@snejus
Copy link
Member

snejus commented Mar 10, 2026

Hey, thanks for your contribution! I would suggest having a look at MusicBrainzPlugin at beetsplug/musicbrainz.py, namely extra_mb_field_by_tag property and get_album_criteria with get_search_query_with_filters methods. Ideally I'd want to see the same property and methods in DiscogsPlugin as well, if possible!

@jdoe29103
Copy link
Author

Hey, thanks for your contribution! I would suggest having a look at MusicBrainzPlugin at beetsplug/musicbrainz.py, namely extra_mb_field_by_tag property and get_album_criteria with get_search_query_with_filters methods. Ideally I'd want to see the same property and methods in DiscogsPlugin as well, if possible!

Thanks for taking the time @snejus!
I’ve added an extra_discogs_field_by_tag cached property, mirroring extra_mb_field_by_tag, and updated get_search_query_with_filters to build Discogs search filters from the configured extra_tags.
Because the Discogs API is query+filters search (rather than a criteria dictionary), I didn’t introduce a separate get_album_criteria helper, but the behavior should be aligned with the MusicBrainz plugin.

Copy link
Member

@JOJ0 JOJ0 left a comment

Choose a reason for hiding this comment

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

great feature idea! just some questions inline.

# MusicBrainz "alias" or "tracks" search fields, so we ignore
# those tags if configured.
if tag in {"alias", "tracks"}:
continue
Copy link
Member

Choose a reason for hiding this comment

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

why is it required to remove those silently? if we remove that check, would a misconfiguration throw an error and inform the user that they should fix there config?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think it's required. I went with this approach because I was attempting to mirror the musicbrainz.py implementation and just sort of left it there. I don't see why it couldn't be removed though.


value = str(most_common)
if tag == "catalognum":
value = value.replace(" ", "")
Copy link
Member

@JOJ0 JOJ0 Mar 11, 2026

Choose a reason for hiding this comment

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

aha interesting, so discogs api gives better results if whitespace is removed from queries on that field. did you find this out by trial and error or do discogs api docs state that?

Copy link
Author

Choose a reason for hiding this comment

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

The catalognum whitespace stripping is copied from the MusicBrainz plugin’s get_album_criteria implementation, which normalizes catalognum by removing spaces before using it in searches.

I did a few manual Discogs queries while working on this and found that removing spaces is generally helpful (users often tag catalog with spaces, while Discogs catno fields are typically stored without them in my testing), but I didn’t see this explicitly documented.

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
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.

3 participants