From e9b22cfa3b75c716eae9f74398747fcd856777cf Mon Sep 17 00:00:00 2001 From: David Logie Date: Mon, 3 Apr 2017 13:43:42 +0100 Subject: [PATCH] Use preferred countries when selecting a release event. --- beets/autotag/mb.py | 21 ++++++++++++++++++--- docs/changelog.rst | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index a6133adb1..3c5ccee77 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -109,6 +109,22 @@ def _preferred_alias(aliases): return matches[0] +def _preferred_release_event(release): + """Given a release, select and return the user's preferred release + event as a tuple of (country, release-date). Falls back to the + default release event if a preferred event is not found. + + """ + countries = config['match']['preferred']['countries'].as_str_seq() + + for event in release.get('release-event-list', {}): + for country in countries: + if country in event['area']['iso-3166-1-code-list']: + return country, event['date'] + + return release.get('country'), release.get('date') + + def _flatten_artist_credit(credit): """Given a list representing an ``artist-credit`` block, flatten the data into a triple of joined artist name strings: canonical, sort, and @@ -301,7 +317,6 @@ def album_info(release): info.artist = config['va_name'].as_str() info.asin = release.get('asin') info.releasegroup_id = release['release-group']['id'] - info.country = release.get('country') info.albumstatus = release.get('status') # Build up the disambiguation string from the release group and release. @@ -318,8 +333,8 @@ def album_info(release): if reltype: info.albumtype = reltype.lower() - # Release dates. - release_date = release.get('date') + # Release events. + info.country, release_date = _preferred_release_event(release) release_group_date = release['release-group'].get('first-release-date') if not release_date: # Fall back if release-specific date is not available. diff --git a/docs/changelog.rst b/docs/changelog.rst index 37c1ef9fb..ddb6ec603 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -47,6 +47,8 @@ New features: * A new :ref:`bell` configuration option under the ``import`` section enables a terminal bell when input is required. Thanks to :user:`SpirosChadoulos`. :bug:`2366` :bug:`2495` +* Importing a release with multiple release events now selects the + event based on your :ref:`preferred` countries. :bug:`2501` Fixes: