Use _safe_cast to avoid dying on illegal dates.

This commit is contained in:
Andrew Sutherland 2014-03-16 15:49:37 -04:00
parent 03fa8d809b
commit e290f8dfad
12 changed files with 10 additions and 1 deletions

View file

@ -1016,11 +1016,15 @@ class DateField(MediaField):
datestring = MediaField.__get__(self, mediafile, None)
datestring = re.sub(r'[Tt ].*$', '', unicode(datestring))
items = unicode(datestring).split('-')
# A date with more than 3 components is not a date we understand. In
# that case, act like we saw no date components.
if len(items) > 3:
items = []
items = items + [None] * (3 - len(items))
if not items[0] and hasattr(self, '_year_field'):
# Fallback to addition year field
items[0] = self._year_field.__get__(mediafile)
return [int(item or 0) for item in items]
return [_safe_cast(int, item) for item in items]
def _set_date_tuple(self, mediafile, year, month=None, day=None):
date = [year or 0]

Binary file not shown.

BIN
test/rsrc/unparseable.ape Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.flac Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.m4a Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.mp3 Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.mpc Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.ogg Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.opus Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.wma Normal file

Binary file not shown.

BIN
test/rsrc/unparseable.wv Normal file

Binary file not shown.

View file

@ -467,6 +467,11 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin):
self.assertEqual(mediafile.disc, 10)
self.assertEqual(mediafile.disctotal, 0)
def test_unparseable_date(self):
mediafile = self._mediafile_fixture('unparseable')
self.assertEqual(mediafile.year, 0)
self.assertEqual(mediafile.date, datetime.date.min)
def assertTags(self, mediafile, tags):
__unittest = True