mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 06:42:25 +01:00
zero out month & day when missing from match
This commit is contained in:
parent
938563e287
commit
a9b4169ee2
3 changed files with 51 additions and 8 deletions
|
|
@ -184,14 +184,20 @@ def apply_metadata(album_info, mapping):
|
|||
|
||||
for suffix in 'year', 'month', 'day':
|
||||
key = prefix + suffix
|
||||
value = getattr(album_info, key)
|
||||
if value:
|
||||
setattr(item, key, value)
|
||||
if config['original_date']:
|
||||
# If we're using original release date for both
|
||||
# fields, set item.year = info.original_year,
|
||||
# etc.
|
||||
setattr(item, suffix, value)
|
||||
value = getattr(album_info, key) or 0
|
||||
|
||||
# If we don't even have a year, apply nothing.
|
||||
if suffix == 'year' and not value:
|
||||
break
|
||||
|
||||
# Otherwise, set the fetched value (or 0 for the month
|
||||
# and day if not available).
|
||||
item[key] = value
|
||||
|
||||
# If we're using original release date for both fields,
|
||||
# also set item.year = info.original_year, etc.
|
||||
if config['original_date']:
|
||||
item[suffix] = value
|
||||
|
||||
# Title.
|
||||
item.title = track_info.title
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ Little fixes:
|
|||
equivalent to the empty string).
|
||||
* :doc:`/plugins/lastgenre`: Fix a conflict between canonicalization and
|
||||
multiple genres.
|
||||
* When a match has a year but not a month or day, the autotagger now "zeros
|
||||
out" the month and day fields after applying the year.
|
||||
|
||||
.. _Acoustic Attributes: http://developer.echonest.com/acoustic-attributes.html
|
||||
.. _MPD: http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki
|
||||
|
|
|
|||
|
|
@ -821,6 +821,41 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertEqual(self.items[1].albumartist_sort, 'albumArtistSort')
|
||||
self.assertEqual(self.items[1].artist_sort, 'albumArtistSort')
|
||||
|
||||
def test_full_date_applied(self):
|
||||
my_info = copy.deepcopy(self.info)
|
||||
my_info.year = 2013
|
||||
my_info.month = 12
|
||||
my_info.day = 18
|
||||
self._apply(info=my_info)
|
||||
|
||||
self.assertEqual(self.items[0].year, 2013)
|
||||
self.assertEqual(self.items[0].month, 12)
|
||||
self.assertEqual(self.items[0].day, 18)
|
||||
|
||||
def test_date_only_zeros_month_and_day(self):
|
||||
self.items = []
|
||||
self.items.append(Item(year=1, month=2, day=3))
|
||||
self.items.append(Item(year=4, month=5, day=6))
|
||||
|
||||
my_info = copy.deepcopy(self.info)
|
||||
my_info.year = 2013
|
||||
self._apply(info=my_info)
|
||||
|
||||
self.assertEqual(self.items[0].year, 2013)
|
||||
self.assertEqual(self.items[0].month, 0)
|
||||
self.assertEqual(self.items[0].day, 0)
|
||||
|
||||
def test_missing_date_applies_nothing(self):
|
||||
self.items = []
|
||||
self.items.append(Item(year=1, month=2, day=3))
|
||||
self.items.append(Item(year=4, month=5, day=6))
|
||||
|
||||
self._apply()
|
||||
|
||||
self.assertEqual(self.items[0].year, 1)
|
||||
self.assertEqual(self.items[0].month, 2)
|
||||
self.assertEqual(self.items[0].day, 3)
|
||||
|
||||
class ApplyCompilationTest(_common.TestCase, ApplyTestUtil):
|
||||
def setUp(self):
|
||||
super(ApplyCompilationTest, self).setUp()
|
||||
|
|
|
|||
Loading…
Reference in a new issue