From 35e926a51b232d95ea43b5b7b3ca7d320b9b2ce9 Mon Sep 17 00:00:00 2001 From: Tai Lee Date: Mon, 27 May 2013 01:28:40 +1000 Subject: [PATCH] Add Discogs and general source weight penalty (configurable, undocumented). Discogs (and other individual plugins) should return a penalty between 0.0 and 0.1, which will be multiplied by the general source weight. This allows individual plugins to be weighted against relative to each other, and amplified together against other penalty categories (track, title, etc.) --- beets/config_default.yaml | 4 ++++ beetsplug/discogs.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 82db31707..b7fba6848 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -73,6 +73,7 @@ match: tracklength: strong tracknumber: strong weight: + source: 3.0 artist: 3.0 album: 3.0 track: 1.0 @@ -85,3 +86,6 @@ match: track_length_max: 30 track_length: 2.0 track_id: 5.0 + +discogs: + source_weight: 0.5 diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index ffb8b8045..951c5d593 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -15,6 +15,7 @@ """Adds Discogs album search support to the autotagger. Requires the discogs-client library. """ +from beets import config from beets.autotag.hooks import AlbumInfo, TrackInfo from beets.autotag.match import current_metadata, VA_ARTISTS from beets.plugins import BeetsPlugin @@ -27,6 +28,10 @@ import time log = logging.getLogger('beets') +# Distance parameters. +DISCOGS_SOURCE_WEIGHT = config['discogs']['source_weight'].as_number() +SOURCE_WEIGHT = config['match']['weight']['source'].as_number() + # Silence spurious INFO log lines generated by urllib3. urllib3_logger = logging.getLogger('requests.packages.urllib3') urllib3_logger.setLevel(logging.CRITICAL) @@ -36,6 +41,11 @@ discogs_client.user_agent = 'beets/%s +http://beets.radbox.org/' % \ beets.__version__ class DiscogsPlugin(BeetsPlugin): + def album_distance(self, items, album_info, mapping): + """Returns the discogs source weight and the maximum source weight. + """ + return DISCOGS_SOURCE_WEIGHT * SOURCE_WEIGHT, SOURCE_WEIGHT + def candidates(self, items, artist, album, va_likely): """Returns a list of AlbumInfo objects for discogs search results matching an album and artist (if not various).