get original release date for MB release group (#65)

This commit is contained in:
Adrian Sampson 2011-11-13 16:30:49 -08:00
parent 1219c9c0fb
commit 02402545e0
3 changed files with 23 additions and 9 deletions

View file

@ -68,6 +68,16 @@ def track_info(recording):
return info
def _set_date_str(info, date_str):
"""Given a (possibly partial) YYYY-MM-DD string and an AlbumInfo
object, set the object's release date fields appropriately.
"""
if date_str:
date_parts = date_str.split('-')
for key in ('year', 'month', 'day'):
if date_parts:
setattr(info, key, int(date_parts.pop(0)))
def album_info(release):
"""Takes a MusicBrainz release result dictionary and returns a beets
AlbumInfo object containing the interesting data about that release.
@ -94,13 +104,12 @@ def album_info(release):
info.albumtype = reltype.lower()
# Release date.
if 'date' in release: # XXX: when is this not included?
date_str = release['date']
if date_str:
date_parts = date_str.split('-')
for key in ('year', 'month', 'day'):
if date_parts:
setattr(info, key, int(date_parts.pop(0)))
if 'first-release-date' in release['release-group']:
# Try earliest release date for the entire group first.
_set_date_str(info, release['release-group']['first-release-date'])
elif 'date' in release:
# Fall back to release-specific date.
_set_date_str(info, release['date'])
# Label name.
if release.get('label-info-list'):

View file

@ -18,6 +18,8 @@ Changelog
* The :doc:`/plugins/replaygain`, written by `Peter Brunner`_, has been merged
into the core beets distribution. Use it to analyze audio and adjust playback
levels in ReplayGain-aware music players.
* Albums are now tagged with their *original* release date rather than the date
of any reissue, remaster, "special edition", or the like.
* When entering an ID manually during tagging, beets now searches for anything
that looks like an MBID in the entered string. This means that full
MusicBrainz URLs now work as IDs at the prompt. (Thanks to derwin.)

View file

@ -24,11 +24,14 @@ class MBAlbumInfoTest(unittest.TestCase):
release = {
'title': 'ALBUM TITLE',
'id': 'ALBUM ID',
'release-group': {'type': 'Album'},
'release-group': {
'type': 'Album',
'first-release-date': date_str,
},
'artist-credit': [
{'artist': {'name': 'ARTIST NAME', 'id': 'ARTIST ID'}}
],
'date': date_str,
'date': '3001',
'medium-list': [],
}
if tracks: